summaryrefslogtreecommitdiff
path: root/spec/javascripts/clusters_spec.js
blob: 2ceb0cfdf4cf0bda2716a44e2c890f6e6f0e8712 (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
import Clusters from '~/clusters';

describe('Clusters', () => {
  let cluster;
  preloadFixtures('clusters/show_cluster.html.raw');

  beforeEach(() => {
    loadFixtures('clusters/show_cluster.html.raw');
    cluster = new Clusters();
  });

  describe('toggle', () => {
    it('should update the button and the input field on click', () => {
      cluster.toggleButton.click();

      expect(
        cluster.toggleButton.classList,
      ).not.toContain('checked');

      expect(
        cluster.toggleInput.getAttribute('value'),
      ).toEqual('false');
    });
  });

  describe('updateContainer', () => {
    describe('when creating cluster', () => {
      it('should show the creating container', () => {
        cluster.updateContainer('creating');

        expect(
          cluster.creatingContainer.classList,
        ).not.toContain('hidden');
        expect(
          cluster.successContainer.classList,
        ).toContain('hidden');
        expect(
          cluster.errorContainer.classList,
        ).toContain('hidden');
      });
    });

    describe('when cluster is created', () => {
      it('should show the success container', () => {
        cluster.updateContainer('created');

        expect(
          cluster.creatingContainer.classList,
        ).toContain('hidden');
        expect(
          cluster.successContainer.classList,
        ).not.toContain('hidden');
        expect(
          cluster.errorContainer.classList,
        ).toContain('hidden');
      });
    });

    describe('when cluster has error', () => {
      it('should show the error container', () => {
        cluster.updateContainer('errored', 'this is an error');

        expect(
          cluster.creatingContainer.classList,
        ).toContain('hidden');
        expect(
          cluster.successContainer.classList,
        ).toContain('hidden');
        expect(
          cluster.errorContainer.classList,
        ).not.toContain('hidden');

        expect(
          cluster.errorContainer.querySelector('.js-error-reason').textContent,
        ).toContain('this is an error');
      });
    });
  });
});