scratch-paint/test/unit/clipboard-reducer.test.js

65 lines
2.4 KiB
JavaScript
Raw Normal View History

2017-11-01 16:57:02 -04:00
/* eslint-env jest */
import clipboardReducer from '../../src/reducers/clipboard';
import {clearPasteOffset, incrementPasteOffset, setClipboardItems} from '../../src/reducers/clipboard';
2017-11-01 16:57:02 -04:00
test('initialState', () => {
let defaultState;
expect(clipboardReducer(defaultState /* state */, {type: 'anything'} /* action */).items).toBeDefined();
expect(clipboardReducer(defaultState /* state */, {type: 'anything'} /* action */).pasteOffset).toBeDefined();
2017-11-01 16:57:02 -04:00
});
test('setClipboardItems', () => {
let defaultState;
const newSelected1 = ['selected1', 'selected2'];
const newSelected2 = ['selected1', 'selected3'];
expect(clipboardReducer(defaultState /* state */, setClipboardItems(newSelected1) /* action */).items)
2017-11-01 16:57:02 -04:00
.toEqual(newSelected1);
expect(clipboardReducer(defaultState /* state */, setClipboardItems(newSelected1) /* action */).pasteOffset)
.toEqual(1);
expect(clipboardReducer(newSelected1, setClipboardItems(newSelected2) /* action */).items)
2017-11-01 16:57:02 -04:00
.toEqual(newSelected2);
expect(clipboardReducer(defaultState /* state */, setClipboardItems(newSelected1) /* action */).pasteOffset)
.toEqual(1);
});
test('incrementPasteOffset', () => {
const origState = {
items: ['selected1', 'selected2'],
pasteOffset: 1
};
expect(clipboardReducer(origState /* state */, incrementPasteOffset() /* action */).pasteOffset)
.toEqual(2);
expect(clipboardReducer(origState, incrementPasteOffset() /* action */).items)
.toEqual(origState.items);
});
test('clearPasteOffset', () => {
const origState = {
items: ['selected1', 'selected2'],
pasteOffset: 1
};
expect(clipboardReducer(origState /* state */, clearPasteOffset() /* action */).pasteOffset)
.toEqual(0);
expect(clipboardReducer(origState, clearPasteOffset() /* action */).items)
.toEqual(origState.items);
2017-11-01 16:57:02 -04:00
});
test('invalidSetClipboardItems', () => {
const origState = {
items: ['selected1', 'selected2'],
pasteOffset: 1
};
2017-11-01 16:57:02 -04:00
const nothingSelected = [];
expect(clipboardReducer(origState /* state */, setClipboardItems() /* action */))
.toBe(origState);
expect(clipboardReducer(origState /* state */, setClipboardItems('notAnArray') /* action */))
.toBe(origState);
expect(clipboardReducer(origState /* state */, setClipboardItems(nothingSelected) /* action */))
.toBe(origState);
});