external_dashboard_spec.js 2.9 KB
Newer Older
A
Adriel Santiago 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
import { shallowMount } from '@vue/test-utils';
import { GlButton, GlLink, GlFormGroup, GlFormInput } from '@gitlab/ui';
import ExternalDashboard from '~/operation_settings/components/external_dashboard.vue';
import { TEST_HOST } from 'helpers/test_constants';

describe('operation settings external dashboard component', () => {
  let wrapper;
  const externalDashboardPath = `http://mock-external-domain.com/external/dashboard/path`;
  const externalDashboardHelpPagePath = `${TEST_HOST}/help/page/path`;

  beforeEach(() => {
    wrapper = shallowMount(ExternalDashboard, {
      propsData: {
        externalDashboardPath,
        externalDashboardHelpPagePath,
      },
    });
  });

  it('renders header text', () => {
    expect(wrapper.find('.js-section-header').text()).toBe('External Dashboard');
  });

A
Adriel Santiago 已提交
24 25 26 27 28 29 30 31
  describe('expand/collapse button', () => {
    it('renders as an expand button by default', () => {
      const button = wrapper.find(GlButton);

      expect(button.text()).toBe('Expand');
    });
  });

A
Adriel Santiago 已提交
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
  describe('sub-header', () => {
    let subHeader;

    beforeEach(() => {
      subHeader = wrapper.find('.js-section-sub-header');
    });

    it('renders descriptive text', () => {
      expect(subHeader.text()).toContain(
        'Add a button to the metrics dashboard linking directly to your existing external dashboards.',
      );
    });

    it('renders help page link', () => {
      const link = subHeader.find(GlLink);

      expect(link.text()).toBe('Learn more');
      expect(link.attributes().href).toBe(externalDashboardHelpPagePath);
    });
  });

  describe('form', () => {
    let form;

    beforeEach(() => {
      form = wrapper.find('form');
    });

    describe('external dashboard url', () => {
      describe('input label', () => {
        let formGroup;

        beforeEach(() => {
          formGroup = form.find(GlFormGroup);
        });

        it('uses label text', () => {
          expect(formGroup.attributes().label).toBe('Full dashboard URL');
        });

        it('uses description text', () => {
          expect(formGroup.attributes().description).toBe(
            'Enter the URL of the dashboard you want to link to',
          );
        });
      });

      describe('input field', () => {
        let input;

        beforeEach(() => {
          input = form.find(GlFormInput);
        });

        it('defaults to externalDashboardPath prop', () => {
          expect(input.attributes().value).toBe(externalDashboardPath);
        });

        it('uses a placeholder', () => {
          expect(input.attributes().placeholder).toBe('https://my-org.gitlab.io/my-dashboards');
        });
      });

      describe('submit button', () => {
        let submit;

        beforeEach(() => {
          submit = form.find(GlButton);
        });

        it('renders button label', () => {
          expect(submit.text()).toBe('Save Changes');
        });
      });
    });
  });
});