Skip to content

Commit

Permalink
A whack of fun new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Nov 8, 2024
1 parent acd3294 commit ff5374e
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 23 deletions.
33 changes: 16 additions & 17 deletions ui/app/templates/components/job-version.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
~}}

{{did-update this.versionsDidUpdate this.diff}}
<section class="job-version">
<section class="job-version" data-test-job-version={{this.version.number}}>
<div class="boxed-section {{if this.version.versionTag "tagged"}}" data-test-tagged-version={{if this.version.versionTag "true" "false"}}>
<header class="boxed-section-head is-light inline-definitions">
Version #{{this.version.number}}
Expand Down Expand Up @@ -91,22 +91,21 @@
{{on "click" (action (mut this.cloneButtonStatus) "confirming")}}
/>

<TwoStepButton
data-test-revert-to
@classes={{hash
idleButton="is-warning is-outlined"
confirmButton="is-warning"}}
@fadingBackground={{true}}
@idleText="Revert Version"
@cancelText="Cancel"
@confirmText="Yes, Revert Version"
@confirmationMessage="Are you sure you want to revert to this version?"
@inlineText={{true}}
@size="small"
@awaitingConfirmation={{this.revertTo.isRunning}}
@onConfirm={{perform this.revertTo}} />


<TwoStepButton
data-test-revert-to
@classes={{hash
idleButton="is-warning is-outlined"
confirmButton="is-warning"}}
@fadingBackground={{true}}
@idleText="Revert Version"
@cancelText="Cancel"
@confirmText="Yes, Revert Version"
@confirmationMessage="Are you sure you want to revert to this version?"
@inlineText={{true}}
@size="small"
@awaitingConfirmation={{this.revertTo.isRunning}}
@onConfirm={{perform this.revertTo}}
/>
{{else if (eq this.cloneButtonStatus 'confirming')}}
<Hds::Button
data-test-cancel-clone
Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/jobs/run/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{{page-title "Run a job"}}
<section class="section">
{{#if (and this.sourceString (not this.disregardNameWarning))}}
<Hds::Alert @type="inline" @color="warning" as |A|>
<Hds::Alert @type="inline" @color="warning" data-test-job-name-warning as |A|>
<A.Title>Don't forget to change the job name!</A.Title>
<A.Description>Since you're cloning a job version's source as a new job, you'll want to change the job name. Otherwise, this will appear as a new version of the original job, rather than a new job.</A.Description>
</Hds::Alert>
Expand Down
132 changes: 127 additions & 5 deletions ui/tests/acceptance/job-versions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,35 +329,157 @@ module('Acceptance | job versions (clone and edit)', function (hooks) {

hooks.beforeEach(async function () {
server.create('node-pool');
namespace = server.create('namespace');

const managementToken = server.create('token');
window.localStorage.nomadTokenSecret = managementToken.secretId;

job = server.create('job', { createAllocations: false, version: 99 });
job = server.create('job', {
createAllocations: false,
version: 99,
namespaceId: namespace.id,
});
// remove auto-created versions and create 3 of them, one with a tag
server.db.jobVersions.remove();
server.create('job-version', { job, version: 99 });
server.create('job-version', {
job,
version: 99,
submitTime: 1731101785761339000,
});
server.create('job-version', {
job,
version: 98,
submitTime: 1731101685761339000,
versionTag: {
Name: 'test-tag',
Description: 'A tag with a brief description',
},
});
server.create('job-version', { job, version: 97 });
server.create('job-version', {
job,
version: 0,
submitTime: 1731101585761339000,
});
await Versions.visit({ id: job.id });
});

test('You can clone a version as a new job', async function (assert) {
// Buttons exist
test('Clone and edit buttons are shown', async function (assert) {
assert.dom('.job-version').exists({ count: 3 });
assert
.dom('[data-test-clone-and-edit]')
.exists(
{ count: 2 },
'Current job version doesnt have clone or revert buttons'
);

const versionBlock = '[data-test-job-version="98"]';

assert
.dom(`${versionBlock} [data-test-clone-as-new-version]`)
.doesNotExist(
'Confirmation-stage clone-as-new-version button doesnt exist on initial load'
);
assert
.dom(`${versionBlock} [data-test-clone-as-new-job]`)
.doesNotExist(
'Confirmation-stage clone-as-new-job button doesnt exist on initial load'
);

await click(`${versionBlock} [data-test-clone-and-edit]`);

assert
.dom(`${versionBlock} [data-test-clone-as-new-version]`)
.exists(
'Confirmation-stage clone-as-new-version button exists after clicking clone and edit'
);

assert
.dom(`${versionBlock} [data-test-clone-as-new-job]`)
.exists(
'Confirmation-stage clone-as-new-job button exists after clicking clone and edit'
);

assert
.dom(`${versionBlock} [data-test-revert-to]`)
.doesNotExist('Revert button is hidden when Clone buttons are expanded');

assert
.dom('[data-test-job-version="0"] [data-test-revert-to]')
.exists('Revert button is visible for other versions');

await click(`${versionBlock} [data-test-cancel-clone]`);

assert
.dom(`${versionBlock} [data-test-clone-as-new-version]`)
.doesNotExist(
'Confirmation-stage clone-as-new-version button doesnt exist after clicking cancel'
);
});

test('Clone as new version', async function (assert) {
const versionBlock = '[data-test-job-version="98"]';
await click(`${versionBlock} [data-test-clone-and-edit]`);
await click(`${versionBlock} [data-test-clone-as-new-version]`);
console.log('namespace', namespace);

assert.equal(
currentURL(),
`/jobs/${job.id}@${namespace.id}/definition?isEditing=true&version=98&view=job-spec`,
'Taken to the definition page in edit mode'
);

await percySnapshot(assert);
});

test('Clone as new version when version is 0', async function (assert) {
const versionBlock = '[data-test-job-version="0"]';
await click(`${versionBlock} [data-test-clone-and-edit]`);
await click(`${versionBlock} [data-test-clone-as-new-version]`);

assert.equal(
currentURL(),
`/jobs/${job.id}@${namespace.id}/definition?isEditing=true&version=0&view=job-spec`,
'Taken to the definition page in edit mode'
);
});

test('Clone as a new version when no submission info is available', async function (assert) {
server.pretender.get('/v1/job/:id/submission', () => [500, {}, '']);
const versionBlock = '[data-test-job-version="98"]';
await click(`${versionBlock} [data-test-clone-and-edit]`);
await click(`${versionBlock} [data-test-clone-as-new-version]`);

assert.equal(
currentURL(),
`/jobs/${job.id}@${namespace.id}/definition?isEditing=true&version=98&view=full-definition`,
'Taken to the definition page in edit mode'
);

assert.dom('[data-test-json-warning]').exists();

await percySnapshot(assert);
});

test('Clone as a new job', async function (assert) {
const testString =
'Test string that should appear in my sourceString url param';
server.pretender.get('/v1/job/:id/submission', () => [
200,
{},
JSON.stringify({
Source: testString,
}),
]);
const versionBlock = '[data-test-job-version="98"]';
await click(`${versionBlock} [data-test-clone-and-edit]`);
await click(`${versionBlock} [data-test-clone-as-new-job]`);

assert.equal(
currentURL(),
`/jobs/run?sourceString=${encodeURIComponent(testString)}`,
'Taken to the new job page'
);
assert.dom('[data-test-job-name-warning]').exists();
});
});

Expand Down

0 comments on commit ff5374e

Please sign in to comment.