summaryrefslogtreecommitdiff
path: root/spec/frontend/pages/admin/application_settings/metrics_and_profiling/usage_statistics_spec.js
blob: 3a52c2438670675f290677eb93ae268a8b315eec (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
import initSetHelperText, {
  HELPER_TEXT_SERVICE_PING_DISABLED,
  HELPER_TEXT_SERVICE_PING_ENABLED,
} from '~/pages/admin/application_settings/metrics_and_profiling/usage_statistics';
import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';

describe('UsageStatistics', () => {
  const FIXTURE = 'application_settings/usage.html';
  let servicePingCheckBox;
  let servicePingFeaturesCheckBox;
  let servicePingFeaturesLabel;
  let servicePingFeaturesHelperText;

  beforeEach(() => {
    loadHTMLFixture(FIXTURE);
    initSetHelperText();
    servicePingCheckBox = document.getElementById('application_setting_usage_ping_enabled');
    servicePingFeaturesCheckBox = document.getElementById(
      'application_setting_usage_ping_features_enabled',
    );
    servicePingFeaturesLabel = document.getElementById('service_ping_features_label');
    servicePingFeaturesHelperText = document.getElementById('service_ping_features_helper_text');
  });

  afterEach(() => {
    resetHTMLFixture();
  });

  const expectEnabledservicePingFeaturesCheckBox = () => {
    expect(servicePingFeaturesCheckBox.classList.contains('gl-cursor-not-allowed')).toBe(false);
    expect(servicePingFeaturesHelperText.textContent).toEqual(HELPER_TEXT_SERVICE_PING_ENABLED);
  };

  const expectDisabledservicePingFeaturesCheckBox = () => {
    expect(servicePingFeaturesLabel.classList.contains('gl-cursor-not-allowed')).toBe(true);
    expect(servicePingFeaturesHelperText.textContent).toEqual(HELPER_TEXT_SERVICE_PING_DISABLED);
  };

  describe('Registration Features checkbox', () => {
    it('is disabled when Service Ping checkbox is unchecked', () => {
      expect(servicePingCheckBox.checked).toBe(false);
      expectDisabledservicePingFeaturesCheckBox();
    });

    it('is enabled when Servie Ping checkbox is checked', () => {
      servicePingCheckBox.click();
      expect(servicePingCheckBox.checked).toBe(true);
      expectEnabledservicePingFeaturesCheckBox();
    });

    it('is switched to disabled when Service Ping checkbox is unchecked ', () => {
      servicePingCheckBox.click();
      servicePingFeaturesCheckBox.click();
      expectEnabledservicePingFeaturesCheckBox();

      servicePingCheckBox.click();
      expect(servicePingCheckBox.checked).toBe(false);
      expect(servicePingFeaturesCheckBox.checked).toBe(false);
      expectDisabledservicePingFeaturesCheckBox();
    });
  });
});