Files
threshold-ui/ui/admin/tests/acceptance/workers/update-test.js
T
Lisbet Alvarez 72f7c8a92d fix: 🐛 OIDC authentications not properly showing username (#2930)
* fix: 🐛 properly show username for oidc auth method in user menu

* test: 💍 fix admin ui tests

* test: 💍 fix desktop ui tests

* refactor: 💡 admin to not store username in authenticated object

* refactor: 💡 use getter in app controller

* test: 💍 POC for how we could update our tests to use auth account

* refactor: 💡 remove unused service

* test: 💍 fix all tests in ui/admin

* test: 💍 revert one change

* refactor: 💡 update ui/desktop w/ feedback + fix tests

* refactor: 💡 add in error handling

* refactor: 💡 cleanup unused service

* test: 💍 fix e2e test selector

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-17231
2025-10-30 12:49:30 -07:00

95 lines
2.8 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 { Response } from 'miragejs';
import * as commonSelectors from 'admin/tests/helpers/selectors';
module('Acceptance | workers | update', function (hooks) {
setupApplicationTest(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.schema.scopes.find('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}`;
});
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);
});
});