summaryrefslogtreecommitdiff
path: root/spec/frontend/pages/shared/wikis/components/wiki_alert_spec.js
blob: 6a18473b1a73e4f2eb30f223849093f202eab856 (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
import { GlAlert, GlLink, GlSprintf } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import WikiAlert from '~/pages/shared/wikis/components/wiki_alert.vue';

describe('WikiAlert', () => {
  let wrapper;
  const ERROR = 'There is already a page with the same title in that path.';
  const ERROR_WITH_LINK = 'Before text %{wikiLinkStart}the page%{wikiLinkEnd} after text.';
  const PATH = '/test';

  function createWrapper(propsData = {}, stubs = {}) {
    wrapper = shallowMount(WikiAlert, {
      propsData: { wikiPagePath: PATH, ...propsData },
      stubs,
    });
  }

  afterEach(() => {
    wrapper.destroy();
    wrapper = null;
  });

  const findGlAlert = () => wrapper.findComponent(GlAlert);
  const findGlLink = () => wrapper.findComponent(GlLink);
  const findGlSprintf = () => wrapper.findComponent(GlSprintf);

  describe('Wiki Alert', () => {
    it('shows an alert when there is an error', () => {
      createWrapper({ error: ERROR });
      expect(findGlAlert().exists()).toBe(true);
      expect(findGlSprintf().exists()).toBe(true);
      expect(findGlSprintf().attributes('message')).toBe(ERROR);
    });

    it('shows a the link to the help path', () => {
      createWrapper({ error: ERROR_WITH_LINK }, { GlAlert, GlSprintf });
      expect(findGlLink().attributes('href')).toBe(PATH);
    });
  });
});