2020-08-18 19:51:02 +05:30
import { mount } from '@vue/test-utils' ;
2022-10-11 01:57:18 +05:30
import EnvironmentsBlock from '~/jobs/components/job/environments_block.vue' ;
2018-11-20 20:47:30 +05:30
2019-12-21 20:55:43 +05:30
const TEST _CLUSTER _NAME = 'test_cluster' ;
const TEST _CLUSTER _PATH = 'path/to/test_cluster' ;
2020-03-13 15:44:24 +05:30
const TEST _KUBERNETES _NAMESPACE = 'this-is-a-kubernetes-namespace' ;
2019-12-21 20:55:43 +05:30
2018-11-20 20:47:30 +05:30
describe ( 'Environments block' , ( ) => {
2020-08-18 19:51:02 +05:30
let wrapper ;
2018-12-05 23:21:45 +05:30
const status = {
2018-11-20 20:47:30 +05:30
group : 'success' ,
icon : 'status_success' ,
label : 'passed' ,
text : 'passed' ,
tooltip : 'passed' ,
} ;
2018-12-05 23:21:45 +05:30
2018-11-20 20:47:30 +05:30
const environment = {
2018-12-05 23:21:45 +05:30
environment _path : '/environment' ,
2018-11-20 20:47:30 +05:30
name : 'environment' ,
} ;
2019-12-04 20:38:33 +05:30
const lastDeployment = { iid : 'deployment' , deployable : { build _path : 'bar' } } ;
2019-12-21 20:55:43 +05:30
const createEnvironmentWithLastDeployment = ( ) => ( {
... environment ,
last _deployment : { ... lastDeployment } ,
} ) ;
2020-03-13 15:44:24 +05:30
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-12-21 20:55:43 +05:30
} ) ;
2020-03-13 15:44:24 +05:30
const createComponent = ( deploymentStatus = { } , deploymentCluster = { } ) => {
2020-08-18 19:51:02 +05:30
wrapper = mount ( EnvironmentsBlock , {
propsData : {
deploymentStatus ,
deploymentCluster ,
iconStatus : status ,
} ,
2019-12-21 20:55:43 +05:30
} ) ;
} ;
2022-10-11 01:57:18 +05:30
const findText = ( ) => wrapper . findComponent ( EnvironmentsBlock ) . text ( ) ;
2020-08-18 19:51:02 +05:30
const findJobDeploymentLink = ( ) => wrapper . find ( '[data-testid="job-deployment-link"]' ) ;
const findEnvironmentLink = ( ) => wrapper . find ( '[data-testid="job-environment-link"]' ) ;
const findClusterLink = ( ) => wrapper . find ( '[data-testid="job-cluster-link"]' ) ;
2019-12-21 20:55:43 +05:30
2018-12-05 23:21:45 +05:30
describe ( 'with last deployment' , ( ) => {
2018-11-20 20:47:30 +05:30
it ( 'renders info for most recent deployment' , ( ) => {
2019-12-21 20:55:43 +05:30
createComponent ( {
status : 'last' ,
environment ,
2018-11-20 20:47:30 +05:30
} ) ;
2020-08-18 19:51:02 +05:30
expect ( findText ( ) ) . toBe ( 'This job is deployed to environment.' ) ;
2019-12-21 20:55:43 +05:30
} ) ;
2020-03-13 15:44:24 +05:30
describe ( 'when there is a cluster' , ( ) => {
it ( 'renders info with cluster' , ( ) => {
createComponent (
{
status : 'last' ,
environment : createEnvironmentWithLastDeployment ( ) ,
} ,
createDeploymentWithCluster ( ) ,
) ;
2020-08-18 19:51:02 +05:30
expect ( findText ( ) ) . toBe (
2020-03-13 15:44:24 +05:30
` This job is deployed to environment using cluster ${ TEST _CLUSTER _NAME } . ` ,
) ;
2019-12-21 20:55:43 +05:30
} ) ;
2020-03-13 15:44:24 +05:30
describe ( 'when there is a kubernetes namespace' , ( ) => {
it ( 'renders info with cluster' , ( ) => {
createComponent (
{
status : 'last' ,
environment : createEnvironmentWithLastDeployment ( ) ,
} ,
createDeploymentWithClusterAndKubernetesNamespace ( ) ,
) ;
2020-08-18 19:51:02 +05:30
expect ( findText ( ) ) . toBe (
2020-03-13 15:44:24 +05:30
` This job is deployed to environment using cluster ${ TEST _CLUSTER _NAME } and namespace ${ TEST _KUBERNETES _NAMESPACE } . ` ,
) ;
} ) ;
} ) ;
2018-11-20 20:47:30 +05:30
} ) ;
} ) ;
describe ( 'with out of date deployment' , ( ) => {
describe ( 'with last deployment' , ( ) => {
it ( 'renders info for out date and most recent' , ( ) => {
2019-12-21 20:55:43 +05:30
createComponent ( {
status : 'out_of_date' ,
environment : createEnvironmentWithLastDeployment ( ) ,
2018-11-20 20:47:30 +05:30
} ) ;
2020-08-18 19:51:02 +05:30
expect ( findText ( ) ) . toBe (
2019-12-21 20:55:43 +05:30
'This job is an out-of-date deployment to environment. View the most recent deployment.' ,
2018-11-20 20:47:30 +05:30
) ;
2018-12-13 13:39:08 +05:30
2020-08-18 19:51:02 +05:30
expect ( findJobDeploymentLink ( ) . attributes ( 'href' ) ) . toBe ( 'bar' ) ;
2019-12-21 20:55:43 +05:30
} ) ;
2020-03-13 15:44:24 +05:30
describe ( 'when there is a cluster' , ( ) => {
it ( 'renders info with cluster' , ( ) => {
createComponent (
{
status : 'out_of_date' ,
environment : createEnvironmentWithLastDeployment ( ) ,
} ,
createDeploymentWithCluster ( ) ,
) ;
2020-08-18 19:51:02 +05:30
expect ( findText ( ) ) . toBe (
2020-03-13 15:44:24 +05:30
` This job is an out-of-date deployment to environment using cluster ${ TEST _CLUSTER _NAME } . View the most recent deployment. ` ,
) ;
2019-12-21 20:55:43 +05:30
} ) ;
2020-03-13 15:44:24 +05:30
describe ( 'when there is a kubernetes namespace' , ( ) => {
it ( 'renders info with cluster' , ( ) => {
createComponent (
{
status : 'out_of_date' ,
environment : createEnvironmentWithLastDeployment ( ) ,
} ,
createDeploymentWithClusterAndKubernetesNamespace ( ) ,
) ;
2020-08-18 19:51:02 +05:30
expect ( findText ( ) ) . toBe (
2020-03-13 15:44:24 +05:30
` 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-11-20 20:47:30 +05:30
} ) ;
} ) ;
describe ( 'without last deployment' , ( ) => {
it ( 'renders info about out of date deployment' , ( ) => {
2019-12-21 20:55:43 +05:30
createComponent ( {
status : 'out_of_date' ,
environment ,
2018-11-20 20:47:30 +05:30
} ) ;
2020-08-18 19:51:02 +05:30
expect ( findText ( ) ) . toBe ( 'This job is an out-of-date deployment to environment.' ) ;
2018-11-20 20:47:30 +05:30
} ) ;
} ) ;
} ) ;
describe ( 'with failed deployment' , ( ) => {
it ( 'renders info about failed deployment' , ( ) => {
2019-12-21 20:55:43 +05:30
createComponent ( {
status : 'failed' ,
environment ,
2018-11-20 20:47:30 +05:30
} ) ;
2020-08-18 19:51:02 +05:30
expect ( findText ( ) ) . toBe ( 'The deployment of this job to environment did not succeed.' ) ;
2018-11-20 20:47:30 +05:30
} ) ;
} ) ;
describe ( 'creating deployment' , ( ) => {
describe ( 'with last deployment' , ( ) => {
2018-12-05 23:21:45 +05:30
it ( 'renders info about creating deployment and overriding latest deployment' , ( ) => {
2019-12-21 20:55:43 +05:30
createComponent ( {
status : 'creating' ,
environment : createEnvironmentWithLastDeployment ( ) ,
2018-11-20 20:47:30 +05:30
} ) ;
2020-08-18 19:51:02 +05:30
expect ( findText ( ) ) . toBe (
2019-12-21 20:55:43 +05:30
'This job is creating a deployment to environment. This will overwrite the latest deployment.' ,
2018-11-20 20:47:30 +05:30
) ;
2018-12-13 13:39:08 +05:30
2020-08-18 19:51:02 +05:30
expect ( findEnvironmentLink ( ) . attributes ( 'href' ) ) . toBe ( environment . environment _path ) ;
expect ( findJobDeploymentLink ( ) . attributes ( 'href' ) ) . toBe ( 'bar' ) ;
expect ( findClusterLink ( ) . exists ( ) ) . toBe ( false ) ;
2018-11-20 20:47:30 +05:30
} ) ;
} ) ;
describe ( 'without last deployment' , ( ) => {
2020-03-13 15:44:24 +05:30
it ( 'renders info about deployment being created' , ( ) => {
2019-12-21 20:55:43 +05:30
createComponent ( {
status : 'creating' ,
environment ,
2018-11-20 20:47:30 +05:30
} ) ;
2020-08-18 19:51:02 +05:30
expect ( findText ( ) ) . toBe ( 'This job is creating a deployment to environment.' ) ;
2018-11-20 20:47:30 +05:30
} ) ;
2020-03-13 15:44:24 +05:30
describe ( 'when there is a cluster' , ( ) => {
it ( 'inclues information about the cluster' , ( ) => {
createComponent (
{
status : 'creating' ,
environment ,
} ,
createDeploymentWithCluster ( ) ,
) ;
2020-08-18 19:51:02 +05:30
expect ( findText ( ) ) . toBe (
2020-03-13 15:44:24 +05:30
` This job is creating a deployment to environment using cluster ${ TEST _CLUSTER _NAME } . ` ,
) ;
} ) ;
} ) ;
2018-11-20 20:47:30 +05:30
} ) ;
2018-12-05 23:21:45 +05:30
describe ( 'without environment' , ( ) => {
it ( 'does not render environment link' , ( ) => {
2019-12-21 20:55:43 +05:30
createComponent ( {
status : 'creating' ,
environment : null ,
2018-12-05 23:21:45 +05:30
} ) ;
2018-12-13 13:39:08 +05:30
2020-08-18 19:51:02 +05:30
expect ( findEnvironmentLink ( ) . exists ( ) ) . toBe ( false ) ;
2018-12-05 23:21:45 +05:30
} ) ;
} ) ;
2018-11-20 20:47:30 +05:30
} ) ;
2019-12-04 20:38:33 +05:30
describe ( 'with a cluster' , ( ) => {
it ( 'renders the cluster link' , ( ) => {
2020-03-13 15:44:24 +05:30
createComponent (
{
status : 'last' ,
environment : createEnvironmentWithLastDeployment ( ) ,
} ,
createDeploymentWithCluster ( ) ,
) ;
2019-12-04 20:38:33 +05:30
2020-08-18 19:51:02 +05:30
expect ( findText ( ) ) . toBe (
2019-12-21 20:55:43 +05:30
` This job is deployed to environment using cluster ${ TEST _CLUSTER _NAME } . ` ,
2019-12-04 20:38:33 +05:30
) ;
2019-12-21 20:55:43 +05:30
2020-08-18 19:51:02 +05:30
expect ( findClusterLink ( ) . attributes ( 'href' ) ) . toBe ( TEST _CLUSTER _PATH ) ;
2019-12-04 20:38:33 +05:30
} ) ;
describe ( 'when the cluster is missing the path' , ( ) => {
it ( 'renders the name without a link' , ( ) => {
2020-03-13 15:44:24 +05:30
createComponent (
{
status : 'last' ,
environment : createEnvironmentWithLastDeployment ( ) ,
} ,
{ name : 'the-cluster' } ,
) ;
2019-12-21 20:55:43 +05:30
expect ( findText ( ) ) . toContain ( 'using cluster the-cluster.' ) ;
2019-12-04 20:38:33 +05:30
2020-08-18 19:51:02 +05:30
expect ( findClusterLink ( ) . exists ( ) ) . toBe ( false ) ;
2019-12-21 20:55:43 +05:30
} ) ;
2019-12-04 20:38:33 +05:30
} ) ;
} ) ;
2018-11-20 20:47:30 +05:30
} ) ;