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

mutations_spec.js « detail « modules « stores « releases « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d49c8854ca2d71b6fce681166c8de027b7259a0d (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* eslint-disable jest/valid-describe */
/*
 * ESLint disable directive ↑ can be removed once
 * https://github.com/jest-community/eslint-plugin-jest/issues/203
 * is resolved
 */

import createState from '~/releases/stores/modules/detail/state';
import mutations from '~/releases/stores/modules/detail/mutations';
import * as types from '~/releases/stores/modules/detail/mutation_types';
import { release } from '../../../mock_data';

describe('Release detail mutations', () => {
  let state;
  let releaseClone;

  beforeEach(() => {
    state = createState({
      projectId: '18',
      tagName: 'v1.3',
      releasesPagePath: 'path/to/releases/page',
      markdownDocsPath: 'path/to/markdown/docs',
      markdownPreviewPath: 'path/to/markdown/preview',
      updateReleaseApiDocsPath: 'path/to/api/docs',
    });
    releaseClone = JSON.parse(JSON.stringify(release));
  });

  describe(types.REQUEST_RELEASE, () => {
    it('set state.isFetchingRelease to true', () => {
      mutations[types.REQUEST_RELEASE](state);

      expect(state.isFetchingRelease).toEqual(true);
    });
  });

  describe(types.RECEIVE_RELEASE_SUCCESS, () => {
    it('handles a successful response from the server', () => {
      mutations[types.RECEIVE_RELEASE_SUCCESS](state, releaseClone);

      expect(state.fetchError).toEqual(undefined);

      expect(state.isFetchingRelease).toEqual(false);

      expect(state.release).toEqual(releaseClone);
    });
  });

  describe(types.RECEIVE_RELEASE_ERROR, () => {
    it('handles an unsuccessful response from the server', () => {
      const error = { message: 'An error occurred!' };
      mutations[types.RECEIVE_RELEASE_ERROR](state, error);

      expect(state.isFetchingRelease).toEqual(false);

      expect(state.release).toBeUndefined();

      expect(state.fetchError).toEqual(error);
    });
  });

  describe(types.UPDATE_RELEASE_TITLE, () => {
    it("updates the release's title", () => {
      state.release = releaseClone;
      const newTitle = 'The new release title';
      mutations[types.UPDATE_RELEASE_TITLE](state, newTitle);

      expect(state.release.name).toEqual(newTitle);
    });
  });

  describe(types.UPDATE_RELEASE_NOTES, () => {
    it("updates the release's notes", () => {
      state.release = releaseClone;
      const newNotes = 'The new release notes';
      mutations[types.UPDATE_RELEASE_NOTES](state, newNotes);

      expect(state.release.description).toEqual(newNotes);
    });
  });

  describe(types.REQUEST_UPDATE_RELEASE, () => {
    it('set state.isUpdatingRelease to true', () => {
      mutations[types.REQUEST_UPDATE_RELEASE](state);

      expect(state.isUpdatingRelease).toEqual(true);
    });
  });

  describe(types.RECEIVE_UPDATE_RELEASE_SUCCESS, () => {
    it('handles a successful response from the server', () => {
      mutations[types.RECEIVE_UPDATE_RELEASE_SUCCESS](state, releaseClone);

      expect(state.updateError).toEqual(undefined);

      expect(state.isUpdatingRelease).toEqual(false);
    });
  });

  describe(types.RECEIVE_UPDATE_RELEASE_ERROR, () => {
    it('handles an unsuccessful response from the server', () => {
      const error = { message: 'An error occurred!' };
      mutations[types.RECEIVE_UPDATE_RELEASE_ERROR](state, error);

      expect(state.isUpdatingRelease).toEqual(false);

      expect(state.updateError).toEqual(error);
    });
  });
});