application/__tests__/services/copyNote-service-test.js
jest.unmock('./../../services/base-service');
jest.unmock('./../../services/copyNote-service');
jest.unmock('./../../alt');
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import sinon from 'sinon';
import AltTestingUtils from 'alt-utils/lib/AltTestingUtils';
import alt from './../../alt';
import {CopyNoteService, CopyNoteStore} from './../../services/copyNote-service';
describe('CopyNoteService', () => {
let spies = {};
beforeEach(() => {
spies.add = sinon.spy(CopyNoteService, 'add');
spies.update = sinon.spy(CopyNoteService, 'update');
spies.remove = sinon.spy(CopyNoteService, 'remove');
spies.updateNotes = sinon.spy(CopyNoteService, 'updateNotes');
spies.updateSelection = sinon.spy(CopyNoteService, 'updateSelection');
spies.setLastSelectedNote = sinon.spy(CopyNoteService, 'setLastSelectedNote');
jasmine.clock().uninstall();
jasmine.clock().install();
});
afterEach(() => {
CopyNoteService.add.restore();
CopyNoteService.update.restore();
CopyNoteService.remove.restore();
CopyNoteService.updateNotes.restore();
CopyNoteService.updateSelection.restore();
CopyNoteService.setLastSelectedNote.restore();
jasmine.clock().uninstall();
});
it('expects update to push note stack', (done) => {
CopyNoteService.add(1, 1, 'test note', 'test user', false, 1, 1);
jasmine.clock().tick(2);
expect(spies.add.called).toEqual(true);
expect(spies.updateNotes.called).toEqual(true);
expect(CopyNoteStore.getState().notes[0].contents).toEqual('test note');
done();
});
it('expects update to modify note stack', (done) => {
CopyNoteService.add('123-456', '987-654', 'test note', 'test user', false, 1, 1);
jasmine.clock().tick(2);
expect(spies.add.called).toEqual(true);
expect(spies.updateNotes.calledOnce).toEqual(true);
CopyNoteService.update('123-456', '987-654', 'changed note');
jasmine.clock().tick(4);
process.nextTick(() => {
expect(spies.update.called).toEqual(true);
expect(spies.updateNotes.calledTwice).toEqual(true);
expect(CopyNoteStore.getState().notes[1].contents).toEqual('changed note');
done();
});
});
it('updates last selected note', (done) => {
CopyNoteService.add('654-323', '987-654', 'test note', 'test user', false, 1, 1);
jasmine.clock().tick(2);
CopyNoteService.add('986-234', '987-654', 'test note', 'test user', false, 1, 1);
jasmine.clock().tick(2);
expect(CopyNoteStore.getState().selection).toEqual(false);
CopyNoteService.setLastSelectedNote('986-234');
jasmine.clock().tick(2);
expect(CopyNoteStore.getState().selection).toEqual('986-234');
done();
});
});