* refactor: 💡 workers test - create,delete,read,update * fix: 🐛 address comments
99 lines
3.0 KiB
JavaScript
99 lines
3.0 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { visit, click, fillIn } from '@ember/test-helpers';
|
|
import { setupApplicationTest } from 'admin/tests/helpers';
|
|
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
|
import { Response } from 'miragejs';
|
|
import { authenticateSession } from 'ember-simple-auth/test-support';
|
|
import * as commonSelectors from 'admin/tests/helpers/selectors';
|
|
|
|
module('Acceptance | workers | update', function (hooks) {
|
|
setupApplicationTest(hooks);
|
|
setupMirage(hooks);
|
|
|
|
const instances = {
|
|
scopes: {
|
|
global: null,
|
|
},
|
|
};
|
|
|
|
const urls = {
|
|
globalScope: null,
|
|
workers: null,
|
|
worker: null,
|
|
};
|
|
|
|
hooks.beforeEach(async function () {
|
|
//Generate the resources
|
|
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
|
instances.worker = this.server.create('worker', {
|
|
scope: instances.scopes.global,
|
|
});
|
|
// Generate route URLs for resources
|
|
urls.globalScope = '/scopes/global';
|
|
urls.workers = `${urls.globalScope}/workers`;
|
|
(urls.worker = `${urls.workers}/${instances.worker.id}`),
|
|
await authenticateSession({});
|
|
});
|
|
|
|
test('can save changes to an existing worker', async function (assert) {
|
|
await visit(urls.worker);
|
|
|
|
await click(commonSelectors.EDIT_BTN, 'Click edit mode');
|
|
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
|
|
await click(commonSelectors.SAVE_BTN);
|
|
|
|
assert.dom(commonSelectors.HREF(urls.worker)).isVisible();
|
|
await assert
|
|
.dom(commonSelectors.FIELD_NAME)
|
|
.hasValue(commonSelectors.FIELD_NAME_VALUE);
|
|
});
|
|
|
|
test('can cancel changes to an existing worker', async function (assert) {
|
|
const name = instances.worker.name;
|
|
await visit(urls.worker);
|
|
|
|
await click(commonSelectors.EDIT_BTN, 'Click edit mode');
|
|
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
|
|
await click(commonSelectors.CANCEL_BTN);
|
|
|
|
await assert.dom(commonSelectors.FIELD_NAME).hasValue(`${name}`);
|
|
});
|
|
|
|
test('saving an existing worker with invalid fields displays error messages', async function (assert) {
|
|
const errorMessage = 'Error in provided request.';
|
|
const errorDescription = 'Must be all lowercase.';
|
|
this.server.patch('/workers/:id', () => {
|
|
return new Response(
|
|
400,
|
|
{},
|
|
{
|
|
status: 400,
|
|
code: 'invalid_argument',
|
|
message: errorMessage,
|
|
details: {
|
|
request_fields: [
|
|
{
|
|
name: 'name',
|
|
description: errorDescription,
|
|
},
|
|
],
|
|
},
|
|
},
|
|
);
|
|
});
|
|
await visit(urls.worker);
|
|
|
|
await click(commonSelectors.EDIT_BTN, 'Click edit mode');
|
|
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
|
|
await click(commonSelectors.SAVE_BTN);
|
|
|
|
assert.dom(commonSelectors.ALERT_TOAST_BODY).hasText(errorMessage);
|
|
assert.dom(commonSelectors.FIELD_NAME_ERROR).hasText(errorDescription);
|
|
});
|
|
});
|