|
|
|
import strokeWidthReducer, { |
|
MAX_STROKE_WIDTH, changeStrokeWidth |
|
} from '../../src/reducers/stroke-width'; |
|
import {setSelectedItems} from '../../src/reducers/selected-items'; |
|
import {mockPaperRootItem} from '../__mocks__/paperMocks'; |
|
|
|
test('initialState', () => { |
|
let defaultState; |
|
|
|
expect(strokeWidthReducer(defaultState , {type: 'anything'} )).toBeDefined(); |
|
expect(strokeWidthReducer(defaultState , {type: 'anything'} )).toBeGreaterThanOrEqual(0); |
|
}); |
|
|
|
test('changestrokeWidth', () => { |
|
let defaultState; |
|
const newstrokeWidth = 23; |
|
|
|
expect(strokeWidthReducer(defaultState , changeStrokeWidth(newstrokeWidth) )) |
|
.toEqual(newstrokeWidth); |
|
expect(strokeWidthReducer(1 , changeStrokeWidth(newstrokeWidth) )) |
|
.toEqual(newstrokeWidth); |
|
expect(strokeWidthReducer(1 , changeStrokeWidth(-1) )) |
|
.toEqual(0); |
|
expect(strokeWidthReducer(1 , changeStrokeWidth(453452352) )) |
|
.toEqual(MAX_STROKE_WIDTH); |
|
}); |
|
|
|
test('changeStrokeWidthViaSelectedItems', () => { |
|
let defaultState; |
|
|
|
const strokeWidth1 = 6; |
|
let strokeWidth2; |
|
let selectedItems = [mockPaperRootItem({strokeColor: '#000', strokeWidth: strokeWidth1})]; |
|
expect(strokeWidthReducer(defaultState , setSelectedItems(selectedItems) )) |
|
.toEqual(strokeWidth1); |
|
selectedItems = [mockPaperRootItem({strokeColor: '#000', strokeWidth: strokeWidth2})]; |
|
expect(strokeWidthReducer(defaultState , setSelectedItems(selectedItems) )) |
|
.toEqual(0); |
|
selectedItems = [mockPaperRootItem({strokeColor: '#000', strokeWidth: strokeWidth1}), |
|
mockPaperRootItem({strokeColor: '#000', strokeWidth: strokeWidth2})]; |
|
expect(strokeWidthReducer(defaultState , setSelectedItems(selectedItems) )) |
|
.toEqual(null); |
|
}); |
|
|
|
test('showNoStrokeWidthIfNoStrokeColor', () => { |
|
let defaultState; |
|
|
|
const selectedItems = [mockPaperRootItem({strokeColor: null, strokeWidth: 10})]; |
|
expect(strokeWidthReducer(defaultState , setSelectedItems(selectedItems) )) |
|
.toEqual(0); |
|
}); |
|
|
|
test('invalidChangestrokeWidth', () => { |
|
const origState = {strokeWidth: 1}; |
|
|
|
expect(strokeWidthReducer(origState , changeStrokeWidth('invalid argument') )) |
|
.toBe(origState); |
|
expect(strokeWidthReducer(origState , changeStrokeWidth() )) |
|
.toBe(origState); |
|
}); |
|
|