summaryrefslogtreecommitdiff
path: root/spec/frontend/ide/stores/modules/editor/setup_spec.js
blob: 71b5d7590c5a567a0600a138be9244761074c089 (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
import Vuex from 'vuex';
import eventHub from '~/ide/eventhub';
import { createStoreOptions } from '~/ide/stores';
import { setupFileEditorsSync } from '~/ide/stores/modules/editor/setup';
import { createTriggerRenamePayload } from '../../../helpers';

describe('~/ide/stores/modules/editor/setup', () => {
  let store;

  beforeEach(() => {
    store = new Vuex.Store(createStoreOptions());
    store.state.entries = {
      foo: {},
      bar: {},
    };
    store.state.editor.fileEditors = {
      foo: {},
      bizz: {},
    };

    setupFileEditorsSync(store);
  });

  it('when files change is emitted, removes unused fileEditors', () => {
    eventHub.$emit('ide.files.change');

    expect(store.state.entries).toEqual({
      foo: {},
      bar: {},
    });
    expect(store.state.editor.fileEditors).toEqual({
      foo: {},
    });
  });

  it('when files rename is emitted, renames fileEditor', () => {
    eventHub.$emit('ide.files.change', createTriggerRenamePayload('foo', 'foo_new'));

    expect(store.state.editor.fileEditors).toEqual({
      foo_new: {},
      bizz: {},
    });
  });
});