Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ui] Remove ember-fetch dependency #24077

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ui/app/services/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { getOwner } from '@ember/application';
import { assign } from '@ember/polyfills';
import { task, timeout } from 'ember-concurrency';
import queryString from 'query-string';
import fetch from 'nomad-ui/utils/fetch';
import classic from 'ember-classic-decorator';
import moment from 'moment';

Expand Down
18 changes: 0 additions & 18 deletions ui/app/utils/fetch.js

This file was deleted.

1 change: 0 additions & 1 deletion ui/app/utils/properties/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { get } from '@ember/object';
import { assert } from '@ember/debug';
import RSVP from 'rsvp';
import { task } from 'ember-concurrency';
import { AbortController } from 'fetch';
import wait from 'nomad-ui/utils/wait';
import Watchable from 'nomad-ui/adapters/watchable';
import config from 'nomad-ui/config/environment';
Expand Down
1 change: 0 additions & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
"ember-decorators": "^6.1.1",
"ember-exam": "6.1.0",
"ember-export-application-global": "^2.0.1",
"ember-fetch": "^8.1.1",
"ember-inflector": "^4.0.2",
"ember-inline-svg": "^1.0.1",
"ember-load-initializers": "^2.1.2",
Expand Down
10 changes: 5 additions & 5 deletions ui/tests/acceptance/access-control-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module('Acceptance | access control', function (hooks) {
(t) => t.type === 'management'
);
const { secretId } = managementToken;
await Tokens.secret(secretId).submit();
await Tokens.secret(secretId).submit(this.owner);

assert.dom('[data-test-gutter-link="administration"]').exists();

Expand Down Expand Up @@ -79,7 +79,7 @@ module('Acceptance | access control', function (hooks) {
(t) => t.type === 'management'
);
const { secretId } = managementToken;
await Tokens.secret(secretId).submit();
await Tokens.secret(secretId).submit(this.owner);
await Administration.visit();
assert.dom('[data-test-sentinel-policies-card]').doesNotExist();
});
Expand All @@ -92,7 +92,7 @@ module('Acceptance | access control', function (hooks) {
(t) => t.type === 'management'
);
const { secretId } = managementToken;
await Tokens.secret(secretId).submit();
await Tokens.secret(secretId).submit(this.owner);
await Administration.visit();

assert.dom('[data-test-sentinel-policies-card]').exists();
Expand All @@ -107,7 +107,7 @@ module('Acceptance | access control', function (hooks) {
(t) => t.type === 'management'
);
const { secretId } = managementToken;
await Tokens.secret(secretId).submit();
await Tokens.secret(secretId).submit(this.owner);

await Administration.visit();
assert.dom('[data-test-tokens-card]').exists();
Expand Down Expand Up @@ -140,7 +140,7 @@ module('Acceptance | access control', function (hooks) {
(t) => t.type === 'management'
);
const { secretId } = managementToken;
await Tokens.secret(secretId).submit();
await Tokens.secret(secretId).submit(this.owner);

await Administration.visit();

Expand Down
12 changes: 6 additions & 6 deletions ui/tests/acceptance/actions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ module('Acceptance | actions', function (hooks) {
assert.notOk(Actions.hasTitleActions, 'No actions dropdown by default');
await Tokens.visit();
const { secretId } = managementToken;
await Tokens.secret(secretId).submit();
await Tokens.secret(secretId).submit(this.owner);
await Actions.visitIndex({ id: 'actionable-job' });
assert.ok(
Actions.hasTitleActions,
Expand All @@ -118,7 +118,7 @@ module('Acceptance | actions', function (hooks) {
// Sign out and sign back in as a token without alloc exec
await Tokens.visit();
await Tokens.clear();
await Tokens.secret(clientReaderToken.secretId).submit();
await Tokens.secret(clientReaderToken.secretId).submit(this.owner);
await Actions.visitIndex({ id: 'actionable-job' });
assert.notOk(
Actions.hasTitleActions,
Expand All @@ -132,7 +132,7 @@ module('Acceptance | actions', function (hooks) {
// Sign out and sign back in as a token with alloc exec
await Tokens.visit();
await Tokens.clear();
await Tokens.secret(allocExecToken.secretId).submit();
await Tokens.secret(allocExecToken.secretId).submit(this.owner);
await Actions.visitIndex({ id: 'actionable-job' });
assert.ok(
Actions.hasTitleActions,
Expand All @@ -154,7 +154,7 @@ module('Acceptance | actions', function (hooks) {

await Tokens.visit();
const { secretId } = managementToken;
await Tokens.secret(secretId).submit();
await Tokens.secret(secretId).submit(this.owner);
await Actions.visitIndex({ id: 'actionable-job' });
assert.ok(
Actions.hasTitleActions,
Expand Down Expand Up @@ -286,7 +286,7 @@ module('Acceptance | actions', function (hooks) {

await Tokens.visit();
const { secretId } = managementToken;
await Tokens.secret(secretId).submit();
await Tokens.secret(secretId).submit(this.owner);
await Actions.visitAllocs({ id: 'actionable-job' });

// Get the number of rows; each of them should have an actions dropdown
Expand Down Expand Up @@ -331,7 +331,7 @@ module('Acceptance | actions', function (hooks) {
});
await Tokens.visit();
const { secretId } = managementToken;
await Tokens.secret(secretId).submit();
await Tokens.secret(secretId).submit(this.owner);
await Actions.visitIndex({ id: 'actionable-job' });
// Run an action to open the flyout; observe the dropdown there
await Actions.titleActions.click();
Expand Down
72 changes: 59 additions & 13 deletions ui/tests/acceptance/allocation-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
/* eslint-disable qunit/require-expect */
/* Mirage fixtures are random so we can't expect a set number of assertions */
import AdapterError from '@ember-data/adapter/error';
import { run } from '@ember/runloop';
import { currentURL, click, triggerEvent, waitFor } from '@ember/test-helpers';
import {
currentURL,
click,
triggerEvent,
waitFor,
waitUntil,
} from '@ember/test-helpers';
import { assign } from '@ember/polyfills';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
Expand All @@ -17,7 +22,6 @@ import Allocation from 'nomad-ui/tests/pages/allocations/detail';
import moment from 'moment';
import formatHost from 'nomad-ui/utils/format-host';
import faker from 'nomad-ui/mirage/faker';

let job;
let node;
let allocation;
Expand Down Expand Up @@ -377,6 +381,12 @@ module('Acceptance | allocation detail', function (hooks) {
await Allocation.restart.idle();
await Allocation.restart.confirm();

await waitUntil(() => {
return server.pretender.handledRequests.find((request) => {
return request.method === 'PUT' && request.url.includes(allocation.id);
});
});

assert.equal(
server.pretender.handledRequests.findBy('method', 'PUT').url,
`/v1/client/allocation/${allocation.id}/restart`,
Expand All @@ -397,26 +407,62 @@ module('Acceptance | allocation detail', function (hooks) {
});

test('while an allocation is being restarted, the stop button is disabled', async function (assert) {
server.pretender.post('/v1/allocation/:id/stop', () => [204, {}, ''], true);
let resolveRestart;
const restartRequestPromise = new Promise((resolve) => {
resolveRestart = resolve;
});
server.pretender.put('/v1/client/allocation/:id/restart', () => {
return restartRequestPromise.then(() => {
return [204, {}, ''];
});
});

await Allocation.stop.idle();
await Allocation.restart.idle();
await Allocation.restart.confirm();

run.later(() => {
assert.ok(Allocation.stop.isDisabled, 'Stop is disabled');
assert.ok(Allocation.restart.isDisabled, 'Restart is disabled');
assert.ok(Allocation.restartAll.isDisabled, 'Restart All is disabled');
server.pretender.resolve(server.pretender.requestReferences[0].request);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: with the changes here, requestReferences was always [] during this test.

}, 500);
assert.ok(Allocation.stop.isDisabled, 'Stop is disabled');
assert.ok(Allocation.restart.isDisabled, 'Restart is disabled');
assert.ok(Allocation.restartAll.isDisabled, 'Restart All is disabled');

await Allocation.stop.confirm();
resolveRestart();
await waitUntil(() => !Allocation.stop.isDisabled);

assert.notOk(
Allocation.stop.isDisabled,
'Stop is enabled after request completes'
);
assert.notOk(
Allocation.restart.isDisabled,
'Restart is enabled after request completes'
);
assert.notOk(
Allocation.restartAll.isDisabled,
'Restart All is enabled after request completes'
);
});

test('if stopping or restarting fails, an error message is shown', async function (assert) {
server.pretender.post('/v1/allocation/:id/stop', () => [403, {}, '']);
let resolveStop;
const stopRequestPromise = new Promise((resolve) => {
resolveStop = resolve;
});
server.pretender.post('/v1/allocation/:id/stop', () => {
return stopRequestPromise.then(() => {
return [403, {}, ''];
});
});

await Allocation.stop.idle();
await Allocation.stop.confirm();

assert.notOk(
Allocation.inlineError.isShown,
'No error is shown while request is pending'
);

resolveStop();
await waitUntil(() => Allocation.inlineError.isShown);

assert.ok(Allocation.inlineError.isShown, 'Inline error is shown');
assert.ok(
Allocation.inlineError.title.includes('Could Not Stop Allocation'),
Expand Down
15 changes: 14 additions & 1 deletion ui/tests/acceptance/behaviors/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/* eslint-disable qunit/require-expect */
import { test } from 'qunit';
import { currentURL, visit } from '@ember/test-helpers';
import { currentURL, visit, waitUntil } from '@ember/test-helpers';

import { filesForPath } from 'nomad-ui/mirage/config';
import { formatBytes } from 'nomad-ui/utils/units';
Expand Down Expand Up @@ -363,6 +363,19 @@ export default function browseFilesystem({
assert.ok(FS.fileViewer.isPresent);

const requests = this.server.pretender.handledRequests;
await waitUntil(() => {
return (
requests.some((req) =>
req.url.includes(`${node.httpAddr}/v1/client/fs/readat`)
) &&
requests.some(
(req) =>
req.url.includes('/v1/client/fs/readat') &&
!req.url.includes(node.httpAddr)
)
);
});

const secondAttempt = requests.pop();
const firstAttempt = requests.pop();

Expand Down
Loading
Loading