blob: 2aa3e770e7d627599832e540d83e65a246a4ca54 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
import createTerminalPlugin from '~/ide/stores/plugins/terminal';
import createTerminalSyncPlugin from '~/ide/stores/plugins/terminal_sync';
import { SET_SESSION_STATUS } from '~/ide/stores/modules/terminal/mutation_types';
import { RUNNING, STOPPING } from '~/ide/stores/modules/terminal/constants';
import { createStore } from '~/ide/stores';
import eventHub from '~/ide/eventhub';
jest.mock('~/ide/lib/mirror');
const ACTION_START = 'terminalSync/start';
const ACTION_STOP = 'terminalSync/stop';
const ACTION_UPLOAD = 'terminalSync/upload';
const FILES_CHANGE_EVENT = 'ide.files.change';
describe('IDE stores/plugins/mirror', () => {
let store;
beforeEach(() => {
const root = document.createElement('div');
store = createStore();
createTerminalPlugin(root)(store);
store.dispatch = jest.fn(() => Promise.resolve());
createTerminalSyncPlugin(root)(store);
});
it('does nothing on ide.files.change event', () => {
eventHub.$emit(FILES_CHANGE_EVENT);
expect(store.dispatch).not.toHaveBeenCalled();
});
describe('when session starts running', () => {
beforeEach(() => {
store.commit(`terminal/${SET_SESSION_STATUS}`, RUNNING);
});
it('starts', () => {
expect(store.dispatch).toHaveBeenCalledWith(ACTION_START);
});
it('uploads when ide.files.change is emitted', () => {
expect(store.dispatch).not.toHaveBeenCalledWith(ACTION_UPLOAD);
eventHub.$emit(FILES_CHANGE_EVENT);
jest.runAllTimers();
expect(store.dispatch).toHaveBeenCalledWith(ACTION_UPLOAD);
});
describe('when session stops', () => {
beforeEach(() => {
store.commit(`terminal/${SET_SESSION_STATUS}`, STOPPING);
});
it('stops', () => {
expect(store.dispatch).toHaveBeenCalledWith(ACTION_STOP);
});
it('does not upload anymore', () => {
eventHub.$emit(FILES_CHANGE_EVENT);
jest.runAllTimers();
expect(store.dispatch).not.toHaveBeenCalledWith(ACTION_UPLOAD);
});
});
});
});
|