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/create';
|
|
|
|
import showPage from 'vault/tests/pages/access/identity/show';
|
|
|
|
import indexPage from 'vault/tests/pages/access/identity/index';
|
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 testCRUD = async (name, itemType, assert) => {
|
|
|
|
await page.visit({ item_type: itemType });
|
|
|
|
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
|
|
|
showPage.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
|
|
|
assert.equal(
|
|
|
|
currentRouteName(),
|
|
|
|
'vault.cluster.access.identity.show',
|
|
|
|
`${itemType}: navigates to show on create`
|
|
|
|
);
|
|
|
|
assert.ok(showPage.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 indexPage.visit({ item_type: itemType });
|
|
|
|
assert.equal(
|
|
|
|
indexPage.items.filterBy('name', name).length,
|
|
|
|
1,
|
|
|
|
`${itemType}: lists the entity in the entity list`
|
|
|
|
);
|
|
|
|
await indexPage.items.filterBy('name', name)[0].menu();
|
|
|
|
await indexPage.delete();
|
|
|
|
await withFlash(indexPage.confirmDelete(), () => {
|
|
|
|
assert.ok(
|
|
|
|
indexPage.flashMessage.latestMessage.startsWith(
|
|
|
|
'Successfully deleted',
|
|
|
|
`${itemType}: shows flash message`
|
|
|
|
)
|
2018-05-29 14:14:31 +00:00
|
|
|
);
|
2018-05-24 03:10:21 +00:00
|
|
|
});
|
2018-09-25 16:28:26 +00:00
|
|
|
assert.equal(indexPage.items.filterBy('name', name).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 testDeleteFromForm = async (name, itemType, assert) => {
|
|
|
|
await page.visit({ item_type: itemType });
|
|
|
|
|
|
|
|
await withFlash(page.editForm.name(name).submit());
|
|
|
|
await showPage.edit();
|
|
|
|
assert.equal(
|
|
|
|
currentRouteName(),
|
|
|
|
'vault.cluster.access.identity.edit',
|
|
|
|
`${itemType}: navigates to edit on create`
|
|
|
|
);
|
|
|
|
await page.editForm.delete();
|
|
|
|
await withFlash(page.editForm.confirmDelete(), () => {
|
|
|
|
assert.ok(
|
|
|
|
indexPage.flashMessage.latestMessage.startsWith(
|
|
|
|
'Successfully deleted',
|
|
|
|
`${itemType}: shows flash message`
|
|
|
|
)
|
2018-05-29 14:14:31 +00:00
|
|
|
);
|
2018-05-24 03:10:21 +00:00
|
|
|
});
|
2018-09-25 16:28:26 +00:00
|
|
|
assert.equal(
|
|
|
|
currentRouteName(),
|
|
|
|
'vault.cluster.access.identity.index',
|
|
|
|
`${itemType}: navigates to list page on delete`
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
indexPage.items.filterBy('name', name).length,
|
|
|
|
0,
|
|
|
|
`${itemType}: the row does not show in the list`
|
|
|
|
);
|
2018-05-24 03:10:21 +00:00
|
|
|
};
|