Commit 21f00b99 authored by Jacques Erasmus's avatar Jacques Erasmus Committed by Paul Slaughter

Update cluster link text

- Also refactors the environment text function into smaller functions
parent cdf81f88
...@@ -19,69 +19,18 @@ export default { ...@@ -19,69 +19,18 @@ export default {
}, },
computed: { computed: {
environment() { environment() {
let environmentText;
switch (this.deploymentStatus.status) { switch (this.deploymentStatus.status) {
case 'last': case 'last':
environmentText = sprintf( return this.lastEnvironmentMessage();
__('This job is the most recent deployment to %{link}.'),
{ link: this.environmentLink },
false,
);
break;
case 'out_of_date': case 'out_of_date':
if (this.hasLastDeployment) { return this.outOfDateEnvironmentMessage();
environmentText = sprintf(
__(
'This job is an out-of-date deployment to %{environmentLink}. View the most recent deployment %{deploymentLink}.',
),
{
environmentLink: this.environmentLink,
deploymentLink: this.deploymentLink(`#${this.lastDeployment.iid}`),
},
false,
);
} else {
environmentText = sprintf(
__('This job is an out-of-date deployment to %{environmentLink}.'),
{ environmentLink: this.environmentLink },
false,
);
}
break;
case 'failed': case 'failed':
environmentText = sprintf( return this.failedEnvironmentMessage();
__('The deployment of this job to %{environmentLink} did not succeed.'),
{ environmentLink: this.environmentLink },
false,
);
break;
case 'creating': case 'creating':
if (this.hasLastDeployment) { return this.creatingEnvironmentMessage();
environmentText = sprintf(
__(
'This job is creating a deployment to %{environmentLink} and will overwrite the %{deploymentLink}.',
),
{
environmentLink: this.environmentLink,
deploymentLink: this.deploymentLink(__('latest deployment')),
},
false,
);
} else {
environmentText = sprintf(
__('This job is creating a deployment to %{environmentLink}.'),
{ environmentLink: this.environmentLink },
false,
);
}
break;
default: default:
break; return '';
} }
return environmentText && this.hasCluster
? `${environmentText} ${this.clusterText}`
: environmentText;
}, },
environmentLink() { environmentLink() {
if (this.hasEnvironment) { if (this.hasEnvironment) {
...@@ -137,11 +86,6 @@ export default { ...@@ -137,11 +86,6 @@ export default {
false, false,
); );
}, },
clusterText() {
return this.hasCluster
? sprintf(__('Cluster %{cluster} was used.'), { cluster: this.clusterNameOrLink }, false)
: '';
},
}, },
methods: { methods: {
deploymentLink(name) { deploymentLink(name) {
...@@ -155,6 +99,91 @@ export default { ...@@ -155,6 +99,91 @@ export default {
false, false,
); );
}, },
failedEnvironmentMessage() {
const { environmentLink } = this;
return sprintf(
__('The deployment of this job to %{environmentLink} did not succeed.'),
{ environmentLink },
false,
);
},
lastEnvironmentMessage() {
const { environmentLink, clusterNameOrLink, hasCluster } = this;
const message = hasCluster
? __('This job is deployed to %{environmentLink} using cluster %{clusterNameOrLink}.')
: __('This job is deployed to %{environmentLink}.');
return sprintf(message, { environmentLink, clusterNameOrLink }, false);
},
outOfDateEnvironmentMessage() {
const { hasLastDeployment, hasCluster, environmentLink, clusterNameOrLink } = this;
if (hasLastDeployment) {
const message = hasCluster
? __(
'This job is an out-of-date deployment to %{environmentLink} using cluster %{clusterNameOrLink}. View the %{deploymentLink}.',
)
: __(
'This job is an out-of-date deployment to %{environmentLink}. View the %{deploymentLink}.',
);
return sprintf(
message,
{
environmentLink,
clusterNameOrLink,
deploymentLink: this.deploymentLink(__('most recent deployment')),
},
false,
);
}
const message = hasCluster
? __(
'This job is an out-of-date deployment to %{environmentLink} using cluster %{clusterNameOrLink}.',
)
: __('This job is an out-of-date deployment to %{environmentLink}.');
return sprintf(
message,
{
environmentLink,
clusterNameOrLink,
},
false,
);
},
creatingEnvironmentMessage() {
const { hasLastDeployment, hasCluster, environmentLink, clusterNameOrLink } = this;
if (hasLastDeployment) {
const message = hasCluster
? __(
'This job is creating a deployment to %{environmentLink} using cluster %{clusterNameOrLink}. This will overwrite the %{deploymentLink}.',
)
: __(
'This job is creating a deployment to %{environmentLink}. This will overwrite the %{deploymentLink}.',
);
return sprintf(
message,
{
environmentLink,
clusterNameOrLink,
deploymentLink: this.deploymentLink(__('latest deployment')),
},
false,
);
}
return sprintf(
__('This job is creating a deployment to %{environmentLink}.'),
{ environmentLink },
false,
);
},
}, },
}; };
</script> </script>
......
---
title: Update cluster link text
merge_request: 18322
author:
type: changed
...@@ -3348,9 +3348,6 @@ msgstr "" ...@@ -3348,9 +3348,6 @@ msgstr ""
msgid "Closes this %{quick_action_target}." msgid "Closes this %{quick_action_target}."
msgstr "" msgstr ""
msgid "Cluster %{cluster} was used."
msgstr ""
msgid "Cluster Health" msgid "Cluster Health"
msgstr "" msgstr ""
...@@ -16662,21 +16659,36 @@ msgstr "" ...@@ -16662,21 +16659,36 @@ msgstr ""
msgid "This job has not started yet" msgid "This job has not started yet"
msgstr "" msgstr ""
msgid "This job is an out-of-date deployment to %{environmentLink} using cluster %{clusterNameOrLink}."
msgstr ""
msgid "This job is an out-of-date deployment to %{environmentLink} using cluster %{clusterNameOrLink}. View the %{deploymentLink}."
msgstr ""
msgid "This job is an out-of-date deployment to %{environmentLink}." msgid "This job is an out-of-date deployment to %{environmentLink}."
msgstr "" msgstr ""
msgid "This job is an out-of-date deployment to %{environmentLink}. View the most recent deployment %{deploymentLink}." msgid "This job is an out-of-date deployment to %{environmentLink}. View the %{deploymentLink}."
msgstr "" msgstr ""
msgid "This job is archived. Only the complete pipeline can be retried." msgid "This job is archived. Only the complete pipeline can be retried."
msgstr "" msgstr ""
msgid "This job is creating a deployment to %{environmentLink} and will overwrite the %{deploymentLink}." msgid "This job is creating a deployment to %{environmentLink} using cluster %{clusterNameOrLink}. This will overwrite the %{deploymentLink}."
msgstr "" msgstr ""
msgid "This job is creating a deployment to %{environmentLink}." msgid "This job is creating a deployment to %{environmentLink}."
msgstr "" msgstr ""
msgid "This job is creating a deployment to %{environmentLink}. This will overwrite the %{deploymentLink}."
msgstr ""
msgid "This job is deployed to %{environmentLink} using cluster %{clusterNameOrLink}."
msgstr ""
msgid "This job is deployed to %{environmentLink}."
msgstr ""
msgid "This job is in pending state and is waiting to be picked by a runner" msgid "This job is in pending state and is waiting to be picked by a runner"
msgstr "" msgstr ""
...@@ -16692,9 +16704,6 @@ msgstr "" ...@@ -16692,9 +16704,6 @@ msgstr ""
msgid "This job is stuck because you don't have any active runners that can run this job." msgid "This job is stuck because you don't have any active runners that can run this job."
msgstr "" msgstr ""
msgid "This job is the most recent deployment to %{link}."
msgstr ""
msgid "This job requires a manual action" msgid "This job requires a manual action"
msgstr "" msgstr ""
...@@ -19713,6 +19722,9 @@ msgstr "" ...@@ -19713,6 +19722,9 @@ msgstr ""
msgid "missing" msgid "missing"
msgstr "" msgstr ""
msgid "most recent deployment"
msgstr ""
msgid "mrWidgetCommitsAdded|%{commitCount} and %{mergeCommitCount} will be added to %{targetBranch}." msgid "mrWidgetCommitsAdded|%{commitCount} and %{mergeCommitCount} will be added to %{targetBranch}."
msgstr "" msgstr ""
......
...@@ -534,7 +534,7 @@ describe 'Jobs', :clean_gitlab_redis_shared_state do ...@@ -534,7 +534,7 @@ describe 'Jobs', :clean_gitlab_redis_shared_state do
end end
it 'shows deployment message' do it 'shows deployment message' do
expect(page).to have_content 'This job is the most recent deployment to production' expect(page).to have_content 'This job is deployed to production'
expect(find('.js-environment-link')['href']).to match("environments/#{environment.id}") expect(find('.js-environment-link')['href']).to match("environments/#{environment.id}")
end end
...@@ -548,14 +548,14 @@ describe 'Jobs', :clean_gitlab_redis_shared_state do ...@@ -548,14 +548,14 @@ describe 'Jobs', :clean_gitlab_redis_shared_state do
end end
it 'shows the name of the cluster' do it 'shows the name of the cluster' do
expect(page).to have_content 'Cluster the-cluster was used' expect(page).to have_content 'using cluster the-cluster'
end end
context 'when the user is not able to view the cluster' do context 'when the user is not able to view the cluster' do
let(:user_access_level) { :developer } let(:user_access_level) { :developer }
it 'includes only the name of the cluster without a link' do it 'includes only the name of the cluster without a link' do
expect(page).to have_content 'Cluster the-cluster was used' expect(page).to have_content 'using cluster the-cluster'
expect(page).not_to have_link 'the-cluster' expect(page).not_to have_link 'the-cluster'
end end
end end
...@@ -623,8 +623,7 @@ describe 'Jobs', :clean_gitlab_redis_shared_state do ...@@ -623,8 +623,7 @@ describe 'Jobs', :clean_gitlab_redis_shared_state do
let!(:second_deployment) { create(:deployment, :success, environment: environment, deployable: second_build) } let!(:second_deployment) { create(:deployment, :success, environment: environment, deployable: second_build) }
it 'shows deployment message' do it 'shows deployment message' do
expected_text = 'This job is an out-of-date deployment ' \ expected_text = 'This job is an out-of-date deployment to staging. View the most recent deployment.'
"to staging. View the most recent deployment ##{second_deployment.iid}."
expect(page).to have_css('.environment-information', text: expected_text) expect(page).to have_css('.environment-information', text: expected_text)
end end
......
...@@ -2,6 +2,9 @@ import Vue from 'vue'; ...@@ -2,6 +2,9 @@ import Vue from 'vue';
import component from '~/jobs/components/environments_block.vue'; import component from '~/jobs/components/environments_block.vue';
import mountComponent from '../../helpers/vue_mount_component_helper'; import mountComponent from '../../helpers/vue_mount_component_helper';
const TEST_CLUSTER_NAME = 'test_cluster';
const TEST_CLUSTER_PATH = 'path/to/test_cluster';
describe('Environments block', () => { describe('Environments block', () => {
const Component = Vue.extend(component); const Component = Vue.extend(component);
let vm; let vm;
...@@ -20,22 +23,53 @@ describe('Environments block', () => { ...@@ -20,22 +23,53 @@ describe('Environments block', () => {
const lastDeployment = { iid: 'deployment', deployable: { build_path: 'bar' } }; const lastDeployment = { iid: 'deployment', deployable: { build_path: 'bar' } };
const createEnvironmentWithLastDeployment = () => ({
...environment,
last_deployment: { ...lastDeployment },
});
const createEnvironmentWithCluster = () => ({
...environment,
last_deployment: {
...lastDeployment,
cluster: { name: TEST_CLUSTER_NAME, path: TEST_CLUSTER_PATH },
},
});
const createComponent = (deploymentStatus = {}) => {
vm = mountComponent(Component, {
deploymentStatus,
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');
afterEach(() => { afterEach(() => {
vm.$destroy(); vm.$destroy();
}); });
describe('with last deployment', () => { describe('with last deployment', () => {
it('renders info for most recent deployment', () => { it('renders info for most recent deployment', () => {
vm = mountComponent(Component, { createComponent({
deploymentStatus: {
status: 'last', status: 'last',
environment, environment,
},
iconStatus: status,
}); });
expect(vm.$el.textContent.trim()).toEqual( expect(findText()).toEqual('This job is deployed to environment.');
'This job is the most recent deployment to environment.', });
it('renders info with cluster', () => {
createComponent({
status: 'last',
environment: createEnvironmentWithCluster(),
});
expect(findText()).toEqual(
`This job is deployed to environment using cluster ${TEST_CLUSTER_NAME}.`,
); );
}); });
}); });
...@@ -43,133 +77,106 @@ describe('Environments block', () => { ...@@ -43,133 +77,106 @@ describe('Environments block', () => {
describe('with out of date deployment', () => { describe('with out of date deployment', () => {
describe('with last deployment', () => { describe('with last deployment', () => {
it('renders info for out date and most recent', () => { it('renders info for out date and most recent', () => {
vm = mountComponent(Component, { createComponent({
deploymentStatus: {
status: 'out_of_date', status: 'out_of_date',
environment: Object.assign({}, environment, { environment: createEnvironmentWithLastDeployment(),
last_deployment: lastDeployment,
}),
},
iconStatus: status,
}); });
expect(vm.$el.textContent.trim()).toEqual( expect(findText()).toEqual(
'This job is an out-of-date deployment to environment. View the most recent deployment #deployment.', 'This job is an out-of-date deployment to environment. View the most recent deployment.',
); );
expect(vm.$el.querySelector('.js-job-deployment-link').getAttribute('href')).toEqual('bar'); expect(findJobDeploymentLink().getAttribute('href')).toEqual('bar');
});
it('renders info with cluster', () => {
createComponent({
status: 'out_of_date',
environment: createEnvironmentWithCluster(),
});
expect(findText()).toEqual(
`This job is an out-of-date deployment to environment using cluster ${TEST_CLUSTER_NAME}. View the most recent deployment.`,
);
}); });
}); });
describe('without last deployment', () => { describe('without last deployment', () => {
it('renders info about out of date deployment', () => { it('renders info about out of date deployment', () => {
vm = mountComponent(Component, { createComponent({
deploymentStatus: {
status: 'out_of_date', status: 'out_of_date',
environment, environment,
},
iconStatus: status,
}); });
expect(vm.$el.textContent.trim()).toEqual( expect(findText()).toEqual('This job is an out-of-date deployment to environment.');
'This job is an out-of-date deployment to environment.',
);
}); });
}); });
}); });
describe('with failed deployment', () => { describe('with failed deployment', () => {
it('renders info about failed deployment', () => { it('renders info about failed deployment', () => {
vm = mountComponent(Component, { createComponent({
deploymentStatus: {
status: 'failed', status: 'failed',
environment, environment,
},
iconStatus: status,
}); });
expect(vm.$el.textContent.trim()).toEqual( expect(findText()).toEqual('The deployment of this job to environment did not succeed.');
'The deployment of this job to environment did not succeed.',
);
}); });
}); });
describe('creating deployment', () => { describe('creating deployment', () => {
describe('with last deployment', () => { describe('with last deployment', () => {
it('renders info about creating deployment and overriding latest deployment', () => { it('renders info about creating deployment and overriding latest deployment', () => {
vm = mountComponent(Component, { createComponent({
deploymentStatus: {
status: 'creating', status: 'creating',
environment: Object.assign({}, environment, { environment: createEnvironmentWithLastDeployment(),
last_deployment: lastDeployment,
}),
},
iconStatus: status,
}); });
expect(vm.$el.textContent.trim()).toEqual( expect(findText()).toEqual(
'This job is creating a deployment to environment and will overwrite the latest deployment.', 'This job is creating a deployment to environment. This will overwrite the latest deployment.',
); );
expect(vm.$el.querySelector('.js-job-deployment-link').getAttribute('href')).toEqual('bar'); expect(findJobDeploymentLink().getAttribute('href')).toEqual('bar');
expect(findEnvironmentLink().getAttribute('href')).toEqual(environment.environment_path);
expect(findClusterLink()).toBeNull();
}); });
}); });
describe('without last deployment', () => { describe('without last deployment', () => {
it('renders info about failed deployment', () => { it('renders info about failed deployment', () => {
vm = mountComponent(Component, { createComponent({
deploymentStatus: {
status: 'creating', status: 'creating',
environment, environment,
},
iconStatus: status,
}); });
expect(vm.$el.textContent.trim()).toEqual( expect(findText()).toEqual('This job is creating a deployment to environment.');
'This job is creating a deployment to environment.',
);
}); });
}); });
describe('without environment', () => { describe('without environment', () => {
it('does not render environment link', () => { it('does not render environment link', () => {
vm = mountComponent(Component, { createComponent({
deploymentStatus: {
status: 'creating', status: 'creating',
environment: null, environment: null,
},
iconStatus: status,
}); });
expect(vm.$el.querySelector('.js-environment-link')).toBeNull(); expect(findEnvironmentLink()).toBeNull();
}); });
}); });
}); });
describe('with a cluster', () => { describe('with a cluster', () => {
it('renders the cluster link', () => { it('renders the cluster link', () => {
const cluster = { createComponent({
name: 'the-cluster',
path: '/the-cluster-path',
};
vm = mountComponent(Component, {
deploymentStatus: {
status: 'last', status: 'last',
environment: Object.assign({}, environment, { environment: createEnvironmentWithCluster(),
last_deployment: {
...lastDeployment,
cluster,
},
}),
},
iconStatus: status,
}); });
expect(vm.$el.textContent.trim()).toContain('Cluster the-cluster was used.'); expect(findText()).toEqual(
`This job is deployed to environment using cluster ${TEST_CLUSTER_NAME}.`,
expect(vm.$el.querySelector('.js-job-cluster-link').getAttribute('href')).toEqual(
'/the-cluster-path',
); );
expect(findClusterLink().getAttribute('href')).toEqual(TEST_CLUSTER_PATH);
}); });
describe('when the cluster is missing the path', () => { describe('when the cluster is missing the path', () => {
...@@ -177,8 +184,7 @@ describe('Environments block', () => { ...@@ -177,8 +184,7 @@ describe('Environments block', () => {
const cluster = { const cluster = {
name: 'the-cluster', name: 'the-cluster',
}; };
vm = mountComponent(Component, { createComponent({
deploymentStatus: {
status: 'last', status: 'last',
environment: Object.assign({}, environment, { environment: Object.assign({}, environment, {
last_deployment: { last_deployment: {
...@@ -186,30 +192,12 @@ describe('Environments block', () => { ...@@ -186,30 +192,12 @@ describe('Environments block', () => {
cluster, cluster,
}, },
}), }),
},
iconStatus: status,
}); });
expect(vm.$el.textContent.trim()).toContain('Cluster the-cluster was used.'); expect(findText()).toContain('using cluster the-cluster.');
expect(vm.$el.querySelector('.js-job-cluster-link')).toBeNull();
});
});
});
describe('without a cluster', () => { expect(findClusterLink()).toBeNull();
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();
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment