summaryrefslogtreecommitdiff
path: root/spec/javascripts/environments/environments_store_spec.js
blob: 115d84b50f5dcebe51238e6384dc03f012cbde79 (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
import Store from '~/environments/stores/environments_store';
import { environmentsList, serverData } from './mock_data';

(() => {
  describe('Store', () => {
    let store;

    beforeEach(() => {
      store = new Store();
    });

    it('should start with a blank state', () => {
      expect(store.state.environments.length).toEqual(0);
      expect(store.state.stoppedCounter).toEqual(0);
      expect(store.state.availableCounter).toEqual(0);
      expect(store.state.paginationInformation).toEqual({});
    });

    it('should store environments', () => {
      store.storeEnvironments(serverData);
      expect(store.state.environments.length).toEqual(serverData.length);
      expect(store.state.environments[0]).toEqual(environmentsList[0]);
    });

    it('should store available count', () => {
      store.storeAvailableCount(2);
      expect(store.state.availableCounter).toEqual(2);
    });

    it('should store stopped count', () => {
      store.storeStoppedCount(2);
      expect(store.state.stoppedCounter).toEqual(2);
    });

    it('should store pagination information', () => {
      const pagination = {
        'X-nExt-pAge': '2',
        'X-page': '1',
        'X-Per-Page': '1',
        'X-Prev-Page': '2',
        'X-TOTAL': '37',
        'X-Total-Pages': '2',
      };

      const expectedResult = {
        perPage: 1,
        page: 1,
        total: 37,
        totalPages: 2,
        nextPage: 2,
        previousPage: 2,
      };

      store.setPagination(pagination);
      expect(store.state.paginationInformation).toEqual(expectedResult);
    });
  });
})();