Skip to content

Commit

Permalink
Test cases begun
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Jul 21, 2023
1 parent 144de3b commit 97afaf3
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 19 deletions.
2 changes: 1 addition & 1 deletion ui/app/routes/jobs/job/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class JobsJobVariablesRoute extends Route {

beforeModel() {
if (this.can.cannot('list variables')) {
this.router.transitionTo(`/jobs/job`);
this.router.transitionTo(`/jobs`);
}
}
async model() {
Expand Down
20 changes: 11 additions & 9 deletions ui/app/templates/components/job-subnav.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,17 @@
</LinkTo>
</li>
{{/unless}}
<li data-test-tab="variables">
<LinkTo
@route="jobs.job.variables"
@model={{@job}}
@activeClass="is-active"
>
Variables
</LinkTo>
</li>
{{#if (can "list variables")}}
<li data-test-tab="variables">
<LinkTo
@route="jobs.job.variables"
@model={{@job}}
@activeClass="is-active"
>
Variables
</LinkTo>
</li>
{{/if}}

</ul>
</div>
21 changes: 21 additions & 0 deletions ui/mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ export default function () {
})
);

this.get(
'/job',
withBlockingSupport(function ({ jobs }, { queryParams }) {
const json = this.serialize(jobs.all());
const namespace = queryParams.namespace || 'default';
return json
.filter((job) => {
if (namespace === '*') return true;
return namespace === 'default'
? !job.NamespaceID || job.NamespaceID === namespace
: job.NamespaceID === namespace;
})
.map((job) => filterKeys(job, 'TaskGroups', 'NamespaceID'));
})
);

this.post('/jobs', function (schema, req) {
const body = JSON.parse(req.requestBody);

Expand Down Expand Up @@ -960,6 +976,11 @@ export default function () {
});

this.get('/var/:id', function ({ variables }, { params }) {
console.log('variable?', params.id, variabls.find(params.id));
let variable = variables.find(params.id);
if (!variable) {
return new Response(404, {}, {});
}
return variables.find(params.id);
});

Expand Down
5 changes: 5 additions & 0 deletions ui/mirage/scenarios/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@ function mediumCluster(server) {

function variableTestCluster(server) {
faker.seed(1);
server.create('token', {
name: 'Novars Murphy',
id: 'n0-v4r5-4cc355',
type: 'client',
});
createTokens(server);
createNamespaces(server);
server.createList('agent', 3, 'withConsulLink', 'withVaultLink');
Expand Down
55 changes: 46 additions & 9 deletions ui/tests/acceptance/variables-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -984,13 +984,50 @@ module('Acceptance | variables', function (hooks) {
});
});

// module('Job Variables Page', function () {
// // Test: If the user has no variable read access, no subnav exists
// // Test: If the user has variable read access, but no variables, the subnav exists but contains only a message
// // Test: If the user has variable read access, and variables, the subnav exists and contains a list of variables
// // Test: The nomad/jobs variable is always included if it exists
// // Test: Multiple task variables are included, and make a maximum of 1 API request
// // Test: Intro text shows examples of variables at groups and tasks
// // Test: No variables + variable write access gets a link to create one, otehrwise no link.
// });
module('Job Variables Page', function () {
// Test: If the user has no variable read access, no subnav exists
test('If the user has no variable read access, no subnav exists', async function (assert) {
allScenarios.variableTestCluster(server);
const variablesToken = server.db.tokens.find('n0-v4r5-4cc355');
// const variablesToken = server.db.tokens.find("f3w3r-53cur3-v4r14bl35");
window.localStorage.nomadTokenSecret = variablesToken.secretId;
await visit(
`/jobs/${server.db.jobs[0].id}@${server.db.jobs[0].namespace}`
);
console.log('currentURL', currentURL());
// Variables tab isn't in subnav
assert.dom('[data-test-tab="variables"]').doesNotExist();

// Attempting to access it directly will boot you to /jobs
await visit(
`/jobs/${server.db.jobs[0].id}@${server.db.jobs[0].namespace}/variables`
);
assert.equal(currentURL(), '/jobs?namespace=*');

window.localStorage.nomadTokenSecret = null; // Reset Token
});
// Test: If the user has variable read access, but no variables, the subnav exists but contains only a message
test('If the user has variable read access, but no variables, the subnav exists but contains only a message', async function (assert) {
allScenarios.variableTestCluster(server);
const variablesToken = server.db.tokens.find('f3w3r-53cur3-v4r14bl35');
window.localStorage.nomadTokenSecret = variablesToken.secretId;
await visit(
`/jobs/${server.db.jobs[0].id}@${server.db.jobs[0].namespace}`
);
assert.dom('[data-test-tab="variables"]').exists();
await click('[data-test-tab="variables"] a');
assert.equal(
currentURL(),
`/jobs/${server.db.jobs[0].id}@${server.db.jobs[0].namespace}/variables`
);
});

// Test: If the user has variable read access, and variables, the subnav exists and contains a list of variables
// Test: The nomad/jobs variable is always included if it exists
// Test: Multiple task variables are included, and make a maximum of 1 API request
// Test: Intro text shows examples of variables at groups and tasks
// Test: No variables + variable write access gets a link to create one, otehrwise no link.
// Test: Notifications links differ from when you have 1 group/task and multiple
// Test: if a variable exists, the notification link goes to edit it; otherwise, creates new with pre-defined path
});
});

0 comments on commit 97afaf3

Please sign in to comment.