Skip to content

Commit

Permalink
fix(2319): Link to template with default namespace (#663)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkyi authored Feb 2, 2021
1 parent b7d4955 commit 552045b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
9 changes: 9 additions & 0 deletions app/components/validator-job/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ export default Component.extend({
return this.get('job.environment.SD_TEMPLATE_FULLNAME');
}
}),
getTemplateLink: computed('job', {
get() {
const namespace = this.get('job.environment.SD_TEMPLATE_NAMESPACE');
const name = this.get('job.environment.SD_TEMPLATE_NAME');
const version = this.get('job.environment.SD_TEMPLATE_VERSION');

return `/templates/${namespace}/${name}/${version}`;
}
}),
getTemplateVersion: computed('job', {
get() {
return this.get('job.environment.SD_TEMPLATE_VERSION');
Expand Down
4 changes: 2 additions & 2 deletions app/components/validator-job/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
{{/if}}
{{#if getTemplateName}}
{{#if template}}
<h4>This template extends <a href="/templates/{{getTemplateName}}/{{getTemplateVersion}}">{{getTemplateName}}</a> template.</h4>
<h4>This template extends <a href={{getTemplateLink}}>{{getTemplateName}}</a> template.</h4>
{{else}}
<h4>This job uses <a href="/templates/{{getTemplateName}}/{{getTemplateVersion}}">{{getTemplateName}}</a> template.</h4>
<h4>This job uses <a href={{getTemplateLink}}>{{getTemplateName}}</a> template.</h4>
{{/if}}
{{/if}}
{{#if template.description}}
Expand Down
41 changes: 34 additions & 7 deletions tests/integration/components/validator-job/component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,29 +139,51 @@ module('Integration | Component | validator job', function(hooks) {
assert.dom('.sourcePaths ul li').hasText('None defined');
});

test('it renders template name', async function(assert) {
test('it renders template name when template is used', async function(assert) {
this.set('templateMock', {
description: 'Test template',
maintainer: '[email protected]',
images: {
stable: 'node:6',
development: 'node:7'
},
name: 'test',
namespace: 'batman',
version: '2.0.0'
});
this.set('jobMock', {
image: 'int-test:1',
template: 'baz',
steps: [{ step1: 'echo hello' }, { step2: 'echo goodby' }],
secrets: [],
environment: { SD_TEMPLATE_FULLNAME: 'foo/bar' },
environment: {
SD_TEMPLATE_FULLNAME: 'baz',
SD_TEMPLATE_NAMESPACE: 'default',
SD_TEMPLATE_NAME: 'baz',
SD_TEMPLATE_VERSION: '2.0.0'
},
settings: {},
annotations: {}
});

await render(hbs`{{validator-job name="int-test" index=0 job=jobMock}}`);
await render(hbs`{{validator-job name="int-test" index=0 job=jobMock template=templateMock}}`);

assert.dom('h4:nth-of-type(1)').hasText('int-test');
assert.dom('h4:nth-of-type(2)').hasText('This job uses foo/bar template.');
assert.dom('h4:nth-of-type(2) a').hasAttribute('href', '/templates/foo/bar/');
assert.dom('h4:nth-of-type(2)').hasText('This template extends baz template.');
assert.dom('h4:nth-of-type(2) a').hasAttribute('href', '/templates/default/baz/2.0.0');
});

test('it renders template name with version tag', async function(assert) {
this.set('jobMock', {
image: 'int-test:1',
steps: [{ step1: 'echo hello' }, { step2: 'echo goodby' }],
secrets: [],
environment: { SD_TEMPLATE_FULLNAME: 'foo/bar', SD_TEMPLATE_VERSION: 'latest' },
environment: {
SD_TEMPLATE_FULLNAME: 'foo/bar',
SD_TEMPLATE_NAMESPACE: 'foo',
SD_TEMPLATE_NAME: 'bar',
SD_TEMPLATE_VERSION: 'latest'
},
settings: {},
annotations: {}
});
Expand All @@ -178,7 +200,12 @@ module('Integration | Component | validator job', function(hooks) {
image: 'int-test:1',
steps: [{ step1: 'echo hello' }, { step2: 'echo goodby' }],
secrets: [],
environment: { SD_TEMPLATE_FULLNAME: 'foo/bar', SD_TEMPLATE_VERSION: '0.0.1' },
environment: {
SD_TEMPLATE_FULLNAME: 'foo/bar',
SD_TEMPLATE_NAMESPACE: 'foo',
SD_TEMPLATE_NAME: 'bar',
SD_TEMPLATE_VERSION: '0.0.1'
},
settings: {},
annotations: {}
});
Expand Down

0 comments on commit 552045b

Please sign in to comment.