Skip to content

Commit

Permalink
UI: Add tests for prodcut links (#11645)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgfa29 authored Dec 8, 2021
1 parent c651f2d commit f54a891
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ui/app/templates/components/global-header.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
</a>
{{/if}}
{{#if this.system.agent.config.UI.Consul.BaseUIURL}}
<a href={{this.system.agent.config.UI.Consul.BaseUIURL}} class="navbar-item">
<a data-test-header-consul-link href={{this.system.agent.config.UI.Consul.BaseUIURL}} class="navbar-item">
Consul
</a>
{{/if}}
{{#if this.system.agent.config.UI.Vault.BaseUIURL}}
<a href={{this.system.agent.config.UI.Vault.BaseUIURL}} class="navbar-item">
<a data-test-header-vault-link href={{this.system.agent.config.UI.Vault.BaseUIURL}} class="navbar-item">
Vault
</a>
{{/if}}
Expand Down
21 changes: 20 additions & 1 deletion ui/mirage/factories/agent.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Factory } from 'ember-cli-mirage';
import { Factory, trait } from 'ember-cli-mirage';
import faker from 'nomad-ui/mirage/faker';
import { provide } from '../utils';
import { DATACENTERS } from '../common';
Expand All @@ -13,6 +13,9 @@ export default Factory.extend({
name: () => generateName(),

config: {
UI: {
Enabled: true,
},
Version: {
Version: '1.1.0',
VersionMetadata: 'ent',
Expand All @@ -34,6 +37,22 @@ export default Factory.extend({
version() {
return this.member.Tags?.build || '';
},

withConsulLink: trait({
afterCreate(agent) {
agent.config.UI.Consul = {
BaseUIURL: 'http://localhost:8500/ui',
};
},
}),

withVaultLink: trait({
afterCreate(agent) {
agent.config.UI.Vault = {
BaseUIURL: 'http://localhost:8200/ui',
};
},
}),
});

function generateName() {
Expand Down
2 changes: 1 addition & 1 deletion ui/mirage/scenarios/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function(server) {

function smallCluster(server) {
server.create('feature', { name: 'Dynamic Application Sizing' });
server.createList('agent', 3);
server.createList('agent', 3, 'withConsulLink', 'withVaultLink');
server.createList('node', 5);
server.createList('job', 5, { createRecommendations: true });
server.createList('allocFile', 5);
Expand Down
49 changes: 49 additions & 0 deletions ui/tests/acceptance/global-header-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable ember-a11y-testing/a11y-audit-called */
import { module, test } from 'qunit';
import { visit } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
import Layout from 'nomad-ui/tests/pages/layout';

module('Acceptance | global header', function(hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);

test('it diplays no links', async function(assert) {
server.create('agent');

await visit('/');

assert.false(Layout.navbar.end.vaultLink.isVisible);
assert.false(Layout.navbar.end.vaultLink.isVisible);
});

test('it diplays both links', async function(assert) {
server.create('agent', 'withConsulLink', 'withVaultLink');

await visit('/');

assert.true(Layout.navbar.end.vaultLink.isVisible);
assert.true(Layout.navbar.end.vaultLink.isVisible);
});

test('it diplays Consul link', async function(assert) {
server.create('agent', 'withConsulLink');

await visit('/');

assert.true(Layout.navbar.end.consulLink.isVisible);
assert.equal(Layout.navbar.end.consulLink.text, 'Consul');
assert.equal(Layout.navbar.end.consulLink.link, 'http://localhost:8500/ui');
});

test('it diplays Vault link', async function(assert) {
server.create('agent', 'withVaultLink');

await visit('/');

assert.true(Layout.navbar.end.vaultLink.isVisible);
assert.equal(Layout.navbar.end.vaultLink.text, 'Vault');
assert.equal(Layout.navbar.end.vaultLink.link, 'http://localhost:8200/ui');
});
});
17 changes: 17 additions & 0 deletions ui/tests/pages/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
hasClass,
isHidden,
isPresent,
property,
text,
} from 'ember-cli-page-object';

Expand Down Expand Up @@ -46,6 +47,22 @@ export default create({
resetScope: true,
},
},

end: {
scope: '.navbar-end',

consulLink: {
scope: '[data-test-header-consul-link]',
text: text(),
link: property('href'),
},

vaultLink: {
scope: '[data-test-header-vault-link]',
text: text(),
link: property('href'),
},
},
},

gutter: {
Expand Down

0 comments on commit f54a891

Please sign in to comment.