2021-06-08 01:23:25 +05:30
import { shallowMount } from '@vue/test-utils' ;
import Feature from '~/whats_new/components/feature.vue' ;
describe ( "What's new single feature" , ( ) => {
/** @type {import("@vue/test-utils").Wrapper} */
let wrapper ;
const exampleFeature = {
2022-08-27 11:52:29 +05:30
name : 'Compliance pipeline configurations' ,
description :
2021-09-04 01:27:46 +05:30
'<p data-testid="body-content">We are thrilled to announce that it is now possible to define enforceable pipelines that will run for any project assigned a corresponding <a href="https://en.wikipedia.org/wiki/Compliance_(psychology)" target="_blank" rel="noopener noreferrer" onload="alert(xss)">compliance</a> framework.</p>' ,
2021-06-08 01:23:25 +05:30
stage : 'Manage' ,
'self-managed' : true ,
'gitlab-com' : true ,
2022-08-27 11:52:29 +05:30
available _in : [ 'Ultimate' ] ,
documentation _link :
'https://docs.gitlab.com/ee/user/project/settings/#compliance-pipeline-configuration' ,
2021-06-08 01:23:25 +05:30
image _url : 'https://img.youtube.com/vi/upLJ_equomw/hqdefault.jpg' ,
published _at : '2021-04-22T00:00:00.000Z' ,
release : '13.11' ,
} ;
const findReleaseDate = ( ) => wrapper . find ( '[data-testid="release-date"]' ) ;
2021-09-04 01:27:46 +05:30
const findBodyAnchor = ( ) => wrapper . find ( '[data-testid="body-content"] a' ) ;
2022-07-16 23:28:13 +05:30
const findImageLink = ( ) => wrapper . find ( '[data-testid="whats-new-image-link"]' ) ;
2021-06-08 01:23:25 +05:30
const createWrapper = ( { feature } = { } ) => {
wrapper = shallowMount ( Feature , {
propsData : { feature } ,
} ) ;
} ;
afterEach ( ( ) => {
wrapper . destroy ( ) ;
wrapper = null ;
} ) ;
it ( 'renders the date' , ( ) => {
createWrapper ( { feature : exampleFeature } ) ;
2022-07-16 23:28:13 +05:30
2021-06-08 01:23:25 +05:30
expect ( findReleaseDate ( ) . text ( ) ) . toBe ( 'April 22, 2021' ) ;
} ) ;
2022-07-16 23:28:13 +05:30
it ( 'renders image link' , ( ) => {
createWrapper ( { feature : exampleFeature } ) ;
expect ( findImageLink ( ) . exists ( ) ) . toBe ( true ) ;
expect ( findImageLink ( ) . find ( 'div' ) . attributes ( 'style' ) ) . toBe (
` background-image: url( ${ exampleFeature . image _url } ); ` ,
) ;
} ) ;
describe ( 'when published_at is null' , ( ) => {
it ( 'does not render the date' , ( ) => {
2021-06-08 01:23:25 +05:30
createWrapper ( { feature : { ... exampleFeature , published _at : null } } ) ;
2022-07-16 23:28:13 +05:30
2021-06-08 01:23:25 +05:30
expect ( findReleaseDate ( ) . exists ( ) ) . toBe ( false ) ;
} ) ;
} ) ;
2021-09-04 01:27:46 +05:30
2022-07-16 23:28:13 +05:30
describe ( 'when image_url is null' , ( ) => {
it ( 'does not render image link' , ( ) => {
createWrapper ( { feature : { ... exampleFeature , image _url : null } } ) ;
expect ( findImageLink ( ) . exists ( ) ) . toBe ( false ) ;
} ) ;
} ) ;
2021-09-04 01:27:46 +05:30
it ( 'safe-html config allows target attribute on elements' , ( ) => {
createWrapper ( { feature : exampleFeature } ) ;
2022-07-16 23:28:13 +05:30
2021-09-04 01:27:46 +05:30
expect ( findBodyAnchor ( ) . attributes ( ) ) . toEqual ( {
href : expect . any ( String ) ,
rel : 'noopener noreferrer' ,
target : '_blank' ,
} ) ;
} ) ;
2021-06-08 01:23:25 +05:30
} ) ;