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

form_spec.js « pages_domains « projects « pages « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 55336596f30c08d5cfe2326b65a810680b0a89ef (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
import initForm from '~/pages/projects/pages_domains/form';

const ENABLED_UNLESS_AUTO_SSL_CLASS = 'js-enabled-unless-auto-ssl';
const SSL_TOGGLE_CLASS = 'js-enable-ssl-gl-toggle';
const SSL_TOGGLE_INPUT_CLASS = 'js-project-feature-toggle-input';
const SHOW_IF_AUTO_SSL_CLASS = 'js-shown-if-auto-ssl';
const SHOW_UNLESS_AUTO_SSL_CLASS = 'js-shown-unless-auto-ssl';
const D_NONE_CLASS = 'd-none';

describe('Page domains form', () => {
  let toggle;

  const findEnabledUnless = () => document.querySelector(`.${ENABLED_UNLESS_AUTO_SSL_CLASS}`);
  const findSslToggle = () => document.querySelector(`.${SSL_TOGGLE_CLASS} button`);
  const findSslToggleInput = () => document.querySelector(`.${SSL_TOGGLE_INPUT_CLASS}`);
  const findIfAutoSsl = () => document.querySelector(`.${SHOW_IF_AUTO_SSL_CLASS}`);
  const findUnlessAutoSsl = () => document.querySelector(`.${SHOW_UNLESS_AUTO_SSL_CLASS}`);

  const create = () => {
    setFixtures(`
      <form>
        <span
          class="${SSL_TOGGLE_CLASS}"
          data-label="SSL toggle"
          ></span>
        <input class="${SSL_TOGGLE_INPUT_CLASS}" type="hidden" />
        <span class="${SHOW_UNLESS_AUTO_SSL_CLASS}"></span>
        <span class="${SHOW_IF_AUTO_SSL_CLASS}"></span>
        <button class="${ENABLED_UNLESS_AUTO_SSL_CLASS}"></button>
      </form>
    `);
  };

  it('instantiates the toggle', () => {
    create();
    initForm();

    expect(findSslToggle()).not.toBe(null);
  });

  describe('when auto SSL is enabled', () => {
    beforeEach(() => {
      create();
      toggle = initForm();
      toggle.$emit('change', true);
    });

    it('sets the correct classes', () => {
      expect(Array.from(findIfAutoSsl().classList)).not.toContain(D_NONE_CLASS);
      expect(Array.from(findUnlessAutoSsl().classList)).toContain(D_NONE_CLASS);
    });

    it('sets the correct disabled value', () => {
      expect(findEnabledUnless().getAttribute('disabled')).toBe('disabled');
    });

    it('sets the correct value for the input', () => {
      expect(findSslToggleInput().getAttribute('value')).toBe('true');
    });
  });

  describe('when auto SSL is not enabled', () => {
    beforeEach(() => {
      create();
      toggle = initForm();
      toggle.$emit('change', false);
    });

    it('sets the correct classes', () => {
      expect(Array.from(findIfAutoSsl().classList)).toContain(D_NONE_CLASS);
      expect(Array.from(findUnlessAutoSsl().classList)).not.toContain(D_NONE_CLASS);
    });

    it('sets the correct disabled value', () => {
      expect(findUnlessAutoSsl().getAttribute('disabled')).toBe(null);
    });

    it('sets the correct value for the input', () => {
      expect(findSslToggleInput().getAttribute('value')).toBe('false');
    });
  });
});