scratch-paint/test/unit/fill-color-reducer.test.js

69 lines
3.1 KiB
JavaScript
Raw Normal View History

2017-09-07 17:12:50 -04:00
/* eslint-env jest */
2020-07-09 18:00:12 -04:00
import fillColorReducer from '../../src/reducers/fill-style';
import {changeFillColor} from '../../src/reducers/fill-style';
2017-10-03 15:04:53 -04:00
import {setSelectedItems} from '../../src/reducers/selected-items';
import {MIXED} from '../../src/helper/style-path';
2020-07-09 18:00:12 -04:00
import GradientTypes from '../../src/lib/gradient-types';
2017-10-03 15:04:53 -04:00
import {mockPaperRootItem} from '../__mocks__/paperMocks';
2017-09-07 17:12:50 -04:00
test('initialState', () => {
let defaultState;
expect(fillColorReducer(defaultState /* state */, {type: 'anything'} /* action */)).toBeDefined();
});
test('changeFillColor', () => {
let defaultState;
// 3 value hex code
let newFillColor = '#fff';
2020-07-09 18:00:12 -04:00
expect(fillColorReducer(defaultState /* state */, changeFillColor(newFillColor) /* action */).primary)
2017-09-07 17:12:50 -04:00
.toEqual(newFillColor);
2020-07-09 18:00:12 -04:00
expect(fillColorReducer('#010' /* state */, changeFillColor(newFillColor) /* action */).primary)
2017-09-07 17:12:50 -04:00
.toEqual(newFillColor);
// 6 value hex code
newFillColor = '#facade';
2020-07-09 18:00:12 -04:00
expect(fillColorReducer(defaultState /* state */, changeFillColor(newFillColor) /* action */).primary)
2017-09-07 17:12:50 -04:00
.toEqual(newFillColor);
2020-07-09 18:00:12 -04:00
expect(fillColorReducer('#010' /* state */, changeFillColor(newFillColor) /* action */).primary)
2017-09-07 17:12:50 -04:00
.toEqual(newFillColor);
});
2017-10-03 15:04:53 -04:00
test('changefillColorViaSelectedItems', () => {
let defaultState;
const fillColor1 = 6;
const fillColor2 = null; // transparent
let selectedItems = [mockPaperRootItem({fillColor: fillColor1})];
2020-07-09 18:00:12 -04:00
expect(fillColorReducer(defaultState /* state */, setSelectedItems(selectedItems) /* action */).primary)
2017-10-03 15:04:53 -04:00
.toEqual(fillColor1);
selectedItems = [mockPaperRootItem({fillColor: fillColor2})];
2020-07-09 18:00:12 -04:00
expect(fillColorReducer(defaultState /* state */, setSelectedItems(selectedItems) /* action */).primary)
2017-10-03 15:04:53 -04:00
.toEqual(fillColor2);
selectedItems = [mockPaperRootItem({fillColor: fillColor1}), mockPaperRootItem({fillColor: fillColor2})];
2020-07-09 18:00:12 -04:00
expect(fillColorReducer(defaultState /* state */, setSelectedItems(selectedItems) /* action */).primary)
2017-10-03 15:04:53 -04:00
.toEqual(MIXED);
});
2017-09-07 17:12:50 -04:00
test('invalidChangeFillColor', () => {
2020-07-09 18:00:12 -04:00
const origState = {primary: '#fff', secondary: null, gradientType: GradientTypes.SOLID};
2017-09-07 17:12:50 -04:00
expect(fillColorReducer(origState /* state */, changeFillColor() /* action */))
.toBe(origState);
expect(fillColorReducer(origState /* state */, changeFillColor('#') /* action */))
.toBe(origState);
expect(fillColorReducer(origState /* state */, changeFillColor('#1') /* action */))
.toBe(origState);
expect(fillColorReducer(origState /* state */, changeFillColor('#12') /* action */))
.toBe(origState);
expect(fillColorReducer(origState /* state */, changeFillColor('#1234') /* action */))
.toBe(origState);
expect(fillColorReducer(origState /* state */, changeFillColor('#12345') /* action */))
.toBe(origState);
expect(fillColorReducer(origState /* state */, changeFillColor('#1234567') /* action */))
.toBe(origState);
expect(fillColorReducer(origState /* state */, changeFillColor('invalid argument') /* action */))
.toBe(origState);
});