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

pipeline_schedule_callout_spec.js « components « shared « pipeline_schedules « projects « pages « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ca7f70f443471fee4479a088111fca73ab3f45cd (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { GlButton } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import Cookies from '~/lib/utils/cookies';
import PipelineSchedulesCallout from '~/pages/projects/pipeline_schedules/shared/components/pipeline_schedules_callout.vue';

const cookieKey = 'pipeline_schedules_callout_dismissed';
const docsUrl = 'help/ci/scheduled_pipelines';
const illustrationUrl = 'pages/projects/pipeline_schedules/shared/icons/intro_illustration.svg';

describe('Pipeline Schedule Callout', () => {
  let wrapper;

  const createComponent = () => {
    wrapper = shallowMount(PipelineSchedulesCallout, {
      provide: {
        docsUrl,
        illustrationUrl,
      },
    });
  };

  const findInnerContentOfCallout = () => wrapper.find('[data-testid="innerContent"]');
  const findDismissCalloutBtn = () => wrapper.find(GlButton);

  describe(`when ${cookieKey} cookie is set`, () => {
    beforeEach(async () => {
      Cookies.set(cookieKey, true);
      createComponent();

      await nextTick();
    });

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

    it('does not render the callout', () => {
      expect(findInnerContentOfCallout().exists()).toBe(false);
    });
  });

  describe('when cookie is not set', () => {
    beforeEach(() => {
      Cookies.remove(cookieKey);
      createComponent();
    });

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

    it('renders the callout container', () => {
      expect(findInnerContentOfCallout().exists()).toBe(true);
    });

    it('renders the callout title', () => {
      expect(wrapper.find('h4').text()).toBe('Scheduling Pipelines');
    });

    it('renders the callout text', () => {
      expect(wrapper.find('p').text()).toContain('runs pipelines in the future');
    });

    it('renders the documentation url', () => {
      expect(wrapper.find('a').attributes('href')).toBe(docsUrl);
    });

    describe('methods', () => {
      it('#dismissCallout sets calloutDismissed to true', async () => {
        expect(wrapper.vm.calloutDismissed).toBe(false);

        findDismissCalloutBtn().vm.$emit('click');

        await nextTick();

        expect(findInnerContentOfCallout().exists()).toBe(false);
      });

      it('sets cookie on dismiss', () => {
        const setCookiesSpy = jest.spyOn(Cookies, 'set');

        findDismissCalloutBtn().vm.$emit('click');

        expect(setCookiesSpy).toHaveBeenCalledWith('pipeline_schedules_callout_dismissed', true, {
          expires: 365,
          secure: false,
        });
      });
    });

    it('is hidden when close button is clicked', async () => {
      findDismissCalloutBtn().vm.$emit('click');

      await nextTick();

      expect(findInnerContentOfCallout().exists()).toBe(false);
    });
  });
});