Skip to content

Commit

Permalink
fix ui functional tests (#2819)
Browse files Browse the repository at this point in the history
Signed-off-by: aporss <[email protected]>
  • Loading branch information
ArtjomsPorss authored Dec 4, 2024
1 parent 8deaec8 commit 87c5565
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 130 deletions.
102 changes: 52 additions & 50 deletions ui/src/__tests__/spec/tests/groups.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const TEST_NAME_GROUP_ADD_USER_INPUT =
'dropdown input for adding user during group creation - should preserve input on blur, make input bold when selected in dropdown, reject unselected input';
const TEST_NAME_GROUP_REVIEW_EXTEND =
'Group Review - Extend radio button should be enabled only when Expiry/Review (Days) are set in settings';
const TEST_NAME_GROUP_DOMAIN_FILTER =
'Domain Filter - only principals matching specific domain(s) can be added to a group';

describe('group screen tests', () => {
let currentTest;
Expand Down Expand Up @@ -201,44 +203,8 @@ describe('group screen tests', () => {
await expect(extendRadio).toBeEnabled();
});

afterEach(async () => {
// runs after each test and checks which test was run to perform corresponding cleanup logic
if (currentTest === TEST_NAME_GROUP_HISTORY_VISIBLE_AFTER_REFRESH) {
// open browser
await browser.newUser();
await browser.url(`/`);
// select domain
let domain = 'athenz.dev.functional-test';
let testDomain = await $(`a*=${domain}`);
await testDomain.click();

// navigate to groups page
let groups = await $('div*=Groups');
await groups.click();

// delete the group used in the test
let buttonDeleteGroup = await $(
'.//*[local-name()="svg" and @id="delete-group-icon-history-test-group"]'
);
await buttonDeleteGroup.click();
let modalDeleteButton = await $('button*=Delete');
await modalDeleteButton.click();
} else if (currentTest === TEST_NAME_GROUP_REVIEW_EXTEND) {
await browser.newUser();
await browser.url(`/domain/athenz.dev.functional-test/group`);
await expect(browser).toHaveUrl(expect.stringContaining('athenz'));

await $(
`.//*[local-name()="svg" and @id="delete-group-icon-${reviewExtendTest}"]`
).click();
await $('button*=Delete').click();
}

// to reset currentTest after running cleanup
currentTest = '';
});

it('Domain Filter - only principals matching specific domain(s) can be added to a group', async () => {
it(TEST_NAME_GROUP_DOMAIN_FILTER, async () => {
currentTest = TEST_NAME_GROUP_DOMAIN_FILTER;
// open browser
await browser.newUser();
await browser.url(`/domain/athenz.dev.functional-test/group`);
Expand Down Expand Up @@ -294,7 +260,7 @@ describe('group screen tests', () => {
memberRow = await $(`tr[data-wdio='${unix}-member-row']`).$(
`td*=${unix}`
);
await expect(memberRow).toHaveTextContaining(unix);
await expect(memberRow).toHaveText(expect.stringContaining(unix));

// specify user domain to be able to add non-unix user
await $('div*=Settings').click();
Expand All @@ -318,19 +284,55 @@ describe('group screen tests', () => {
memberRow = await $(`tr[data-wdio='${nonUnixUser}-member-row']`).$(
`td*=${nonUnixUser}`
);
await expect(memberRow).toHaveTextContaining(nonUnixUser);
await expect(memberRow).toHaveText(
expect.stringContaining(nonUnixUser)
);
});

// delete group created in previous test
after(async () => {
// delete group created in previous test
await browser.newUser();
await browser.url(`/domain/athenz.dev.functional-test/group`);
await expect(browser).toHaveUrlContaining('athenz');
afterEach(async () => {
// runs after each test and checks which test was run to perform corresponding cleanup logic
if (currentTest === TEST_NAME_GROUP_HISTORY_VISIBLE_AFTER_REFRESH) {
// open browser
await browser.newUser();
await browser.url(`/`);
// select domain
let domain = 'athenz.dev.functional-test';
let testDomain = await $(`a*=${domain}`);
await testDomain.click();

await $(
`.//*[local-name()="svg" and @id="delete-group-icon-${domainFilterTest}"]`
).click();
await $('button*=Delete').click();
// navigate to groups page
let groups = await $('div*=Groups');
await groups.click();

// delete the group used in the test
let buttonDeleteGroup = await $(
'.//*[local-name()="svg" and @id="delete-group-icon-history-test-group"]'
);
await buttonDeleteGroup.click();
let modalDeleteButton = await $('button*=Delete');
await modalDeleteButton.click();
} else if (currentTest === TEST_NAME_GROUP_REVIEW_EXTEND) {
await browser.newUser();
await browser.url(`/domain/athenz.dev.functional-test/group`);
await expect(browser).toHaveUrl(expect.stringContaining('athenz'));

await $(
`.//*[local-name()="svg" and @id="delete-group-icon-${reviewExtendTest}"]`
).click();
await $('button*=Delete').click();
} else if (currentTest === TEST_NAME_GROUP_DOMAIN_FILTER) {
// delete group created in previous test
await browser.newUser();
await browser.url(`/domain/athenz.dev.functional-test/group`);
await expect(browser).toHaveUrl(expect.stringContaining('athenz'));

await $(
`.//*[local-name()="svg" and @id="delete-group-icon-${domainFilterTest}"]`
).click();
await $('button*=Delete').click();
}

// to reset currentTest after running cleanup
currentTest = '';
});
});
160 changes: 80 additions & 80 deletions ui/src/__tests__/spec/tests/roles.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const TEST_NAME_ADD_ROLE_MEMBER_INPUT_PRESERVES_CONTENTS_ON_BLUR =
'member dropdown when creating a role and adding to existing role - should preserve input on blur, make input bold when selected in dropdown, reject unselected input';
const TEST_NAME_ROLE_REVIEW_EXTEND_DISABLED =
'Role Review - Extend radio button should be enabled only when Expiry/Review (Days) are set in settings';
const TEST_NAME_DOMAIN_FILTER =
'Domain Filter - only principals matching specific domain(s) can be added to a role';

describe('role screen tests', () => {
let currentTest;
Expand Down Expand Up @@ -492,74 +494,8 @@ describe('role screen tests', () => {
await expect(extendRadio).toBeEnabled();
});

afterEach(async () => {
if (currentTest === TEST_NAME_HISTORY_VISIBLE_AFTER_PAGE_REFRESH) {
// open browser
await browser.newUser();
await browser.url(`/`);
// select domain
let domain = 'athenz.dev.functional-test';
let testDomain = await $(`a*=${domain}`);
await testDomain.click();

// delete the role used in the test
let buttonDeleteRole = await $(
'.//*[local-name()="svg" and @id="history-test-role-delete-role-button"]'
).getElement();
await buttonDeleteRole.click();
let modalDeleteButton = await $('button*=Delete');
await modalDeleteButton.click();
} else if (
currentTest ===
TEST_NAME_DELEGATED_ROLE_ADDITIONAL_SETTINGS_ARE_DISABLED
) {
// open browser
await browser.newUser();
await browser.url(`/`);
// select domain
let domain = 'athenz.dev.functional-test';
let testDomain = await $(`a*=${domain}`);
await browser.waitUntil(async () => await testDomain.isClickable());
await testDomain.click();

// delete the delegate role used in the test
// find row with 'delegated-role' in name and click delete on svg
let buttonDeleteDelegatedRole = await $(
'.//*[local-name()="svg" and @id="delegated-role-delete-role-button"]'
).getElement();
await buttonDeleteDelegatedRole.click();
let modalDeleteButton = await $('button*=Delete');
await modalDeleteButton.click();
} else if (
currentTest ===
TEST_NAME_ADD_ROLE_MEMBER_INPUT_PRESERVES_CONTENTS_ON_BLUR
) {
// delete role created during test
await browser.newUser();
await browser.url(`/domain/athenz.dev.functional-test/role`);
await expect(browser).toHaveUrl(expect.stringContaining('athenz'));

await $(
`.//*[local-name()="svg" and @id="${dropdownTestRoleName}-delete-role-button"]`
).click();
await $('button*=Delete').click();
} else if (currentTest === TEST_NAME_ROLE_REVIEW_EXTEND_DISABLED) {
// delete role created during test
await browser.newUser();
await browser.url(`/domain/athenz.dev.functional-test/role`);
await expect(browser).toHaveUrl(expect.stringContaining('athenz'));

await $(
`.//*[local-name()="svg" and @id="${reviewExtendTest}-delete-role-button"]`
).click();
await $('button*=Delete').click();
}

// reset current test
currentTest = '';
});

it('Domain Filter - only principals matching specific domain(s) can be added to a role', async () => {
it(TEST_NAME_DOMAIN_FILTER, async () => {
currentTest = TEST_NAME_DOMAIN_FILTER;
// open browser
await browser.newUser();
await browser.url(`/domain/athenz.dev.functional-test/role`);
Expand Down Expand Up @@ -603,7 +539,7 @@ describe('role screen tests', () => {
let memberRow = await $(`tr[data-wdio='${user}-member-row']`).$(
`td*=${user}`
);
await expect(memberRow).toHaveTextContaining(user);
await expect(memberRow).toHaveText(expect.stringContaining(user));

// check that domain filter applies to an existing role
// let's reuse the role created above
Expand Down Expand Up @@ -644,19 +580,83 @@ describe('role screen tests', () => {
memberRow = await $(`tr[data-wdio='${unix}-member-row']`).$(
`td*=${unix}`
);
await expect(memberRow).toHaveTextContaining(unix);
await expect(memberRow).toHaveText(expect.stringContaining(unix));
});

// delete role created in previous test
after(async () => {
// delete role created in previous test
await browser.newUser();
await browser.url(`/domain/athenz.dev.functional-test/role`);
await expect(browser).toHaveUrlContaining('athenz');
afterEach(async () => {
if (currentTest === TEST_NAME_HISTORY_VISIBLE_AFTER_PAGE_REFRESH) {
// open browser
await browser.newUser();
await browser.url(`/`);
// select domain
let domain = 'athenz.dev.functional-test';
let testDomain = await $(`a*=${domain}`);
await testDomain.click();

await $(
`.//*[local-name()="svg" and @id="${domainFilterTest}-delete-role-button"]`
).click();
await $('button*=Delete').click();
// delete the role used in the test
let buttonDeleteRole = await $(
'.//*[local-name()="svg" and @id="history-test-role-delete-role-button"]'
).getElement();
await buttonDeleteRole.click();
let modalDeleteButton = await $('button*=Delete');
await modalDeleteButton.click();
} else if (
currentTest ===
TEST_NAME_DELEGATED_ROLE_ADDITIONAL_SETTINGS_ARE_DISABLED
) {
// open browser
await browser.newUser();
await browser.url(`/`);
// select domain
let domain = 'athenz.dev.functional-test';
let testDomain = await $(`a*=${domain}`);
await browser.waitUntil(async () => await testDomain.isClickable());
await testDomain.click();

// delete the delegate role used in the test
// find row with 'delegated-role' in name and click delete on svg
let buttonDeleteDelegatedRole = await $(
'.//*[local-name()="svg" and @id="delegated-role-delete-role-button"]'
).getElement();
await buttonDeleteDelegatedRole.click();
let modalDeleteButton = await $('button*=Delete');
await modalDeleteButton.click();
} else if (
currentTest ===
TEST_NAME_ADD_ROLE_MEMBER_INPUT_PRESERVES_CONTENTS_ON_BLUR
) {
// delete role created during test
await browser.newUser();
await browser.url(`/domain/athenz.dev.functional-test/role`);
await expect(browser).toHaveUrl(expect.stringContaining('athenz'));

await $(
`.//*[local-name()="svg" and @id="${dropdownTestRoleName}-delete-role-button"]`
).click();
await $('button*=Delete').click();
} else if (currentTest === TEST_NAME_ROLE_REVIEW_EXTEND_DISABLED) {
// delete role created during test
await browser.newUser();
await browser.url(`/domain/athenz.dev.functional-test/role`);
await expect(browser).toHaveUrl(expect.stringContaining('athenz'));

await $(
`.//*[local-name()="svg" and @id="${reviewExtendTest}-delete-role-button"]`
).click();
await $('button*=Delete').click();
} else if (currentTest === TEST_NAME_DOMAIN_FILTER) {
await browser.newUser();
await browser.url(`/domain/athenz.dev.functional-test/role`);
await expect(browser).toHaveUrl(expect.stringContaining('athenz'));

let deleteSvg = await $(
`.//*[local-name()="svg" and @id="${domainFilterTest}-delete-role-button"]`
);
await deleteSvg.click();
await $('button*=Delete').click();
}

// reset current test
currentTest = '';
});
});

0 comments on commit 87c5565

Please sign in to comment.