summaryrefslogtreecommitdiff
path: root/spec/frontend/pages/projects/pipeline_schedules/shared/components/pipeline_schedule_callout_spec.js
blob: 5da998d9d2d2b56487c6ffc7f5c1c0f5cc10f167 (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
101
102
103
104
105
106
107
108
109
import Vue from 'vue';
import Cookies from 'js-cookie';
import PipelineSchedulesCallout from '~/pages/projects/pipeline_schedules/shared/components/pipeline_schedules_callout.vue';

const PipelineSchedulesCalloutComponent = Vue.extend(PipelineSchedulesCallout);
const cookieKey = 'pipeline_schedules_callout_dismissed';
const docsUrl = 'help/ci/scheduled_pipelines';
const imageUrl = 'pages/projects/pipeline_schedules/shared/icons/intro_illustration.svg';

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

  beforeEach(() => {
    setFixtures(`
      <div id='pipeline-schedules-callout' data-docs-url=${docsUrl} data-image-url=${imageUrl}></div>
    `);
  });

  describe('independent of cookies', () => {
    beforeEach(() => {
      calloutComponent = new PipelineSchedulesCalloutComponent().$mount();
    });

    it('the component can be initialized', () => {
      expect(calloutComponent).toBeDefined();
    });

    it('correctly sets docsUrl', () => {
      expect(calloutComponent.docsUrl).toContain(docsUrl);
    });

    it('correctly sets imageUrl', () => {
      expect(calloutComponent.imageUrl).toContain(imageUrl);
    });
  });

  describe(`when ${cookieKey} cookie is set`, () => {
    beforeEach(() => {
      Cookies.set(cookieKey, true);
      calloutComponent = new PipelineSchedulesCalloutComponent().$mount();
    });

    it('correctly sets calloutDismissed to true', () => {
      expect(calloutComponent.calloutDismissed).toBe(true);
    });

    it('does not render the callout', () => {
      expect(calloutComponent.$el.childNodes.length).toBe(0);
    });
  });

  describe('when cookie is not set', () => {
    beforeEach(() => {
      Cookies.remove(cookieKey);
      calloutComponent = new PipelineSchedulesCalloutComponent().$mount();
    });

    it('correctly sets calloutDismissed to false', () => {
      expect(calloutComponent.calloutDismissed).toBe(false);
    });

    it('renders the callout container', () => {
      expect(calloutComponent.$el.querySelector('.bordered-box')).not.toBeNull();
    });

    it('renders the callout img', () => {
      expect(calloutComponent.$el.outerHTML).toContain('<img');
    });

    it('renders the callout title', () => {
      expect(calloutComponent.$el.outerHTML).toContain('Scheduling Pipelines');
    });

    it('renders the callout text', () => {
      expect(calloutComponent.$el.outerHTML).toContain('runs pipelines in the future');
    });

    it('renders the documentation url', () => {
      expect(calloutComponent.$el.outerHTML).toContain(docsUrl);
    });

    it('updates calloutDismissed when close button is clicked', done => {
      calloutComponent.$el.querySelector('#dismiss-callout-btn').click();

      Vue.nextTick(() => {
        expect(calloutComponent.calloutDismissed).toBe(true);
        done();
      });
    });

    it('#dismissCallout updates calloutDismissed', done => {
      calloutComponent.dismissCallout();

      Vue.nextTick(() => {
        expect(calloutComponent.calloutDismissed).toBe(true);
        done();
      });
    });

    it('is hidden when close button is clicked', done => {
      calloutComponent.$el.querySelector('#dismiss-callout-btn').click();

      Vue.nextTick(() => {
        expect(calloutComponent.$el.childNodes.length).toBe(0);
        done();
      });
    });
  });
});