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

actions_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: 98d7d0d2c2dd09b60adc0b2d8da56992f457b3fe (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
import testAction from 'helpers/vuex_action_helper';
import createState from '~/static_site_editor/store/state';
import * as actions from '~/static_site_editor/store/actions';
import * as mutationTypes from '~/static_site_editor/store/mutation_types';
import loadSourceContent from '~/static_site_editor/services/load_source_content';

import createFlash from '~/flash';

import {
  projectId,
  sourcePath,
  sourceContentTitle as title,
  sourceContent as content,
} from '../mock_data';

jest.mock('~/flash');
jest.mock('~/static_site_editor/services/load_source_content', () => jest.fn());

describe('Static Site Editor Store actions', () => {
  let state;

  beforeEach(() => {
    state = createState({
      projectId,
      sourcePath,
    });
  });

  describe('loadContent', () => {
    describe('on success', () => {
      const payload = { title, content };

      beforeEach(() => {
        loadSourceContent.mockResolvedValueOnce(payload);
      });

      it('commits receiveContentSuccess', () => {
        testAction(
          actions.loadContent,
          null,
          state,
          [
            { type: mutationTypes.LOAD_CONTENT },
            { type: mutationTypes.RECEIVE_CONTENT_SUCCESS, payload },
          ],
          [],
        );

        expect(loadSourceContent).toHaveBeenCalledWith({ projectId, sourcePath });
      });
    });

    describe('on error', () => {
      const expectedMutations = [
        { type: mutationTypes.LOAD_CONTENT },
        { type: mutationTypes.RECEIVE_CONTENT_ERROR },
      ];

      beforeEach(() => {
        loadSourceContent.mockRejectedValueOnce();
      });

      it('commits receiveContentError', () => {
        testAction(actions.loadContent, null, state, expectedMutations);
      });

      it('displays flash communicating error', () => {
        return testAction(actions.loadContent, null, state, expectedMutations).then(() => {
          expect(createFlash).toHaveBeenCalledWith(
            'An error ocurred while loading your content. Please try again.',
          );
        });
      });
    });
  });
});