Skip to content

Commit

Permalink
New tests for warning block presence
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Nov 30, 2023
1 parent a3b4a15 commit 99cf94f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ui/app/templates/components/job-editor/review.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
<br>

{{#if this.warnings}}
<Hds::Alert @type="inline" @color="warning" as |A|>
<A.Description>
<Hds::Alert @type="inline" @color="warning" data-test-dry-run-warnings as |A|>
<A.Description data-test-dry-run-warning-body>
<p>
{{this.warnings}}
</p>
Expand Down
12 changes: 11 additions & 1 deletion ui/mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,16 @@ export default function () {
const FailedTGAllocs =
body.Job.Unschedulable && generateFailedTGAllocs(body.Job);

const jobPlanWarnings = body.Job.WithWarnings && generateWarnings();

return new Response(
200,
{},
JSON.stringify({ FailedTGAllocs, Diff: generateDiff(req.params.id) })
JSON.stringify({
FailedTGAllocs,
Warnings: jobPlanWarnings,
Diff: generateDiff(req.params.id),
})
);
});

Expand Down Expand Up @@ -1224,3 +1230,7 @@ function generateFailedTGAllocs(job, taskGroups) {
return hash;
}, {});
}

function generateWarnings() {
return '2 warnings:\n\n* Group "yourtask" has warnings: 1 error occurred:\n\t* Task "yourtask" has warnings: 1 error occurred:\n\t* 2 errors occurred:\n\t* Identity[vault_default] identities without an audience are insecure\n\t* Identity[vault_default] identities without an expiration are insecure\n* Task yourtask has an identity called vault_default but no vault block';
}
20 changes: 19 additions & 1 deletion ui/tests/integration/components/job-editor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ module('Integration | Component | job-editor', function (hooks) {
});

test('when the scheduler dry-run has errors, the errors are shown to the user', async function (assert) {
assert.expect(4);
assert.expect(5);

const spec = jsonJob({ Unschedulable: true });
const job = await this.store.createRecord('job');
Expand All @@ -313,11 +313,29 @@ module('Integration | Component | job-editor', function (hooks) {
'The scheduler dry-run message includes the warning from send back by the API'
);

assert.notOk(
Editor.warningMessage.isPresent,
'The scheduler dry-run warning block is not present when there is an error but no warnings'
);

await componentA11yAudit(this.element, assert);

await percySnapshot(assert);
});

test('When the scheduler dry-run has warnings, the warnings are shown to the user', async function (assert) {
assert.expect(1);
const spec = jsonJob({ WithWarnings: true });
const job = await this.store.createRecord('job');
await renderNewJob(this, job);
await planJob(spec);
assert.ok(
Editor.warningMessage.isPresent,
'The scheduler dry-run warning block is shown to the user'
);
await percySnapshot(assert);
});

test('when the scheduler dry-run has no warnings, a success message is shown to the user', async function (assert) {
assert.expect(3);

Expand Down
5 changes: 5 additions & 0 deletions ui/tests/pages/components/job-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ export default () => ({
errored: hasClass('hds-alert--color-critical'),
succeeded: hasClass('hds-alert--color-success'),
},

warningMessage: {
scope: '[data-test-dry-run-warnings]',
body: text('[data-test-dry-run-warning-body]'),
},
});

0 comments on commit 99cf94f

Please sign in to comment.