Welcome to mirror list, hosted at ThFree Co, Russian Federation.

terminal_sync_spec.js « plugins « stores « ide « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0e5f41846794981a8d9e97cafd4ae6dce18e4f71 (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
73
74
75
76
77
78
79
80
81
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';
import { createTriggerUpdatePayload } from '../../helpers';

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);
    });

    it('does nothing when ide.files.change is emitted with "update"', () => {
      eventHub.$emit(FILES_CHANGE_EVENT, createTriggerUpdatePayload('foo'));

      jest.runAllTimers();

      expect(store.dispatch).not.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);
      });
    });
  });
});