125 lines
3.3 KiB
JavaScript
125 lines
3.3 KiB
JavaScript
import Store from '../../src/modules/store.js';
|
|
|
|
export default class StoreTest {
|
|
constructor(assert) {
|
|
this.assert = assert;
|
|
}
|
|
|
|
test() {
|
|
(() => {
|
|
let called = false
|
|
const store = new Store(() => called = true);
|
|
|
|
const event = new Event('addLine');
|
|
store.eventHandler(event);
|
|
|
|
this.assert("eventHandler calls the callback after successfull event", called, true);
|
|
|
|
})();
|
|
(() => {
|
|
const store = new Store(() => {});
|
|
store.records = [
|
|
{id: 0, text: "asdf", action: 'add'},
|
|
{id: 1, text: "qwer", action: 'add'},
|
|
{id: 2, action: 'remove'},
|
|
]
|
|
|
|
const event = new Event('unknown');
|
|
store.eventHandler(event);
|
|
|
|
const expected = [
|
|
{id: 0, text: "asdf", action: 'add'},
|
|
{id: 1, text: "qwer", action: 'add'},
|
|
{id: 2, action: 'remove'},
|
|
];
|
|
|
|
this.assert("eventHandler does nothing on an unknown event type", store.records, expected);
|
|
|
|
})();
|
|
(() => {
|
|
const store = new Store(() => {});
|
|
|
|
const event = new Event('addLine');
|
|
store.eventHandler(event);
|
|
|
|
const expected = [
|
|
{id: 0, text: "asdf", action: 'add'},
|
|
];
|
|
|
|
this.assert("eventHandler adds the appropiate record when Event 'addLine' is passed", store.records, expected);
|
|
|
|
})();
|
|
(() => {
|
|
const store = new Store(() => {});
|
|
store.records = [
|
|
{id: 0, text: "asdf", action: 'add'},
|
|
]
|
|
|
|
const event = new Event('removeLine');
|
|
store.eventHandler(event);
|
|
|
|
const expected = [
|
|
{id: 0, text: "asdf", action: 'add'},
|
|
{id: 1, action: 'remove'},
|
|
];
|
|
|
|
this.assert("eventHandler adds the appropiate record when Event 'removeLine' is passed", store.records, expected);
|
|
|
|
})();
|
|
(() => {
|
|
const store = new Store(() => {});
|
|
store.records = [
|
|
{id: 0, text: "asdf", action: 'add'},
|
|
{id: 1, text: "qwer", action: 'add'},
|
|
{id: 2, action: 'remove'},
|
|
]
|
|
|
|
const event = new Event('undo');
|
|
store.eventHandler(event);
|
|
|
|
const expected = [
|
|
{id: 0, text: "asdf", action: 'add'},
|
|
{id: 1, text: "qwer", action: 'add'},
|
|
];
|
|
|
|
this.assert("eventHandler deletes the appropiate record when Event 'undo' is passed", store.records, expected);
|
|
|
|
})();
|
|
(() => {
|
|
const store = new Store(() => {});
|
|
|
|
store.records = [
|
|
{id: 0, text: "Line 1", action: 'add'},
|
|
{id: 1, text: "Line 2", action: 'add'},
|
|
{id: 2, text: "Line 3", action: 'add'},
|
|
];
|
|
|
|
const expected = [
|
|
{id: 0, text: "Line 1"},
|
|
{id: 1, text: "Line 2"},
|
|
{id: 2, text: "Line 3"},
|
|
];
|
|
|
|
this.assert("getState returns an array of strings with 3 add records", store.getState(), expected);
|
|
})();
|
|
|
|
(() => {
|
|
const store = new Store(() => {});
|
|
|
|
store.records = [
|
|
{id: 0, text: "Line 1", action: 'add'},
|
|
{id: 1, text: "Line 2", action: 'add'},
|
|
{id: 2, text: "Line 3", action: 'add'},
|
|
{id: 3, targetId: 1, action: 'remove'},
|
|
];
|
|
|
|
const expected = [
|
|
{id: 0, text: "Line 1"},
|
|
{id: 2, text: "Line 3"},
|
|
];
|
|
|
|
this.assert("getState returns an array of strings with 3 add records and a delete record", store.getState(), expected);
|
|
})();
|
|
}
|
|
}
|