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

actions_spec.js « stores « registry « javascripts « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3c9da4f107b27c8b0787e73c170190dd2a199fbe (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
import Vue from 'vue';
import VueResource from 'vue-resource';
import _ from 'underscore';
import * as actions from '~/registry/stores/actions';
import * as types from '~/registry/stores/mutation_types';
import testAction from '../../helpers/vuex_action_helper';
import {
  defaultState,
  reposServerResponse,
  registryServerResponse,
  parsedReposServerResponse,
} from '../mock_data';

Vue.use(VueResource);

describe('Actions Registry Store', () => {
  let interceptor;
  let mockedState;

  beforeEach(() => {
    mockedState = defaultState;
  });

  describe('server requests', () => {
    afterEach(() => {
      Vue.http.interceptors = _.without(Vue.http.interceptors, interceptor);
    });

    describe('fetchRepos', () => {
      beforeEach(() => {
        interceptor = (request, next) => {
          next(request.respondWith(JSON.stringify(reposServerResponse), {
            status: 200,
          }));
        };

        Vue.http.interceptors.push(interceptor);
      });

      it('should set receveived repos', (done) => {
        testAction(actions.fetchRepos, null, mockedState, [
          { type: types.TOGGLE_MAIN_LOADING },
          { type: types.SET_REPOS_LIST, payload: reposServerResponse },
        ], done);
      });
    });

    describe('fetchList', () => {
      beforeEach(() => {
        interceptor = (request, next) => {
          next(request.respondWith(JSON.stringify(registryServerResponse), {
            status: 200,
          }));
        };

        Vue.http.interceptors.push(interceptor);
      });

      it('should set received list', (done) => {
        mockedState.repos = parsedReposServerResponse;

        testAction(actions.fetchList, { repo: mockedState.repos[1] }, mockedState, [
          { type: types.TOGGLE_REGISTRY_LIST_LOADING },
          { type: types.SET_REGISTRY_LIST, payload: registryServerResponse },
        ], done);
      });
    });
  });

  describe('setMainEndpoint', () => {
    it('should commit set main endpoint', (done) => {
      testAction(actions.setMainEndpoint, 'endpoint', mockedState, [
        { type: types.SET_MAIN_ENDPOINT, payload: 'endpoint' },
      ], done);
    });
  });

  describe('toggleLoading', () => {
    it('should commit toggle main loading', (done) => {
      testAction(actions.toggleLoading, null, mockedState, [
        { type: types.TOGGLE_MAIN_LOADING },
      ], done);
    });
  });
});