Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
5de31afb
Commit
5de31afb
authored
Sep 09, 2021
by
Anna Vovchenko
Committed by
Michael Lunøe
Sep 09, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upsell the GitLab Terraform features - iteration 3 frontend
parent
7043b942
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
50 deletions
+68
-50
app/assets/javascripts/projects/terraform_notification/components/terraform_notification.vue
...raform_notification/components/terraform_notification.vue
+22
-23
app/assets/javascripts/projects/terraform_notification/index.js
...sets/javascripts/projects/terraform_notification/index.js
+10
-4
spec/frontend/projects/terraform_notification/terraform_notification_spec.js
...cts/terraform_notification/terraform_notification_spec.js
+36
-23
No files found.
app/assets/javascripts/projects/terraform_notification/components/terraform_notification.vue
View file @
5de31afb
<
script
>
import
{
GlBanner
}
from
'
@gitlab/ui
'
;
import
{
helpPagePath
}
from
'
~/helpers/help_page_helper
'
;
import
{
setCookie
}
from
'
~/lib/utils/common_utils
'
;
import
{
s__
}
from
'
~/locale
'
;
import
Tracking
from
'
~/tracking
'
;
import
UserCalloutDismisser
from
'
~/vue_shared/components/user_callout_dismisser.vue
'
;
import
{
EVENT_LABEL
,
DISMISS_EVENT
,
CLICK_EVENT
}
from
'
../constants
'
;
const
trackingMixin
=
Tracking
.
mixin
({
label
:
EVENT_LABEL
});
...
...
@@ -19,24 +19,19 @@ export default {
},
components
:
{
GlBanner
,
UserCalloutDismisser
,
},
mixins
:
[
trackingMixin
],
inject
:
[
'
terraformImagePath
'
,
'
bannerDismissedKey
'
],
data
()
{
return
{
isVisible
:
true
,
};
},
inject
:
[
'
terraformImagePath
'
],
computed
:
{
docsUrl
()
{
return
helpPagePath
(
'
user/infrastructure/
terraform_state
'
);
return
helpPagePath
(
'
user/infrastructure/
iac/terraform_state.md
'
);
},
},
methods
:
{
handleClose
()
{
setCookie
(
this
.
bannerDismissedKey
,
true
);
this
.
isVisible
=
false
;
this
.
track
(
DISMISS_EVENT
);
this
.
$refs
.
calloutDismisser
.
dismiss
();
},
buttonClick
()
{
this
.
track
(
CLICK_EVENT
);
...
...
@@ -45,17 +40,21 @@ export default {
};
</
script
>
<
template
>
<div
v-if=
"isVisible"
class=
"gl-py-5"
>
<gl-banner
:title=
"$options.i18n.title"
:button-text=
"$options.i18n.buttonText"
:button-link=
"docsUrl"
:svg-path=
"terraformImagePath"
variant=
"promotion"
@
primary=
"buttonClick"
@
close=
"handleClose"
>
<p>
{{
$options
.
i18n
.
description
}}
</p>
</gl-banner>
</div>
<user-callout-dismisser
ref=
"calloutDismisser"
feature-name=
"terraform_notification_dismissed"
>
<template
#default
="
{ shouldShowCallout }">
<div
v-if=
"shouldShowCallout"
class=
"gl-py-5"
>
<gl-banner
:title=
"$options.i18n.title"
:button-text=
"$options.i18n.buttonText"
:button-link=
"docsUrl"
:svg-path=
"terraformImagePath"
variant=
"promotion"
@
primary=
"buttonClick"
@
close=
"handleClose"
>
<p>
{{
$options
.
i18n
.
description
}}
</p>
</gl-banner>
</div>
</
template
>
</user-callout-dismisser>
</template>
app/assets/javascripts/projects/terraform_notification/index.js
View file @
5de31afb
import
Vue
from
'
vue
'
;
import
{
parseBoolean
,
getCookie
}
from
'
~/lib/utils/common_utils
'
;
import
VueApollo
from
'
vue-apollo
'
;
import
createDefaultClient
from
'
~/lib/graphql
'
;
import
TerraformNotification
from
'
./components/terraform_notification.vue
'
;
Vue
.
use
(
VueApollo
);
const
apolloProvider
=
new
VueApollo
({
defaultClient
:
createDefaultClient
(),
});
export
default
()
=>
{
const
el
=
document
.
querySelector
(
'
.js-terraform-notification
'
);
const
bannerDismissedKey
=
'
terraform_notification_dismissed
'
;
if
(
!
el
||
parseBoolean
(
getCookie
(
bannerDismissedKey
))
)
{
if
(
!
el
)
{
return
false
;
}
...
...
@@ -14,9 +20,9 @@ export default () => {
return
new
Vue
({
el
,
apolloProvider
,
provide
:
{
terraformImagePath
,
bannerDismissedKey
,
},
render
:
(
createElement
)
=>
createElement
(
TerraformNotification
),
});
...
...
spec/frontend/projects/terraform_notification/terraform_notification_spec.js
View file @
5de31afb
import
{
GlBanner
}
from
'
@gitlab/ui
'
;
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
m
ockTracking
,
unmockTracking
}
from
'
helpers/tracking_help
er
'
;
import
{
setCookie
,
parseBoolean
}
from
'
~/lib/utils/common_utils
'
;
import
{
m
akeMockUserCalloutDismisser
}
from
'
helpers/mock_user_callout_dismiss
er
'
;
import
{
mockTracking
}
from
'
helpers/tracking_helper
'
;
import
TerraformNotification
from
'
~/projects/terraform_notification/components/terraform_notification.vue
'
;
import
{
EVENT_LABEL
,
...
...
@@ -9,64 +9,77 @@ import {
CLICK_EVENT
,
}
from
'
~/projects/terraform_notification/constants
'
;
jest
.
mock
(
'
~/lib/utils/common_utils
'
);
const
terraformImagePath
=
'
/path/to/image
'
;
const
bannerDismissedKey
=
'
terraform_notification_dismissed
'
;
describe
(
'
TerraformNotificationBanner
'
,
()
=>
{
let
wrapper
;
let
trackingSpy
;
let
userCalloutDismissSpy
;
const
provideData
=
{
terraformImagePath
,
bannerDismissedKey
,
};
const
findBanner
=
()
=>
wrapper
.
findComponent
(
GlBanner
);
beforeEach
(()
=>
{
const
createComponent
=
({
shouldShowCallout
=
true
}
=
{})
=>
{
userCalloutDismissSpy
=
jest
.
fn
();
wrapper
=
shallowMount
(
TerraformNotification
,
{
provide
:
provideData
,
stubs
:
{
GlBanner
},
stubs
:
{
GlBanner
,
UserCalloutDismisser
:
makeMockUserCalloutDismisser
({
dismiss
:
userCalloutDismissSpy
,
shouldShowCallout
,
}),
},
});
};
beforeEach
(()
=>
{
createComponent
();
trackingSpy
=
mockTracking
(
undefined
,
wrapper
.
element
,
jest
.
spyOn
);
});
afterEach
(()
=>
{
wrapper
.
destroy
();
parseBoolean
.
mockReturnValue
(
false
);
unmockTracking
();
});
describe
(
'
when the dismiss cookie is not set
'
,
()
=>
{
describe
(
'
when user has already dismissed the banner
'
,
()
=>
{
beforeEach
(()
=>
{
createComponent
({
shouldShowCallout
:
false
,
});
});
it
(
'
should not render the banner
'
,
()
=>
{
expect
(
findBanner
().
exists
()).
toBe
(
false
);
});
});
describe
(
"
when user hasn't yet dismissed the banner
"
,
()
=>
{
it
(
'
should render the banner
'
,
()
=>
{
expect
(
findBanner
().
exists
()).
toBe
(
true
);
});
});
describe
(
'
when close button is clicked
'
,
()
=>
{
beforeEach
(
async
()
=>
{
await
findBanner
().
vm
.
$emit
(
'
close
'
);
});
it
(
'
should set the cookie with the bannerDismissedKey
'
,
()
=>
{
expect
(
setCookie
).
toHaveBeenCalledWith
(
bannerDismissedKey
,
true
);
beforeEach
(()
=>
{
wrapper
.
vm
.
$refs
.
calloutDismisser
.
dismiss
=
userCalloutDismissSpy
;
findBanner
().
vm
.
$emit
(
'
close
'
);
});
it
(
'
should send the dismiss event
'
,
()
=>
{
expect
(
trackingSpy
).
toHaveBeenCalledWith
(
undefined
,
DISMISS_EVENT
,
{
label
:
EVENT_LABEL
,
});
});
it
(
'
should remove the banner
'
,
()
=>
{
expect
(
findBanner
().
exists
()).
toBe
(
false
);
it
(
'
should call the dismiss callback
'
,
()
=>
{
expect
(
userCalloutDismissSpy
).
toHaveBeenCalledTimes
(
1
);
});
});
describe
(
'
when docs link is clicked
'
,
()
=>
{
beforeEach
(
async
()
=>
{
await
findBanner
().
vm
.
$emit
(
'
primary
'
);
beforeEach
(()
=>
{
findBanner
().
vm
.
$emit
(
'
primary
'
);
});
it
(
'
should send button click event
'
,
()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment