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

mutations_spec.js « store « static_site_editor « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0b213c11a04f0d1f0f460b31ac8f1301ee4e46bf (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
import createState from '~/static_site_editor/store/state';
import mutations from '~/static_site_editor/store/mutations';
import * as types from '~/static_site_editor/store/mutation_types';
import {
  sourceContentTitle as title,
  sourceContent as content,
  savedContentMeta,
} from '../mock_data';

describe('Static Site Editor Store mutations', () => {
  let state;
  const contentLoadedPayload = { title, content };

  beforeEach(() => {
    state = createState();
  });

  it.each`
    mutation                         | stateProperty         | payload                 | expectedValue
    ${types.LOAD_CONTENT}            | ${'isLoadingContent'} | ${undefined}            | ${true}
    ${types.RECEIVE_CONTENT_SUCCESS} | ${'isLoadingContent'} | ${contentLoadedPayload} | ${false}
    ${types.RECEIVE_CONTENT_SUCCESS} | ${'isContentLoaded'}  | ${contentLoadedPayload} | ${true}
    ${types.RECEIVE_CONTENT_SUCCESS} | ${'title'}            | ${contentLoadedPayload} | ${title}
    ${types.RECEIVE_CONTENT_SUCCESS} | ${'content'}          | ${contentLoadedPayload} | ${content}
    ${types.RECEIVE_CONTENT_SUCCESS} | ${'originalContent'}  | ${contentLoadedPayload} | ${content}
    ${types.RECEIVE_CONTENT_ERROR}   | ${'isLoadingContent'} | ${undefined}            | ${false}
    ${types.SET_CONTENT}             | ${'content'}          | ${content}              | ${content}
    ${types.SUBMIT_CHANGES}          | ${'isSavingChanges'}  | ${undefined}            | ${true}
    ${types.SUBMIT_CHANGES_SUCCESS}  | ${'savedContentMeta'} | ${savedContentMeta}     | ${savedContentMeta}
    ${types.SUBMIT_CHANGES_SUCCESS}  | ${'isSavingChanges'}  | ${savedContentMeta}     | ${false}
    ${types.SUBMIT_CHANGES_ERROR}    | ${'isSavingChanges'}  | ${undefined}            | ${false}
  `(
    '$mutation sets $stateProperty to $expectedValue',
    ({ mutation, stateProperty, payload, expectedValue }) => {
      mutations[mutation](state, payload);
      expect(state[stateProperty]).toBe(expectedValue);
    },
  );

  it(`${types.SUBMIT_CHANGES_SUCCESS} sets originalContent to content current value`, () => {
    const editedContent = `${content} plus something else`;

    state = createState({
      originalContent: content,
      content: editedContent,
    });
    mutations[types.SUBMIT_CHANGES_SUCCESS](state);

    expect(state.originalContent).toBe(state.content);
  });
});