Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hashishaw committed Sep 19, 2024
1 parent 097e3c8 commit c4aa43d
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 33 deletions.
28 changes: 19 additions & 9 deletions ui/tests/acceptance/secrets/backend/ldap/libraries-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,35 @@ module('Acceptance | ldap | libraries', function (hooks) {
ldapMirageScenario(this.server);
this.backend = `ldap-test-${uuidv4()}`;
await authPage.login();
await runCmd(mountEngineCmd('ldap', this.backend));
return visitURL('libraries');
// mount & configure
await runCmd([
mountEngineCmd('ldap', this.backend),
`write ${this.backend}/config binddn=foo bindpass=bar url=http://localhost:8208`,
]);
return visitURL('libraries', this.backend);
});

hooks.afterEach(async function () {
await runCmd(deleteEngineCmd(this.backend));
});

test('it should show libraries on overview page', async function (assert) {
await visitURL('overview');
await visitURL('overview', this.backend);
assert.dom('[data-test-libraries-count]').hasText('1');
});

test('it should transition to create library route on toolbar link click', async function (assert) {
await click('[data-test-toolbar-action="library"]');
assert.true(isURL('libraries/create'), 'Transitions to library create route on toolbar link click');
assert.true(
isURL('libraries/create', this.backend),
'Transitions to library create route on toolbar link click'
);
});

