Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LinearProgress] Fix calculating of getRelativeValue #4624

Merged
merged 1 commit into from
Jul 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/LinearProgress/LinearProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import transitions from '../styles/transitions';
function getRelativeValue(value, min, max) {
const clampedValue = Math.min(Math.max(min, value), max);
const rangeValue = max - min;
const relValue = Math.round(clampedValue / rangeValue * 10000) / 10000;
const relValue = Math.round((clampedValue - min) / rangeValue * 10000) / 10000;
return relValue * 100;
}

Expand Down
55 changes: 55 additions & 0 deletions src/LinearProgress/LinearProgress.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* eslint-env mocha */
import React from 'react';
import {shallow} from 'enzyme';
import {assert} from 'chai';
import LinearProgress from './LinearProgress';
import getMuiTheme from '../styles/getMuiTheme';

describe('<LinearProgress />', () => {
const muiTheme = getMuiTheme();
const shallowWithContext = (node) => shallow(node, {context: {muiTheme}});

describe('props: min', () => {
it('should work when min equal zero', () => {
const wrapper = shallowWithContext(
<LinearProgress
mode="determinate"
value={50}
min={0}
max={100}
/>
);

assert.strictEqual(wrapper.children().props().style.width, '50%',
'should compute the width correctly');
});

it('should work when min is different to zero', () => {
const wrapper = shallowWithContext(
<LinearProgress
mode="determinate"
value={75}
min={50}
max={100}
/>
);

assert.strictEqual(wrapper.children().props().style.width, '50%',
'should compute the width correctly');
});

it('should work when value equal min', () => {
const wrapper = shallowWithContext(
<LinearProgress
mode="determinate"
value={50}
min={50}
max={100}
/>
);

assert.strictEqual(wrapper.children().props().style.width, '0%',
'should compute the width correctly');
});
});
});