2018-09-25 16:28:26 +00:00
|
|
|
import { currentRouteName } from '@ember/test-helpers';
|
2018-05-24 03:10:21 +00:00
|
|
|
import page from 'vault/tests/pages/access/identity/aliases/add';
|
|
|
|
import aliasIndexPage from 'vault/tests/pages/access/identity/aliases/index';
|
|
|
|
import aliasShowPage from 'vault/tests/pages/access/identity/aliases/show';
|
|
|
|
import createItemPage from 'vault/tests/pages/access/identity/create';
|
|
|
|
import showItemPage from 'vault/tests/pages/access/identity/show';
|
2018-09-25 16:28:26 +00:00
|
|
|
import withFlash from 'vault/tests/helpers/with-flash';
|
2018-05-24 03:10:21 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
export const testAliasCRUD = async function(name, itemType, assert) {
|
2018-05-24 03:10:21 +00:00
|
|
|
let itemID;
|
|
|
|
let aliasID;
|
2018-09-25 16:28:26 +00:00
|
|
|
let idRow;
|
2018-05-24 03:10:21 +00:00
|
|
|
if (itemType === 'groups') {
|
|
|
|
createItemPage.createItem(itemType, 'external');
|
|
|
|
} else {
|
|
|
|
createItemPage.createItem(itemType);
|
|
|
|
}
|
2018-09-25 16:28:26 +00:00
|
|
|
await withFlash();
|
|
|
|
idRow = showItemPage.rows.filterBy('hasLabel').filterBy('rowLabel', 'ID')[0];
|
|
|
|
itemID = idRow.rowValue;
|
|
|
|
await page.visit({ item_type: itemType, id: itemID });
|
|
|
|
|
|
|
|
await withFlash(page.editForm.name(name).submit(), () => {
|
2018-05-24 03:10:21 +00:00
|
|
|
assert.ok(
|
2018-05-29 14:14:31 +00:00
|
|
|
aliasShowPage.flashMessage.latestMessage.startsWith(
|
|
|
|
'Successfully saved',
|
|
|
|
`${itemType}: shows a flash message`
|
|
|
|
)
|
2018-05-24 03:10:21 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
idRow = aliasShowPage.rows.filterBy('hasLabel').filterBy('rowLabel', 'ID')[0];
|
|
|
|
aliasID = idRow.rowValue;
|
|
|
|
assert.equal(
|
|
|
|
currentRouteName(),
|
|
|
|
'vault.cluster.access.identity.aliases.show',
|
|
|
|
'navigates to the correct route'
|
|
|
|
);
|
|
|
|
assert.ok(aliasShowPage.nameContains(name), `${itemType}: renders the name on the show page`);
|
2018-05-24 03:10:21 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
await aliasIndexPage.visit({ item_type: itemType });
|
|
|
|
assert.equal(
|
|
|
|
aliasIndexPage.items.filterBy('name', name).length,
|
|
|
|
1,
|
|
|
|
`${itemType}: lists the entity in the entity list`
|
|
|
|
);
|
|
|
|
|
|
|
|
let item = aliasIndexPage.items.filterBy('name', name)[0];
|
|
|
|
await item.menu();
|
|
|
|
|
|
|
|
await aliasIndexPage.delete();
|
|
|
|
await withFlash(aliasIndexPage.confirmDelete(), () => {
|
2018-05-29 14:14:31 +00:00
|
|
|
aliasIndexPage.flashMessage.latestMessage.startsWith(
|
|
|
|
'Successfully deleted',
|
|
|
|
`${itemType}: shows flash message`
|
|
|
|
);
|
2018-05-24 03:10:21 +00:00
|
|
|
});
|
2018-09-25 16:28:26 +00:00
|
|
|
|
|
|
|
assert.equal(aliasIndexPage.items.filterBy('id', aliasID).length, 0, `${itemType}: the row is deleted`);
|
2018-05-24 03:10:21 +00:00
|
|
|
};
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
export const testAliasDeleteFromForm = async function(name, itemType, assert) {
|
2018-05-24 03:10:21 +00:00
|
|
|
let itemID;
|
|
|
|
let aliasID;
|
2018-09-25 16:28:26 +00:00
|
|
|
let idRow;
|
2018-05-24 03:10:21 +00:00
|
|
|
if (itemType === 'groups') {
|
|
|
|
createItemPage.createItem(itemType, 'external');
|
|
|
|
} else {
|
|
|
|
createItemPage.createItem(itemType);
|
|
|
|
}
|
2018-09-25 16:28:26 +00:00
|
|
|
await withFlash();
|
|
|
|
idRow = showItemPage.rows.filterBy('hasLabel').filterBy('rowLabel', 'ID')[0];
|
|
|
|
itemID = idRow.rowValue;
|
|
|
|
await page.visit({ item_type: itemType, id: itemID });
|
2018-05-24 03:10:21 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
await withFlash(page.editForm.name(name).submit());
|
|
|
|
|
|
|
|
idRow = aliasShowPage.rows.filterBy('hasLabel').filterBy('rowLabel', 'ID')[0];
|
|
|
|
aliasID = idRow.rowValue;
|
|
|
|
await aliasShowPage.edit();
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
currentRouteName(),
|
|
|
|
'vault.cluster.access.identity.aliases.edit',
|
|
|
|
`${itemType}: navigates to edit on create`
|
|
|
|
);
|
|
|
|
await page.editForm.delete();
|
|
|
|
|
|
|
|
await withFlash(page.editForm.confirmDelete(), () => {
|
2018-05-29 14:14:31 +00:00
|
|
|
aliasIndexPage.flashMessage.latestMessage.startsWith(
|
|
|
|
'Successfully deleted',
|
|
|
|
`${itemType}: shows flash message`
|
|
|
|
);
|
2018-05-24 03:10:21 +00:00
|
|
|
});
|
2018-09-25 16:28:26 +00:00
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
currentRouteName(),
|
|
|
|
'vault.cluster.access.identity.aliases.index',
|
|
|
|
`${itemType}: navigates to list page on delete`
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
aliasIndexPage.items.filterBy('id', aliasID).length,
|
|
|
|
0,
|
|
|
|
`${itemType}: the row does not show in the list`
|
|
|
|
);
|
2018-05-24 03:10:21 +00:00
|
|
|
};
|