test('it should transition to library details route on list item click', async function (assert) {
await click('[data-test-list-item-link] a');
assert.true(
isURL('libraries/test-library/details/accounts'),
isURL('libraries/test-library/details/accounts', this.backend),
'Transitions to library details accounts route on list item click'
);
assert.dom('[data-test-account-name]').exists({ count: 2 }, 'lists the accounts');
Expand All @@ -59,7 +66,7 @@ module('Acceptance | ldap | libraries', function (hooks) {
await click(`[data-test-${action}]`);
const uri = action === 'details' ? 'details/accounts' : action;
assert.true(
isURL(`libraries/test-library/${uri}`),
isURL(`libraries/test-library/${uri}`, this.backend),
`Transitions to ${action} route on list item action menu click`
);
await click('[data-test-breadcrumb="libraries"] a');
Expand All @@ -70,20 +77,23 @@ module('Acceptance | ldap | libraries', function (hooks) {
await click('[data-test-list-item-link] a');
await click('[data-test-tab="config"]');
assert.true(
isURL('libraries/test-library/details/configuration'),
isURL('libraries/test-library/details/configuration', this.backend),
'Transitions to configuration route on tab click'
);

await click('[data-test-tab="accounts"]');
assert.true(
isURL('libraries/test-library/details/accounts'),
isURL('libraries/test-library/details/accounts', this.backend),
'Transitions to accounts route on tab click'
);
});

test('it should transition to routes from library details toolbar links', async function (assert) {
await click('[data-test-list-item-link] a');
await click('[data-test-edit]');
assert.true(isURL('libraries/test-library/edit'), 'Transitions to credentials route from toolbar link');
assert.true(
isURL('libraries/test-library/edit', this.backend),
'Transitions to credentials route from toolbar link'
);
});
});
54 changes: 37 additions & 17 deletions ui/tests/acceptance/secrets/backend/ldap/overview-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,28 @@
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { v4 as uuidv4 } from 'uuid';
import ldapMirageScenario from 'vault/mirage/scenarios/ldap';
import ldapHandlers from 'vault/mirage/handlers/ldap';
import authPage from 'vault/tests/pages/auth';
import { click, fillIn, visit } from '@ember/test-helpers';
import { selectChoose } from 'ember-power-select/test-support';
import { isURL, visitURL } from 'vault/tests/helpers/ldap/ldap-helpers';
import { deleteEngineCmd, runCmd } from 'vault/tests/helpers/commands';
import { deleteEngineCmd, mountEngineCmd, runCmd } from 'vault/tests/helpers/commands';

module('Acceptance | ldap | overview', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);

hooks.beforeEach(async function () {
ldapHandlers(this.server);
this.backend = `ldap-test-${uuidv4()}`;
this.mountAndConfig = (backend) => {
return runCmd([
mountEngineCmd('ldap', backend),
`write ${backend}/config binddn=foo bindpass=bar url=http://localhost:8208`,
]);
};
return authPage.login();
});

Expand All @@ -39,63 +47,75 @@ module('Acceptance | ldap | overview', function (hooks) {

test('it should transition to routes on tab link click', async function (assert) {
assert.expect(4);
await this.mountAndConfig(this.backend);

await visitURL('overview');
await visitURL('overview', this.backend);

for (const tab of ['roles', 'libraries', 'config', 'overview']) {
await click(`[data-test-tab="${tab}"]`);
const route = tab === 'config' ? 'configuration' : tab;
assert.true(isURL(route), `Transitions to ${route} route on tab link click`);
assert.true(isURL(route, this.backend), `Transitions to ${route} route on tab link click`);
}
});

test('it should transition to configuration route when engine is not configured', async function (assert) {
await visitURL('overview');
await runCmd(mountEngineCmd('ldap', this.backend));
await visitURL('overview', this.backend);
await click('[data-test-config-cta] a');
assert.true(isURL('configure'), 'Transitions to configure route on cta link click');
assert.true(isURL('configure', this.backend), 'Transitions to configure route on cta link click');

await click('[data-test-breadcrumb="ldap-test"] a');
await click(`[data-test-breadcrumb="${this.backend}"] a`);
await click('[data-test-toolbar-action="config"]');
assert.true(isURL('configure'), 'Transitions to configure route on toolbar link click');
assert.true(isURL('configure', this.backend), 'Transitions to configure route on toolbar link click');
});
// including a test for the configuration route here since it is the only one needed
test('it should transition to configuration edit on toolbar link click', async function (assert) {
ldapMirageScenario(this.server);
await visitURL('overview');
await this.mountAndConfig(this.backend);
await visitURL('overview', this.backend);
await click('[data-test-tab="config"]');
await click('[data-test-toolbar-config-action]');
assert.true(isURL('configure'), 'Transitions to configure route on toolbar link click');
assert.true(isURL('configure', this.backend), 'Transitions to configure route on toolbar link click');
});

test('it should transition to create role route on card action link click', async function (assert) {
ldapMirageScenario(this.server);
await visitURL('overview');
await this.mountAndConfig(this.backend);
await visitURL('overview', this.backend);
await click('[data-test-overview-card="Roles"] a');
assert.true(isURL('roles/create'), 'Transitions to role create route on card action link click');
assert.true(
isURL('roles/create', this.backend),
'Transitions to role create route on card action link click'
);
});

test('it should transition to create library route on card action link click', async function (assert) {
ldapMirageScenario(this.server);
await visitURL('overview');
await this.mountAndConfig(this.backend);
await visitURL('overview', this.backend);
await click('[data-test-overview-card="Libraries"] a');
assert.true(isURL('libraries/create'), 'Transitions to library create route on card action link click');
assert.true(
isURL('libraries/create', this.backend),
'Transitions to library create route on card action link click'
);
});

test('it should transition to role credentials route on generate credentials action', async function (assert) {
ldapMirageScenario(this.server);
await visitURL('overview');
await this.mountAndConfig(this.backend);
await visitURL('overview', this.backend);
await selectChoose('.search-select', 'static-role');
await click('[data-test-generate-credential-button]');
assert.true(
isURL('roles/static/static-role/credentials'),
isURL('roles/static/static-role/credentials', this.backend),
'Transitions to role credentials route on generate credentials action'
);

await click('[data-test-breadcrumb="ldap-test"] a');
await click(`[data-test-breadcrumb="${this.backend}"] a`);
await selectChoose('.search-select', 'dynamic-role');
await click('[data-test-generate-credential-button]');
assert.true(
isURL('roles/dynamic/dynamic-role/credentials'),
isURL('roles/dynamic/dynamic-role/credentials', this.backend),
'Transitions to role credentials route on generate credentials action'
);
});
Expand Down
32 changes: 25 additions & 7 deletions ui/tests/acceptance/secrets/backend/ldap/roles-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { v4 as uuidv4 } from 'uuid';
import ldapMirageScenario from 'vault/mirage/scenarios/ldap';
import ldapHandlers from 'vault/mirage/handlers/ldap';
import authPage from 'vault/tests/pages/auth';
import { click, fillIn, waitFor } from '@ember/test-helpers';
import { isURL, visitURL } from 'vault/tests/helpers/ldap/ldap-helpers';
import { GENERAL } from 'vault/tests/helpers/general-selectors';
import { deleteEngineCmd, mountEngineCmd, runCmd } from 'vault/tests/helpers/commands';

module('Acceptance | ldap | roles', function (hooks) {
setupApplicationTest(hooks);
Expand All @@ -20,26 +22,39 @@ module('Acceptance | ldap | roles', function (hooks) {
hooks.beforeEach(async function () {
ldapHandlers(this.server);
ldapMirageScenario(this.server);
this.backend = `ldap-test-${uuidv4()}`;
await authPage.login();
return visitURL('roles');
// mount & configure
await runCmd([
mountEngineCmd('ldap', this.backend),
`write ${this.backend}/config binddn=foo bindpass=bar url=http://localhost:8208`,
]);
return visitURL('roles', this.backend);
});

hooks.afterEach(async function () {
await runCmd(deleteEngineCmd(this.backend));
});

test('it should transition to create role route on toolbar link click', async function (assert) {
await click('[data-test-toolbar-action="role"]');
assert.true(isURL('roles/create'), 'Transitions to role create route on toolbar link click');
assert.true(
isURL('roles/create', this.backend),
'Transitions to role create route on toolbar link click'
);
});

test('it should transition to role details route on list item click', async function (assert) {
await click('[data-test-list-item-link]:nth-of-type(1) a');
assert.true(
isURL('roles/dynamic/dynamic-role/details'),
isURL('roles/dynamic/dynamic-role/details', this.backend),
'Transitions to role details route on list item click'
);

await click('[data-test-breadcrumb="roles"] a');
await click('[data-test-list-item-link]:nth-of-type(2) a');
assert.true(
isURL('roles/static/static-role/details'),
isURL('roles/static/static-role/details', this.backend),
'Transitions to role details route on list item click'
);
});
Expand All @@ -52,7 +67,7 @@ module('Acceptance | ldap | roles', function (hooks) {
await click(`[data-test-${action}]`);
const uri = action === 'get-creds' ? 'credentials' : action;
assert.true(
isURL(`roles/dynamic/dynamic-role/${uri}`),
isURL(`roles/dynamic/dynamic-role/${uri}`, this.backend),
`Transitions to ${uri} route on list item action menu click`
);
await click('[data-test-breadcrumb="roles"] a');
Expand All @@ -63,13 +78,16 @@ module('Acceptance | ldap | roles', function (hooks) {
await click('[data-test-list-item-link]:nth-of-type(1) a');
await click('[data-test-get-credentials]');
assert.true(
isURL('roles/dynamic/dynamic-role/credentials'),
isURL('roles/dynamic/dynamic-role/credentials', this.backend),
'Transitions to credentials route from toolbar link'
);

await click('[data-test-breadcrumb="dynamic-role"] a');
await click('[data-test-edit]');
assert.true(isURL('roles/dynamic/dynamic-role/edit'), 'Transitions to edit route from toolbar link');
assert.true(
isURL('roles/dynamic/dynamic-role/edit', this.backend),
'Transitions to edit route from toolbar link'
);
});

test('it should clear roles page filter value on route exit', async function (assert) {
Expand Down

0 comments on commit c4aa43d

Please sign in to comment.