2018-08-28 03:53:48 -04:00
import Vue from 'vue' ;
import component from '~/jobs/components/environments_block.vue' ;
import mountComponent from '../../helpers/vue_mount_component_helper' ;
2019-10-15 17:06:25 -04:00
const TEST _CLUSTER _NAME = 'test_cluster' ;
const TEST _CLUSTER _PATH = 'path/to/test_cluster' ;
2020-02-14 04:08:43 -05:00
const TEST _KUBERNETES _NAMESPACE = 'this-is-a-kubernetes-namespace' ;
2019-10-15 17:06:25 -04:00
2018-08-28 03:53:48 -04:00
describe ( 'Environments block' , ( ) => {
const Component = Vue . extend ( component ) ;
let vm ;
2018-10-03 11:29:07 -04:00
const status = {
2018-08-28 03:53:48 -04:00
group : 'success' ,
icon : 'status_success' ,
label : 'passed' ,
text : 'passed' ,
tooltip : 'passed' ,
} ;
2018-10-03 11:29:07 -04:00
2018-08-28 03:53:48 -04:00
const environment = {
2018-10-03 11:29:07 -04:00
environment _path : '/environment' ,
2018-08-28 03:53:48 -04:00
name : 'environment' ,
} ;
2019-09-13 09:26:31 -04:00
const lastDeployment = { iid : 'deployment' , deployable : { build _path : 'bar' } } ;
2019-10-15 17:06:25 -04:00
const createEnvironmentWithLastDeployment = ( ) => ( {
... environment ,
last _deployment : { ... lastDeployment } ,
} ) ;
2020-02-14 04:08:43 -05:00
const createDeploymentWithCluster = ( ) => ( { name : TEST _CLUSTER _NAME , path : TEST _CLUSTER _PATH } ) ;
const createDeploymentWithClusterAndKubernetesNamespace = ( ) => ( {
name : TEST _CLUSTER _NAME ,
path : TEST _CLUSTER _PATH ,
kubernetes _namespace : TEST _KUBERNETES _NAMESPACE ,
2019-10-15 17:06:25 -04:00
} ) ;
2020-02-14 04:08:43 -05:00
const createComponent = ( deploymentStatus = { } , deploymentCluster = { } ) => {
2019-10-15 17:06:25 -04:00
vm = mountComponent ( Component , {
deploymentStatus ,
2020-02-14 04:08:43 -05:00
deploymentCluster ,
2019-10-15 17:06:25 -04:00
iconStatus : status ,
} ) ;
} ;
const findText = ( ) => vm . $el . textContent . trim ( ) ;
const findJobDeploymentLink = ( ) => vm . $el . querySelector ( '.js-job-deployment-link' ) ;
const findEnvironmentLink = ( ) => vm . $el . querySelector ( '.js-environment-link' ) ;
const findClusterLink = ( ) => vm . $el . querySelector ( '.js-job-cluster-link' ) ;
2018-08-28 03:53:48 -04:00
afterEach ( ( ) => {
vm . $destroy ( ) ;
} ) ;
2018-10-03 11:29:07 -04:00
describe ( 'with last deployment' , ( ) => {
2018-08-28 03:53:48 -04:00
it ( 'renders info for most recent deployment' , ( ) => {
2019-10-15 17:06:25 -04:00
createComponent ( {
status : 'last' ,
environment ,
2018-08-28 03:53:48 -04:00
} ) ;
2019-10-15 17:06:25 -04:00
expect ( findText ( ) ) . toEqual ( 'This job is deployed to environment.' ) ;
} ) ;
2020-02-14 04:08:43 -05:00
describe ( 'when there is a cluster' , ( ) => {
it ( 'renders info with cluster' , ( ) => {
createComponent (
{
status : 'last' ,
environment : createEnvironmentWithLastDeployment ( ) ,
} ,
createDeploymentWithCluster ( ) ,
) ;
expect ( findText ( ) ) . toEqual (
` This job is deployed to environment using cluster ${ TEST _CLUSTER _NAME } . ` ,
) ;
2019-10-15 17:06:25 -04:00
} ) ;
2020-02-14 04:08:43 -05:00
describe ( 'when there is a kubernetes namespace' , ( ) => {
it ( 'renders info with cluster' , ( ) => {
createComponent (
{
status : 'last' ,
environment : createEnvironmentWithLastDeployment ( ) ,
} ,
createDeploymentWithClusterAndKubernetesNamespace ( ) ,
) ;
expect ( findText ( ) ) . toEqual (
` This job is deployed to environment using cluster ${ TEST _CLUSTER _NAME } and namespace ${ TEST _KUBERNETES _NAMESPACE } . ` ,
) ;
} ) ;
} ) ;
2018-08-28 03:53:48 -04:00
} ) ;
} ) ;
describe ( 'with out of date deployment' , ( ) => {
describe ( 'with last deployment' , ( ) => {
it ( 'renders info for out date and most recent' , ( ) => {
2019-10-15 17:06:25 -04:00
createComponent ( {
status : 'out_of_date' ,
environment : createEnvironmentWithLastDeployment ( ) ,
2018-08-28 03:53:48 -04:00
} ) ;
2019-10-15 17:06:25 -04:00
expect ( findText ( ) ) . toEqual (
'This job is an out-of-date deployment to environment. View the most recent deployment.' ,
2018-08-28 03:53:48 -04:00
) ;
2018-10-09 14:03:09 -04:00
2019-10-15 17:06:25 -04:00
expect ( findJobDeploymentLink ( ) . getAttribute ( 'href' ) ) . toEqual ( 'bar' ) ;
} ) ;
2020-02-14 04:08:43 -05:00
describe ( 'when there is a cluster' , ( ) => {
it ( 'renders info with cluster' , ( ) => {
createComponent (
{
status : 'out_of_date' ,
environment : createEnvironmentWithLastDeployment ( ) ,
} ,
createDeploymentWithCluster ( ) ,
) ;
expect ( findText ( ) ) . toEqual (
` This job is an out-of-date deployment to environment using cluster ${ TEST _CLUSTER _NAME } . View the most recent deployment. ` ,
) ;
2019-10-15 17:06:25 -04:00
} ) ;
2020-02-14 04:08:43 -05:00
describe ( 'when there is a kubernetes namespace' , ( ) => {
it ( 'renders info with cluster' , ( ) => {
createComponent (
{
status : 'out_of_date' ,
environment : createEnvironmentWithLastDeployment ( ) ,
} ,
createDeploymentWithClusterAndKubernetesNamespace ( ) ,
) ;
expect ( findText ( ) ) . toEqual (
` This job is an out-of-date deployment to environment using cluster ${ TEST _CLUSTER _NAME } and namespace ${ TEST _KUBERNETES _NAMESPACE } . View the most recent deployment. ` ,
) ;
} ) ;
} ) ;
2018-08-28 03:53:48 -04:00
} ) ;
} ) ;
describe ( 'without last deployment' , ( ) => {
it ( 'renders info about out of date deployment' , ( ) => {
2019-10-15 17:06:25 -04:00
createComponent ( {
status : 'out_of_date' ,
environment ,
2018-08-28 03:53:48 -04:00
} ) ;
2019-10-15 17:06:25 -04:00
expect ( findText ( ) ) . toEqual ( 'This job is an out-of-date deployment to environment.' ) ;
2018-08-28 03:53:48 -04:00
} ) ;
} ) ;
} ) ;
describe ( 'with failed deployment' , ( ) => {
it ( 'renders info about failed deployment' , ( ) => {
2019-10-15 17:06:25 -04:00
createComponent ( {
status : 'failed' ,
environment ,
2018-08-28 03:53:48 -04:00
} ) ;
2019-10-15 17:06:25 -04:00
expect ( findText ( ) ) . toEqual ( 'The deployment of this job to environment did not succeed.' ) ;
2018-08-28 03:53:48 -04:00
} ) ;
} ) ;
describe ( 'creating deployment' , ( ) => {
describe ( 'with last deployment' , ( ) => {
2018-10-03 11:29:07 -04:00
it ( 'renders info about creating deployment and overriding latest deployment' , ( ) => {
2019-10-15 17:06:25 -04:00
createComponent ( {
status : 'creating' ,
environment : createEnvironmentWithLastDeployment ( ) ,
2018-08-28 03:53:48 -04:00
} ) ;
2019-10-15 17:06:25 -04:00
expect ( findText ( ) ) . toEqual (
'This job is creating a deployment to environment. This will overwrite the latest deployment.' ,
2018-08-28 03:53:48 -04:00
) ;
2018-10-09 14:03:09 -04:00
2019-10-15 17:06:25 -04:00
expect ( findJobDeploymentLink ( ) . getAttribute ( 'href' ) ) . toEqual ( 'bar' ) ;
expect ( findEnvironmentLink ( ) . getAttribute ( 'href' ) ) . toEqual ( environment . environment _path ) ;
expect ( findClusterLink ( ) ) . toBeNull ( ) ;
2018-08-28 03:53:48 -04:00
} ) ;
} ) ;
describe ( 'without last deployment' , ( ) => {
2020-02-14 04:08:43 -05:00
it ( 'renders info about deployment being created' , ( ) => {
2019-10-15 17:06:25 -04:00
createComponent ( {
status : 'creating' ,
environment ,
2018-08-28 03:53:48 -04:00
} ) ;
2019-10-15 17:06:25 -04:00
expect ( findText ( ) ) . toEqual ( 'This job is creating a deployment to environment.' ) ;
2018-08-28 03:53:48 -04:00
} ) ;
2020-02-14 04:08:43 -05:00
describe ( 'when there is a cluster' , ( ) => {
it ( 'inclues information about the cluster' , ( ) => {
createComponent (
{
status : 'creating' ,
environment ,
} ,
createDeploymentWithCluster ( ) ,
) ;
expect ( findText ( ) ) . toEqual (
` This job is creating a deployment to environment using cluster ${ TEST _CLUSTER _NAME } . ` ,
) ;
} ) ;
} ) ;
2018-08-28 03:53:48 -04:00
} ) ;
2018-10-03 11:29:07 -04:00
describe ( 'without environment' , ( ) => {
it ( 'does not render environment link' , ( ) => {
2019-10-15 17:06:25 -04:00
createComponent ( {
status : 'creating' ,
environment : null ,
2018-10-03 11:29:07 -04:00
} ) ;
2018-10-09 14:03:09 -04:00
2019-10-15 17:06:25 -04:00
expect ( findEnvironmentLink ( ) ) . toBeNull ( ) ;
2018-10-03 11:29:07 -04:00
} ) ;
} ) ;
2018-08-28 03:53:48 -04:00
} ) ;
2019-09-13 09:26:31 -04:00
describe ( 'with a cluster' , ( ) => {
it ( 'renders the cluster link' , ( ) => {
2020-02-14 04:08:43 -05:00
createComponent (
{
status : 'last' ,
environment : createEnvironmentWithLastDeployment ( ) ,
} ,
createDeploymentWithCluster ( ) ,
) ;
2019-09-13 09:26:31 -04:00
2019-10-15 17:06:25 -04:00
expect ( findText ( ) ) . toEqual (
` This job is deployed to environment using cluster ${ TEST _CLUSTER _NAME } . ` ,
2019-09-13 09:26:31 -04:00
) ;
2019-10-15 17:06:25 -04:00
expect ( findClusterLink ( ) . getAttribute ( 'href' ) ) . toEqual ( TEST _CLUSTER _PATH ) ;
2019-09-13 09:26:31 -04:00
} ) ;
describe ( 'when the cluster is missing the path' , ( ) => {
it ( 'renders the name without a link' , ( ) => {
2020-02-14 04:08:43 -05:00
createComponent (
{
status : 'last' ,
environment : createEnvironmentWithLastDeployment ( ) ,
} ,
{ name : 'the-cluster' } ,
) ;
2019-10-15 17:06:25 -04:00
expect ( findText ( ) ) . toContain ( 'using cluster the-cluster.' ) ;
2019-09-13 09:26:31 -04:00
2019-10-15 17:06:25 -04:00
expect ( findClusterLink ( ) ) . toBeNull ( ) ;
} ) ;
2019-09-13 09:26:31 -04:00
} ) ;
} ) ;
2018-08-28 03:53:48 -04:00
} ) ;