Commit 100a2dd9 authored by Olena Horal-Koretska's avatar Olena Horal-Koretska

Merge branch '336360-upsell-the-gitlab-terraform-features-iteration-2-fe' into 'master'

Upsell the GitLab Terraform features - iteration 2

See merge request gitlab-org/gitlab!68135
parents 5fc32509 0a888229
<script> <script>
import { GlBanner } from '@gitlab/ui'; import { GlBanner } from '@gitlab/ui';
import { helpPagePath } from '~/helpers/help_page_helper'; import { helpPagePath } from '~/helpers/help_page_helper';
import { parseBoolean, setCookie, getCookie } from '~/lib/utils/common_utils'; import { setCookie } from '~/lib/utils/common_utils';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
export default { export default {
...@@ -16,50 +16,36 @@ export default { ...@@ -16,50 +16,36 @@ export default {
components: { components: {
GlBanner, GlBanner,
}, },
props: { inject: ['terraformImagePath', 'bannerDismissedKey'],
projectId: {
type: Number,
required: true,
},
},
data() { data() {
return { return {
isVisible: true, isVisible: true,
}; };
}, },
computed: { computed: {
bannerDissmisedKey() {
return `terraform_notification_dismissed_for_project_${this.projectId}`;
},
docsUrl() { docsUrl() {
return helpPagePath('user/infrastructure/terraform_state'); return helpPagePath('user/infrastructure/terraform_state');
}, },
}, },
created() {
if (parseBoolean(getCookie(this.bannerDissmisedKey))) {
this.isVisible = false;
}
},
methods: { methods: {
handleClose() { handleClose() {
setCookie(this.bannerDissmisedKey, true); setCookie(this.bannerDismissedKey, true);
this.isVisible = false; this.isVisible = false;
}, },
}, },
}; };
</script> </script>
<template> <template>
<div v-if="isVisible"> <div v-if="isVisible" class="gl-py-5">
<div class="gl-py-5">
<gl-banner <gl-banner
:title="$options.i18n.title" :title="$options.i18n.title"
:button-text="$options.i18n.buttonText" :button-text="$options.i18n.buttonText"
:button-link="docsUrl" :button-link="docsUrl"
variant="introduction" :svg-path="terraformImagePath"
variant="promotion"
@close="handleClose" @close="handleClose"
> >
<p>{{ $options.i18n.description }}</p> <p>{{ $options.i18n.description }}</p>
</gl-banner> </gl-banner>
</div> </div>
</div>
</template> </template>
import Vue from 'vue'; import Vue from 'vue';
import { parseBoolean, getCookie } from '~/lib/utils/common_utils';
import TerraformNotification from './components/terraform_notification.vue'; import TerraformNotification from './components/terraform_notification.vue';
export default () => { export default () => {
const el = document.querySelector('.js-terraform-notification'); const el = document.querySelector('.js-terraform-notification');
const bannerDismissedKey = 'terraform_notification_dismissed';
if (!el) { if (!el || parseBoolean(getCookie(bannerDismissedKey))) {
return false; return false;
} }
const { projectId } = el.dataset; const { terraformImagePath } = el.dataset;
return new Vue({ return new Vue({
el, el,
render: (createElement) => provide: {
createElement(TerraformNotification, { props: { projectId: Number(projectId) } }), terraformImagePath,
bannerDismissedKey,
},
render: (createElement) => createElement(TerraformNotification),
}); });
}; };
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
- if show_terraform_banner?(project) - if show_terraform_banner?(project)
.container-fluid{ class: @content_class } .container-fluid{ class: @content_class }
.js-terraform-notification{ data: { project_id: project.id } } .js-terraform-notification{ data: { terraform_image_path: image_path('illustrations/third-party-logos/ci_cd-template-logos/terraform.svg') } }
...@@ -5,19 +5,21 @@ import TerraformNotification from '~/projects/terraform_notification/components/ ...@@ -5,19 +5,21 @@ import TerraformNotification from '~/projects/terraform_notification/components/
jest.mock('~/lib/utils/common_utils'); jest.mock('~/lib/utils/common_utils');
const bannerDissmisedKey = 'terraform_notification_dismissed_for_project_1'; const terraformImagePath = '/path/to/image';
const bannerDismissedKey = 'terraform_notification_dismissed';
describe('TerraformNotificationBanner', () => { describe('TerraformNotificationBanner', () => {
let wrapper; let wrapper;
const propsData = { const provideData = {
projectId: 1, terraformImagePath,
bannerDismissedKey,
}; };
const findBanner = () => wrapper.findComponent(GlBanner); const findBanner = () => wrapper.findComponent(GlBanner);
beforeEach(() => { beforeEach(() => {
wrapper = shallowMount(TerraformNotification, { wrapper = shallowMount(TerraformNotification, {
propsData, provide: provideData,
stubs: { GlBanner }, stubs: { GlBanner },
}); });
}); });
...@@ -27,19 +29,6 @@ describe('TerraformNotificationBanner', () => { ...@@ -27,19 +29,6 @@ describe('TerraformNotificationBanner', () => {
parseBoolean.mockReturnValue(false); parseBoolean.mockReturnValue(false);
}); });
describe('when the dismiss cookie is set', () => {
beforeEach(() => {
parseBoolean.mockReturnValue(true);
wrapper = shallowMount(TerraformNotification, {
propsData,
});
});
it('should not render the banner', () => {
expect(findBanner().exists()).toBe(false);
});
});
describe('when the dismiss cookie is not set', () => { describe('when the dismiss cookie is not set', () => {
it('should render the banner', () => { it('should render the banner', () => {
expect(findBanner().exists()).toBe(true); expect(findBanner().exists()).toBe(true);
...@@ -51,8 +40,8 @@ describe('TerraformNotificationBanner', () => { ...@@ -51,8 +40,8 @@ describe('TerraformNotificationBanner', () => {
await findBanner().vm.$emit('close'); await findBanner().vm.$emit('close');
}); });
it('should set the cookie with the bannerDissmisedKey', () => { it('should set the cookie with the bannerDismissedKey', () => {
expect(setCookie).toHaveBeenCalledWith(bannerDissmisedKey, true); expect(setCookie).toHaveBeenCalledWith(bannerDismissedKey, true);
}); });
it('should remove the banner', () => { it('should remove the banner', () => {
......
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