summaryrefslogtreecommitdiff
path: root/spec/frontend/pages
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-11-02 09:08:35 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-11-02 09:08:35 +0000
commit94823a9248837114ec84582f83b642ec45fe68ad (patch)
treeb8e9fec80a6df5af5449ab47e46a2570da183426 /spec/frontend/pages
parent26c50e0eb9e1513e60e3a38e538f25f682146ac6 (diff)
downloadgitlab-ce-94823a9248837114ec84582f83b642ec45fe68ad.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/pages')
-rw-r--r--spec/frontend/pages/projects/pipeline_schedules/shared/components/pipeline_schedule_callout_spec.js106
1 files changed, 47 insertions, 59 deletions
diff --git a/spec/frontend/pages/projects/pipeline_schedules/shared/components/pipeline_schedule_callout_spec.js b/spec/frontend/pages/projects/pipeline_schedules/shared/components/pipeline_schedule_callout_spec.js
index 51af3cbdf74..cfe54016410 100644
--- a/spec/frontend/pages/projects/pipeline_schedules/shared/components/pipeline_schedule_callout_spec.js
+++ b/spec/frontend/pages/projects/pipeline_schedules/shared/components/pipeline_schedule_callout_spec.js
@@ -1,110 +1,98 @@
-import Vue from 'vue';
+import { shallowMount } from '@vue/test-utils';
+import { GlButton } from '@gitlab/ui';
import Cookies from 'js-cookie';
-import { getByRole } from '@testing-library/dom';
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';
+const illustrationUrl = 'pages/projects/pipeline_schedules/shared/icons/intro_illustration.svg';
describe('Pipeline Schedule Callout', () => {
- let calloutComponent;
+ let wrapper;
- 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();
+ const createComponent = () => {
+ wrapper = shallowMount(PipelineSchedulesCallout, {
+ provide: {
+ docsUrl,
+ illustrationUrl,
+ },
});
+ };
- it('correctly sets docsUrl', () => {
- expect(calloutComponent.docsUrl).toContain(docsUrl);
- });
-
- it('correctly sets imageUrl', () => {
- expect(calloutComponent.imageUrl).toContain(imageUrl);
- });
- });
+ const findInnerContentOfCallout = () => wrapper.find('[data-testid="innerContent"]');
+ const findDismissCalloutBtn = () => wrapper.find(GlButton);
describe(`when ${cookieKey} cookie is set`, () => {
- beforeEach(() => {
+ beforeEach(async () => {
Cookies.set(cookieKey, true);
- calloutComponent = new PipelineSchedulesCalloutComponent().$mount();
+ createComponent();
+
+ await wrapper.vm.$nextTick();
});
- it('correctly sets calloutDismissed to true', () => {
- expect(calloutComponent.calloutDismissed).toBe(true);
+ afterEach(() => {
+ wrapper.destroy();
});
it('does not render the callout', () => {
- expect(calloutComponent.$el.childNodes.length).toBe(0);
+ expect(findInnerContentOfCallout().exists()).toBe(false);
});
});
describe('when cookie is not set', () => {
beforeEach(() => {
Cookies.remove(cookieKey);
- calloutComponent = new PipelineSchedulesCalloutComponent().$mount();
+ createComponent();
});
- it('correctly sets calloutDismissed to false', () => {
- expect(calloutComponent.calloutDismissed).toBe(false);
+ afterEach(() => {
+ wrapper.destroy();
});
it('renders the callout container', () => {
- expect(calloutComponent.$el.querySelector('.bordered-box')).not.toBeNull();
- });
-
- it('renders the callout img', () => {
- expect(calloutComponent.$el.outerHTML).toContain('<img');
+ expect(findInnerContentOfCallout().exists()).toBe(true);
});
it('renders the callout title', () => {
- expect(calloutComponent.$el.outerHTML).toContain('Scheduling Pipelines');
+ expect(wrapper.find('h4').text()).toBe('Scheduling Pipelines');
});
it('renders the callout text', () => {
- expect(calloutComponent.$el.outerHTML).toContain('runs pipelines in the future');
+ expect(wrapper.find('p').text()).toContain('runs pipelines in the future');
});
it('renders the documentation url', () => {
- expect(calloutComponent.$el.outerHTML).toContain(docsUrl);
+ expect(wrapper.find('a').attributes('href')).toBe(docsUrl);
});
- it('updates calloutDismissed when close button is clicked', done => {
- getByRole(calloutComponent.$el, 'button', /dismiss/i).click();
+ describe('methods', () => {
+ it('#dismissCallout sets calloutDismissed to true', async () => {
+ expect(wrapper.vm.calloutDismissed).toBe(false);
+
+ findDismissCalloutBtn().vm.$emit('click');
+
+ await wrapper.vm.$nextTick();
- Vue.nextTick(() => {
- expect(calloutComponent.calloutDismissed).toBe(true);
- done();
+ expect(findInnerContentOfCallout().exists()).toBe(false);
});
- });
- it('#dismissCallout updates calloutDismissed', done => {
- calloutComponent.dismissCallout();
+ it('sets cookie on dismiss', () => {
+ const setCookiesSpy = jest.spyOn(Cookies, 'set');
+
+ findDismissCalloutBtn().vm.$emit('click');
- Vue.nextTick(() => {
- expect(calloutComponent.calloutDismissed).toBe(true);
- done();
+ expect(setCookiesSpy).toHaveBeenCalledWith('pipeline_schedules_callout_dismissed', true, {
+ expires: 365,
+ });
});
});
- it('is hidden when close button is clicked', done => {
- getByRole(calloutComponent.$el, 'button', /dismiss/i).click();
+ it('is hidden when close button is clicked', async () => {
+ findDismissCalloutBtn().vm.$emit('click');
- Vue.nextTick(() => {
- expect(calloutComponent.$el.childNodes.length).toBe(0);
- done();
- });
+ await wrapper.vm.$nextTick();
+
+ expect(findInnerContentOfCallout().exists()).toBe(false);
});
});
});