Merge branch 'main' into add-type-field-to-credential-library
This commit is contained in:
4 files changed
+190
-13
No files matched your search
@@ -1,5 +1,9 @@
|
||||
import Route from '@ember/routing/route';
|
||||
import { hash, all } from 'rsvp';
|
||||
import { all } from 'rsvp';
|
||||
import { action } from '@ember/object';
|
||||
import loading from 'ember-loading/decorator';
|
||||
import { confirm } from 'core/decorators/confirm';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
|
||||
export default class ScopesScopeTargetsTargetCredentialLibrariesRoute extends Route {
|
||||
// =methods
|
||||
@@ -11,17 +15,13 @@ export default class ScopesScopeTargetsTargetCredentialLibrariesRoute extends Ro
|
||||
beforeModel() {
|
||||
const { application_credential_library_ids: credential_libraries } =
|
||||
this.modelFor('scopes.scope.targets.target');
|
||||
return hash({
|
||||
credentialLibraries: all(
|
||||
credential_libraries.map((credential_library) =>
|
||||
this.store.findRecord(
|
||||
'credential-library',
|
||||
credential_library.value,
|
||||
{ reload: true }
|
||||
)
|
||||
)
|
||||
),
|
||||
});
|
||||
return all(
|
||||
credential_libraries.map((credential_library) =>
|
||||
this.store.findRecord('credential-library', credential_library.value, {
|
||||
reload: true,
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,4 +31,21 @@ export default class ScopesScopeTargetsTargetCredentialLibrariesRoute extends Ro
|
||||
model() {
|
||||
return this.modelFor('scopes.scope.targets.target');
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Remove a credential library from the current target.
|
||||
* @param {TargetModel} target
|
||||
* @param {CredentialLibraryModel} credentialLibrary
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@confirm('questions.remove-confirm')
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess('notifications.remove-success')
|
||||
async removeCredentialLibrary(target, credentialLibrary) {
|
||||
await target.removeCredentialLibrary(credentialLibrary.id);
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
<row.headerCell>{{t 'form.name.label'}}</row.headerCell>
|
||||
<row.headerCell>{{t 'form.type.label'}}</row.headerCell>
|
||||
<row.headerCell>{{t 'form.id.label'}}</row.headerCell>
|
||||
<row.headerCell>{{t 'titles.actions'}}</row.headerCell>
|
||||
</header.row>
|
||||
</table.header>
|
||||
<table.body as |body|>
|
||||
@@ -41,6 +42,28 @@
|
||||
<code>{{credentialLibrary.id}}</code>
|
||||
</Copyable>
|
||||
</row.cell>
|
||||
<row.cell>
|
||||
<Rose::Dropdown
|
||||
@icon='more-horizontal'
|
||||
@iconOnly={{true}}
|
||||
@showCaret={{false}}
|
||||
@dropdownRight={{true}}
|
||||
@text={{t 'actions.manage'}}
|
||||
as |dropdown|
|
||||
>
|
||||
<dropdown.button
|
||||
@style='danger'
|
||||
{{on
|
||||
'click'
|
||||
(route-action
|
||||
'removeCredentialLibrary' @model credentialLibrary
|
||||
)
|
||||
}}
|
||||
>
|
||||
{{t 'actions.remove'}}
|
||||
</dropdown.button>
|
||||
</Rose::Dropdown>
|
||||
</row.cell>
|
||||
</body.row>
|
||||
{{/each}}
|
||||
</table.body>
|
||||
|
||||
@@ -2,6 +2,7 @@ import { module, test } from 'qunit';
|
||||
import { visit, click, fillIn, currentURL, find } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import { Response } from 'miragejs';
|
||||
import { resolve, reject } from 'rsvp';
|
||||
@@ -30,6 +31,7 @@ module('Acceptance | credential-library', function (hooks) {
|
||||
credentialLibrary: null,
|
||||
credentialLibraries: null,
|
||||
newCredentialLibrary: null,
|
||||
unknownCredentialLibrary: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
@@ -58,12 +60,31 @@ module('Acceptance | credential-library', function (hooks) {
|
||||
urls.credentialLibraries = `${urls.credentialStore}/credential-libraries`;
|
||||
urls.credentialLibrary = `${urls.credentialLibraries}/${instances.credentialLibrary.id}`;
|
||||
urls.newCredentialLibrary = `${urls.credentialLibraries}/new`;
|
||||
// Generate resource couner
|
||||
urls.unknownCredentialLibrary = `${urls.credentialLibraries}/foo`;
|
||||
// Generate resource counter
|
||||
getCredentialLibraryCount = () =>
|
||||
this.server.schema.credentialLibraries.all().models.length;
|
||||
authenticateSession({});
|
||||
});
|
||||
|
||||
test('visiting credential libraries', async function (assert) {
|
||||
assert.expect(2);
|
||||
await visit(urls.credentialLibraries);
|
||||
await a11yAudit();
|
||||
assert.equal(currentURL(), urls.credentialLibraries);
|
||||
await visit(urls.credentialLibrary);
|
||||
await a11yAudit();
|
||||
assert.equal(currentURL(), urls.credentialLibrary);
|
||||
});
|
||||
|
||||
test('visiting an unknown credential library displays 404 message', async function (assert) {
|
||||
assert.expect(1);
|
||||
await visit(urls.unknownCredentialLibrary);
|
||||
await a11yAudit();
|
||||
console.debug(find('.rose-message-subtitle'));
|
||||
assert.ok(find('.rose-message-subtitle').textContent.trim(), 'Error 404');
|
||||
});
|
||||
|
||||
test('can create a credential library', async function (assert) {
|
||||
assert.expect(1);
|
||||
const count = getCredentialLibraryCount();
|
||||
@@ -147,4 +168,22 @@ module('Acceptance | credential-library', function (hooks) {
|
||||
assert.equal(getCredentialLibraryCount(), count);
|
||||
assert.ok(confirmService.confirm.calledOnce);
|
||||
});
|
||||
|
||||
test('deleting a credential library which errors displays error messages', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.del('/credential-libraries/:id', () => {
|
||||
return new Response(
|
||||
490,
|
||||
{},
|
||||
{
|
||||
status: 490,
|
||||
code: 'error',
|
||||
message: 'Oops.',
|
||||
}
|
||||
);
|
||||
});
|
||||
await visit(urls.credentialLibrary);
|
||||
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
|
||||
assert.ok(find('[role="alert"]').textContent.trim(), 'Oops.');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,98 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, find, findAll, click } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { Response } from 'miragejs';
|
||||
import {
|
||||
authenticateSession,
|
||||
// These are left here intentionally for future reference.
|
||||
//currentSession,
|
||||
//invalidateSession,
|
||||
} from 'ember-simple-auth/test-support';
|
||||
|
||||
module('Acceptance | targets | credential-libraries', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
let getCredentialLibraryCount;
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
org: null,
|
||||
project: null,
|
||||
},
|
||||
credentialLibraries: null,
|
||||
};
|
||||
const urls = {
|
||||
globalScope: null,
|
||||
orgScope: null,
|
||||
projectScope: null,
|
||||
targets: null,
|
||||
target: null,
|
||||
targetCredentialLibraries: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
// Generate resources
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
scope: { id: 'global', type: 'global' },
|
||||
});
|
||||
instances.scopes.project = this.server.create('scope', {
|
||||
type: 'project',
|
||||
scope: { id: instances.scopes.org.id, type: 'org' },
|
||||
});
|
||||
instances.credentialLibraries = this.server.createList(
|
||||
'credential-library',
|
||||
2,
|
||||
{ scope: instances.scopes.project }
|
||||
);
|
||||
instances.target = this.server.create('target', {
|
||||
scope: instances.scopes.project,
|
||||
credentialLibraries: instances.credentialLibraries,
|
||||
});
|
||||
// Generate route URLs for resources
|
||||
urls.globalScope = `/scopes/global/scopes`;
|
||||
urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`;
|
||||
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
|
||||
urls.targets = `/scopes/${instances.scopes.project.id}/targets`;
|
||||
urls.target = `${urls.targets}/${instances.target.id}`;
|
||||
urls.targetCredentialLibraries = `${urls.target}/credential-libraries`;
|
||||
// Generate resource counter
|
||||
getCredentialLibraryCount = () =>
|
||||
this.server.schema.credentialLibraries.all().models.length;
|
||||
authenticateSession({});
|
||||
});
|
||||
|
||||
test('can remove a credential library', async function (assert) {
|
||||
assert.expect(2);
|
||||
const count = getCredentialLibraryCount();
|
||||
await visit(urls.targetCredentialLibraries);
|
||||
assert.equal(findAll('tbody tr').length, count);
|
||||
await click('tbody tr .rose-dropdown-button-danger');
|
||||
assert.equal(findAll('tbody tr').length, count - 1);
|
||||
});
|
||||
|
||||
test('removing a target credential library which errors displays error messages', async function (assert) {
|
||||
assert.expect(2);
|
||||
this.server.post('/targets/:idMethod', () => {
|
||||
return new Response(
|
||||
400,
|
||||
{},
|
||||
{
|
||||
status: 400,
|
||||
code: 'invalid_argument',
|
||||
message: 'The request was invalid.',
|
||||
details: {},
|
||||
}
|
||||
);
|
||||
});
|
||||
const count = getCredentialLibraryCount();
|
||||
await visit(urls.targetCredentialLibraries);
|
||||
assert.equal(findAll('tbody tr').length, count);
|
||||
await click('tbody tr .rose-dropdown-button-danger');
|
||||
assert.ok(find('[role="alert"]'));
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user