Commit bb5dcfa9 authored by Vitaly Slobodin's avatar Vitaly Slobodin Committed by Natalia Tepluhina

Move constant values to props

Constant values like URLs and image URLs does not
need to be reactive. For performance reasons we should
move them to props.
parent e69eba78
import Vue from 'vue'; import Vue from 'vue';
import PipelineSchedulesCallout from '../shared/components/pipeline_schedules_callout.vue'; import PipelineSchedulesCallout from '../shared/components/pipeline_schedules_callout.vue';
document.addEventListener( document.addEventListener('DOMContentLoaded', () => {
'DOMContentLoaded', const el = document.getElementById('pipeline-schedules-callout');
() =>
if (!el) {
return;
}
const { docsUrl, illustrationUrl } = el.dataset;
// eslint-disable-next-line no-new
new Vue({ new Vue({
el: '#pipeline-schedules-callout', el,
components: {
'pipeline-schedules-callout': PipelineSchedulesCallout,
},
render(createElement) { render(createElement) {
return createElement('pipeline-schedules-callout'); return createElement(PipelineSchedulesCallout);
},
provide: {
docsUrl,
illustrationUrl,
}, },
}), });
); });
...@@ -14,10 +14,9 @@ export default { ...@@ -14,10 +14,9 @@ export default {
components: { components: {
GlButton, GlButton,
}, },
inject: ['docsUrl', 'illustrationUrl'],
data() { data() {
return { return {
docsUrl: document.getElementById('pipeline-schedules-callout').dataset.docsUrl,
imageUrl: document.getElementById('pipeline-schedules-callout').dataset.imageUrl,
calloutDismissed: parseBoolean(Cookies.get(cookieKey)), calloutDismissed: parseBoolean(Cookies.get(cookieKey)),
}; };
}, },
...@@ -31,7 +30,7 @@ export default { ...@@ -31,7 +30,7 @@ export default {
</script> </script>
<template> <template>
<div v-if="!calloutDismissed" class="pipeline-schedules-user-callout user-callout"> <div v-if="!calloutDismissed" class="pipeline-schedules-user-callout user-callout">
<div class="bordered-box landing content-block"> <div class="bordered-box landing content-block" data-testid="innerContent">
<gl-button <gl-button
category="tertiary" category="tertiary"
icon="close" icon="close"
...@@ -39,8 +38,8 @@ export default { ...@@ -39,8 +38,8 @@ export default {
class="gl-absolute gl-top-2 gl-right-2" class="gl-absolute gl-top-2 gl-right-2"
@click="dismissCallout" @click="dismissCallout"
/> />
<div class="svg-container"> <div class="svg-content">
<img :src="imageUrl" /> <img :src="illustrationUrl" />
</div> </div>
<div class="user-callout-copy"> <div class="user-callout-copy">
<h4>{{ __('Scheduling Pipelines') }}</h4> <h4>{{ __('Scheduling Pipelines') }}</h4>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
- page_title _("Pipeline Schedules") - page_title _("Pipeline Schedules")
- add_page_specific_style 'page_bundles/pipeline_schedules' - add_page_specific_style 'page_bundles/pipeline_schedules'
#pipeline-schedules-callout{ data: { docs_url: help_page_path('ci/pipelines/schedules'), image_url: image_path('illustrations/pipeline_schedule_callout.svg') } } #pipeline-schedules-callout{ data: { docs_url: help_page_path('ci/pipelines/schedules'), illustration_url: image_path('illustrations/pipeline_schedule_callout.svg') } }
.top-area .top-area
- schedule_path_proc = ->(scope) { pipeline_schedules_path(@project, scope: scope) } - schedule_path_proc = ->(scope) { pipeline_schedules_path(@project, scope: scope) }
= render "tabs", schedule_path_proc: schedule_path_proc, all_schedules: @all_schedules, scope: @scope = render "tabs", schedule_path_proc: schedule_path_proc, all_schedules: @all_schedules, scope: @scope
......
import Vue from 'vue'; import { shallowMount } from '@vue/test-utils';
import { GlButton } from '@gitlab/ui';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import { getByRole } from '@testing-library/dom';
import PipelineSchedulesCallout from '~/pages/projects/pipeline_schedules/shared/components/pipeline_schedules_callout.vue'; 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 cookieKey = 'pipeline_schedules_callout_dismissed';
const docsUrl = 'help/ci/scheduled_pipelines'; 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', () => { describe('Pipeline Schedule Callout', () => {
let calloutComponent; let wrapper;
beforeEach(() => { const createComponent = () => {
setFixtures(` wrapper = shallowMount(PipelineSchedulesCallout, {
<div id='pipeline-schedules-callout' data-docs-url=${docsUrl} data-image-url=${imageUrl}></div> provide: {
`); docsUrl,
}); illustrationUrl,
},
describe('independent of cookies', () => {
beforeEach(() => {
calloutComponent = new PipelineSchedulesCalloutComponent().$mount();
}); });
};
it('the component can be initialized', () => { const findInnerContentOfCallout = () => wrapper.find('[data-testid="innerContent"]');
expect(calloutComponent).toBeDefined(); const findDismissCalloutBtn = () => wrapper.find(GlButton);
});
it('correctly sets docsUrl', () => {
expect(calloutComponent.docsUrl).toContain(docsUrl);
});
it('correctly sets imageUrl', () => {
expect(calloutComponent.imageUrl).toContain(imageUrl);
});
});
describe(`when ${cookieKey} cookie is set`, () => { describe(`when ${cookieKey} cookie is set`, () => {
beforeEach(() => { beforeEach(async () => {
Cookies.set(cookieKey, true); Cookies.set(cookieKey, true);
calloutComponent = new PipelineSchedulesCalloutComponent().$mount(); createComponent();
await wrapper.vm.$nextTick();
}); });
it('correctly sets calloutDismissed to true', () => { afterEach(() => {
expect(calloutComponent.calloutDismissed).toBe(true); wrapper.destroy();
}); });
it('does not render the callout', () => { it('does not render the callout', () => {
expect(calloutComponent.$el.childNodes.length).toBe(0); expect(findInnerContentOfCallout().exists()).toBe(false);
}); });
}); });
describe('when cookie is not set', () => { describe('when cookie is not set', () => {
beforeEach(() => { beforeEach(() => {
Cookies.remove(cookieKey); Cookies.remove(cookieKey);
calloutComponent = new PipelineSchedulesCalloutComponent().$mount(); createComponent();
}); });
it('correctly sets calloutDismissed to false', () => { afterEach(() => {
expect(calloutComponent.calloutDismissed).toBe(false); wrapper.destroy();
}); });
it('renders the callout container', () => { it('renders the callout container', () => {
expect(calloutComponent.$el.querySelector('.bordered-box')).not.toBeNull(); expect(findInnerContentOfCallout().exists()).toBe(true);
});
it('renders the callout img', () => {
expect(calloutComponent.$el.outerHTML).toContain('<img');
}); });
it('renders the callout title', () => { 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', () => { 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', () => { 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 => { describe('methods', () => {
getByRole(calloutComponent.$el, 'button', /dismiss/i).click(); it('#dismissCallout sets calloutDismissed to true', async () => {
expect(wrapper.vm.calloutDismissed).toBe(false);
Vue.nextTick(() => { findDismissCalloutBtn().vm.$emit('click');
expect(calloutComponent.calloutDismissed).toBe(true);
done(); await wrapper.vm.$nextTick();
});
expect(findInnerContentOfCallout().exists()).toBe(false);
}); });
it('#dismissCallout updates calloutDismissed', done => { it('sets cookie on dismiss', () => {
calloutComponent.dismissCallout(); const setCookiesSpy = jest.spyOn(Cookies, 'set');
findDismissCalloutBtn().vm.$emit('click');
Vue.nextTick(() => { expect(setCookiesSpy).toHaveBeenCalledWith('pipeline_schedules_callout_dismissed', true, {
expect(calloutComponent.calloutDismissed).toBe(true); expires: 365,
done(); });
}); });
}); });
it('is hidden when close button is clicked', done => { it('is hidden when close button is clicked', async () => {
getByRole(calloutComponent.$el, 'button', /dismiss/i).click(); findDismissCalloutBtn().vm.$emit('click');
Vue.nextTick(() => { await wrapper.vm.$nextTick();
expect(calloutComponent.$el.childNodes.length).toBe(0);
done(); expect(findInnerContentOfCallout().exists()).toBe(false);
});
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment