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

clusters_index_spec.js « clusters « javascripts « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0a8b63ed5b42b507ab6f9455c9b1d633fb1128bd (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 MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import setClusterTableToggles from '~/clusters/clusters_index';
import { setTimeout } from 'core-js/library/web/timers';

describe('Clusters table', () => {
  preloadFixtures('clusters/index_cluster.html.raw');
  let mock;

  beforeEach(() => {
    loadFixtures('clusters/index_cluster.html.raw');
    mock = new MockAdapter(axios);
    setClusterTableToggles();
  });

  describe('update cluster', () => {
    it('renders loading state while request is made', () => {
      const button = document.querySelector('.js-toggle-cluster-list');

      button.click();

      expect(button.classList).toContain('is-loading');
      expect(button.getAttribute('disabled')).toEqual('true');
    });

    afterEach(() => {
      mock.restore();
    });

    it('shows updated state after sucessfull request', (done) => {
      mock.onPut().reply(200, {}, {});
      const button = document.querySelector('.js-toggle-cluster-list');
      button.click();

      expect(button.classList).toContain('is-loading');

      setTimeout(() => {
        expect(button.classList).not.toContain('is-loading');
        expect(button.classList).not.toContain('is-checked');
        done();
      }, 0);
    });

    it('shows inital state after failed request', (done) => {
      mock.onPut().reply(500, {}, {});
      const button = document.querySelector('.js-toggle-cluster-list');

      button.click();
      expect(button.classList).toContain('is-loading');

      setTimeout(() => {
        expect(button.classList).not.toContain('is-loading');
        expect(button.classList).toContain('is-checked');
        done();
      }, 0);
    });
  });
});