2017-11-01 16:57:02 -04:00
|
|
|
/* eslint-env jest */
|
|
|
|
import clipboardReducer from '../../src/reducers/clipboard';
|
2017-11-01 18:10:03 -04:00
|
|
|
import {clearPasteOffset, incrementPasteOffset, setClipboardItems} from '../../src/reducers/clipboard';
|
2017-11-01 16:57:02 -04:00
|
|
|
|
|
|
|
test('initialState', () => {
|
|
|
|
let defaultState;
|
|
|
|
|
2017-11-01 18:10:03 -04:00
|
|
|
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'];
|
2017-11-01 18:10:03 -04:00
|
|
|
expect(clipboardReducer(defaultState /* state */, setClipboardItems(newSelected1) /* action */).items)
|
2017-11-01 16:57:02 -04:00
|
|
|
.toEqual(newSelected1);
|
2017-11-01 18:10:03 -04:00
|
|
|
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);
|
2017-11-01 18:10:03 -04:00
|
|
|
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', () => {
|
2017-11-01 18:10:03 -04:00
|
|
|
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);
|
|
|
|
});
|