2017-09-08 11:52:36 -04:00
|
|
|
/* eslint-env jest */
|
2021-02-09 12:14:00 -05:00
|
|
|
import strokeWidthReducer, {
|
|
|
|
MAX_STROKE_WIDTH, changeStrokeWidth
|
|
|
|
} from '../../src/reducers/stroke-width';
|
2017-10-03 15:04:53 -04:00
|
|
|
import {setSelectedItems} from '../../src/reducers/selected-items';
|
|
|
|
import {mockPaperRootItem} from '../__mocks__/paperMocks';
|
2017-09-08 11:52:36 -04:00
|
|
|
|
|
|
|
test('initialState', () => {
|
|
|
|
let defaultState;
|
|
|
|
|
|
|
|
expect(strokeWidthReducer(defaultState /* state */, {type: 'anything'} /* action */)).toBeDefined();
|
|
|
|
expect(strokeWidthReducer(defaultState /* state */, {type: 'anything'} /* action */)).toBeGreaterThanOrEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('changestrokeWidth', () => {
|
|
|
|
let defaultState;
|
2018-12-14 10:46:15 -05:00
|
|
|
const newstrokeWidth = 23;
|
2017-09-08 11:52:36 -04:00
|
|
|
|
|
|
|
expect(strokeWidthReducer(defaultState /* state */, changeStrokeWidth(newstrokeWidth) /* action */))
|
|
|
|
.toEqual(newstrokeWidth);
|
|
|
|
expect(strokeWidthReducer(1 /* state */, changeStrokeWidth(newstrokeWidth) /* action */))
|
|
|
|
.toEqual(newstrokeWidth);
|
|
|
|
expect(strokeWidthReducer(1 /* state */, changeStrokeWidth(-1) /* action */))
|
|
|
|
.toEqual(0);
|
|
|
|
expect(strokeWidthReducer(1 /* state */, changeStrokeWidth(453452352) /* action */))
|
|
|
|
.toEqual(MAX_STROKE_WIDTH);
|
|
|
|
});
|
|
|
|
|
2017-10-03 15:04:53 -04:00
|
|
|
test('changeStrokeWidthViaSelectedItems', () => {
|
|
|
|
let defaultState;
|
|
|
|
|
|
|
|
const strokeWidth1 = 6;
|
|
|
|
let strokeWidth2; // no outline
|
2018-09-26 13:08:47 -04:00
|
|
|
let selectedItems = [mockPaperRootItem({strokeColor: '#000', strokeWidth: strokeWidth1})];
|
2017-10-03 15:04:53 -04:00
|
|
|
expect(strokeWidthReducer(defaultState /* state */, setSelectedItems(selectedItems) /* action */))
|
|
|
|
.toEqual(strokeWidth1);
|
2018-09-26 13:08:47 -04:00
|
|
|
selectedItems = [mockPaperRootItem({strokeColor: '#000', strokeWidth: strokeWidth2})];
|
2017-10-03 15:04:53 -04:00
|
|
|
expect(strokeWidthReducer(defaultState /* state */, setSelectedItems(selectedItems) /* action */))
|
|
|
|
.toEqual(0); // Convert no outline to stroke width 0
|
2018-09-26 13:08:47 -04:00
|
|
|
selectedItems = [mockPaperRootItem({strokeColor: '#000', strokeWidth: strokeWidth1}),
|
|
|
|
mockPaperRootItem({strokeColor: '#000', strokeWidth: strokeWidth2})];
|
2017-10-03 15:04:53 -04:00
|
|
|
expect(strokeWidthReducer(defaultState /* state */, setSelectedItems(selectedItems) /* action */))
|
|
|
|
.toEqual(null); // null indicates mixed for stroke width
|
|
|
|
});
|
|
|
|
|
2018-09-26 13:08:47 -04:00
|
|
|
test('showNoStrokeWidthIfNoStrokeColor', () => {
|
|
|
|
let defaultState;
|
|
|
|
|
|
|
|
const selectedItems = [mockPaperRootItem({strokeColor: null, strokeWidth: 10})];
|
|
|
|
expect(strokeWidthReducer(defaultState /* state */, setSelectedItems(selectedItems) /* action */))
|
|
|
|
.toEqual(0);
|
|
|
|
});
|
|
|
|
|
2017-09-08 11:52:36 -04:00
|
|
|
test('invalidChangestrokeWidth', () => {
|
|
|
|
const origState = {strokeWidth: 1};
|
|
|
|
|
|
|
|
expect(strokeWidthReducer(origState /* state */, changeStrokeWidth('invalid argument') /* action */))
|
|
|
|
.toBe(origState);
|
|
|
|
expect(strokeWidthReducer(origState /* state */, changeStrokeWidth() /* action */))
|
|
|
|
.toBe(origState);
|
|
|
|
});
|