2023-03-04 22:38:38 +05:30
import { createWrapper } from '@vue/test-utils' ;
2023-01-13 00:05:48 +05:30
import { setHTMLFixture , resetHTMLFixture } from 'helpers/fixtures' ;
import initGitlabVersionCheck from '~/gitlab_version_check' ;
2023-03-04 22:38:38 +05:30
import {
VERSION _CHECK _BADGE _NO _PROP _FIXTURE ,
VERSION _CHECK _BADGE _NO _SEVERITY _FIXTURE ,
VERSION _CHECK _BADGE _FIXTURE ,
VERSION _CHECK _BADGE _FINDER ,
VERSION _BADGE _TEXT ,
SECURITY _PATCH _FIXTURE ,
SECURITY _PATCH _FINDER ,
SECURITY _PATCH _TEXT ,
SECURITY _MODAL _FIXTURE ,
SECURITY _MODAL _FINDER ,
SECURITY _MODAL _TEXT ,
} from './mock_data' ;
2023-01-13 00:05:48 +05:30
describe ( 'initGitlabVersionCheck' , ( ) => {
2023-03-04 22:38:38 +05:30
let wrapper ;
2023-01-13 00:05:48 +05:30
2023-03-04 22:38:38 +05:30
const createApp = ( fixture ) => {
setHTMLFixture ( fixture ) ;
initGitlabVersionCheck ( ) ;
wrapper = createWrapper ( document . body ) ;
2023-01-13 00:05:48 +05:30
} ;
afterEach ( ( ) => {
resetHTMLFixture ( ) ;
} ) ;
describe . each `
2023-03-04 22:38:38 +05:30
description | fixture | finders | componentTexts
$ { 'with no version check elements' } | $ { '<div></div>' } | $ { [ ] } | $ { [ ] }
$ { 'with version check badge el but no prop data' } | $ { VERSION _CHECK _BADGE _NO _PROP _FIXTURE } | $ { [ VERSION _CHECK _BADGE _FINDER ] } | $ { [ undefined ] }
$ { 'with version check badge el but no severity data' } | $ { VERSION _CHECK _BADGE _NO _SEVERITY _FIXTURE } | $ { [ VERSION _CHECK _BADGE _FINDER ] } | $ { [ undefined ] }
$ { 'with version check badge el and version data' } | $ { VERSION _CHECK _BADGE _FIXTURE } | $ { [ VERSION _CHECK _BADGE _FINDER ] } | $ { [ VERSION _BADGE _TEXT ] }
$ { 'with security patch el' } | $ { SECURITY _PATCH _FIXTURE } | $ { [ SECURITY _PATCH _FINDER ] } | $ { [ SECURITY _PATCH _TEXT ] }
$ { 'with security patch and version badge els' } | $ { ` ${ SECURITY _PATCH _FIXTURE } ${ VERSION _CHECK _BADGE _FIXTURE } ` } | $ { [ SECURITY _PATCH _FINDER , VERSION _CHECK _BADGE _FINDER ] } | $ { [ SECURITY _PATCH _TEXT , VERSION _BADGE _TEXT ] }
$ { 'with security modal el' } | $ { SECURITY _MODAL _FIXTURE } | $ { [ SECURITY _MODAL _FINDER ] } | $ { [ SECURITY _MODAL _TEXT ] }
$ { 'with security modal, security patch, and version badge els' } | $ { ` ${ SECURITY _PATCH _FIXTURE } ${ SECURITY _MODAL _FIXTURE } ${ VERSION _CHECK _BADGE _FIXTURE } ` } | $ { [ SECURITY _PATCH _FINDER , SECURITY _MODAL _FINDER , VERSION _CHECK _BADGE _FINDER ] } | $ { [ SECURITY _PATCH _TEXT , SECURITY _MODAL _TEXT , VERSION _BADGE _TEXT ] }
` (' $ description', ({ fixture, finders, componentTexts }) => {
beforeEach ( ( ) => {
createApp ( fixture ) ;
} ) ;
it ( ` correctly renders the Version Check Components ` , ( ) => {
const renderedComponentTexts = finders . map ( ( f ) => wrapper . find ( f ) ? . element ? . innerText . trim ( ) ) ;
expect ( renderedComponentTexts ) . toStrictEqual ( componentTexts ) ;
2023-01-13 00:05:48 +05:30
} ) ;
} ) ;
} ) ;