diff options
Diffstat (limited to 'spec/javascripts/jobs/components/environments_block_spec.js')
-rw-r--r-- | spec/javascripts/jobs/components/environments_block_spec.js | 78 |
1 files changed, 72 insertions, 6 deletions
diff --git a/spec/javascripts/jobs/components/environments_block_spec.js b/spec/javascripts/jobs/components/environments_block_spec.js index 0866ddd21d8..4bbc5f5a348 100644 --- a/spec/javascripts/jobs/components/environments_block_spec.js +++ b/spec/javascripts/jobs/components/environments_block_spec.js @@ -18,6 +18,8 @@ describe('Environments block', () => { name: 'environment', }; + const lastDeployment = { iid: 'deployment', deployable: { build_path: 'bar' } }; + afterEach(() => { vm.$destroy(); }); @@ -45,7 +47,7 @@ describe('Environments block', () => { deploymentStatus: { status: 'out_of_date', environment: Object.assign({}, environment, { - last_deployment: { iid: 'deployment', deployable: { build_path: 'bar' } }, + last_deployment: lastDeployment, }), }, iconStatus: status, @@ -99,10 +101,7 @@ describe('Environments block', () => { deploymentStatus: { status: 'creating', environment: Object.assign({}, environment, { - last_deployment: { - iid: 'deployment', - deployable: { build_path: 'foo' }, - }, + last_deployment: lastDeployment, }), }, iconStatus: status, @@ -112,7 +111,7 @@ describe('Environments block', () => { 'This job is creating a deployment to environment and will overwrite the latest deployment.', ); - expect(vm.$el.querySelector('.js-job-deployment-link').getAttribute('href')).toEqual('foo'); + expect(vm.$el.querySelector('.js-job-deployment-link').getAttribute('href')).toEqual('bar'); }); }); @@ -146,4 +145,71 @@ describe('Environments block', () => { }); }); }); + + describe('with a cluster', () => { + it('renders the cluster link', () => { + const cluster = { + name: 'the-cluster', + path: '/the-cluster-path', + }; + vm = mountComponent(Component, { + deploymentStatus: { + status: 'last', + environment: Object.assign({}, environment, { + last_deployment: { + ...lastDeployment, + cluster, + }, + }), + }, + iconStatus: status, + }); + + expect(vm.$el.textContent.trim()).toContain('Cluster the-cluster was used.'); + + expect(vm.$el.querySelector('.js-job-cluster-link').getAttribute('href')).toEqual( + '/the-cluster-path', + ); + }); + + describe('when the cluster is missing the path', () => { + it('renders the name without a link', () => { + const cluster = { + name: 'the-cluster', + }; + vm = mountComponent(Component, { + deploymentStatus: { + status: 'last', + environment: Object.assign({}, environment, { + last_deployment: { + ...lastDeployment, + cluster, + }, + }), + }, + iconStatus: status, + }); + + expect(vm.$el.textContent.trim()).toContain('Cluster the-cluster was used.'); + + expect(vm.$el.querySelector('.js-job-cluster-link')).toBeNull(); + }); + }); + }); + + describe('without a cluster', () => { + it('does not render a cluster link', () => { + vm = mountComponent(Component, { + deploymentStatus: { + status: 'last', + environment: Object.assign({}, environment, { + last_deployment: lastDeployment, + }), + }, + iconStatus: status, + }); + + expect(vm.$el.querySelector('.js-job-cluster-link')).toBeNull(); + }); + }); }); |