Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor functional test to use conditional afterEach #2813

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
271 changes: 146 additions & 125 deletions ui/src/__tests__/spec/tests/domain.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@
* limitations under the License.
*/

const TEST_ADD_BUSINESS_SERVICE_INPUT_PRESERVES_CONTENTS_ON_BLUR =
'modal to add business service - should preserve input on blur, make input bold when selected in dropdown, reject unselected input, allow submission of empty input';
const TEST_MANAGE_DOMAINS_CHANGE_BUSINESS_SERVICE_INPUT_PRESERVES_CONTENTS_ON_BLUR =
'Manage Domains - modal to change add business service - should preserve input on blur, make input bold when selected in dropdown, reject unselected input';

describe('Domain', () => {
let currentTest;

it('should successfully add domain point of contact and security poc', async () => {
await browser.newUser();
await browser.url(`/`);
Expand Down Expand Up @@ -51,7 +58,9 @@ describe('Domain', () => {
await expect(securityPocAnchor).toHaveTextContaining('Chandu Raman');
});

it('modal to add business service - should preserve input on blur, make input bold when selected in dropdown, reject unselected input, allow submission of empty input', async () => {
it(TEST_ADD_BUSINESS_SERVICE_INPUT_PRESERVES_CONTENTS_ON_BLUR, async () => {
currentTest =
TEST_ADD_BUSINESS_SERVICE_INPUT_PRESERVES_CONTENTS_ON_BLUR;
await browser.newUser();
await browser.url(`/domain/athenz.dev.functional-test/role`);
await expect(browser).toHaveUrlContaining('athenz');
Expand Down Expand Up @@ -133,132 +142,94 @@ describe('Domain', () => {
await expect(addBusinessService).toHaveTextContaining(
'PolicyEnforcementService.GLB'
);

// click add business service
await browser.waitUntil(
async () => await addBusinessService.isClickable()
);
await addBusinessService.click();

// clear current input
clearInput = await $(
`.//*[local-name()="svg" and @data-wdio="clear-input"]`
);
await browser.waitUntil(async () => await clearInput.isClickable());
await clearInput.click();

// submit empty input
submitButton = await $('button*=Submit');
await submitButton.click();

// business service for the domain should be empty
await browser.waitUntil(
async () => await addBusinessService.isClickable()
);
expect(addBusinessService).toHaveTextContaining('add');
});

it('Manage Domains - modal to change add business service - should preserve input on blur, make input bold when selected in dropdown, reject unselected input', async () => {
await browser.newUser();

// open athenz manage domains page
await browser.url(`/domain/manage`);
await expect(browser).toHaveUrlContaining('athenz');

// click add business service
let addBusinessService = await $(
'a[data-testid="business-service-athenz.dev.functional-test"]'
);
await browser.waitUntil(
async () => await addBusinessService.isClickable()
);
await addBusinessService.click();

await browser.pause(4000); // wait to make sure dropdown options are loaded

// add random text
let bsInput = await $('input[name="business-service-drop"]');
await bsInput.addValue('nonexistent.service');

// blur
await browser.keys('Tab');

// input did not change
expect(await bsInput.getValue()).toBe('nonexistent.service');

// input is not bold
let fontWeight = await bsInput.getCSSProperty('font-weight').value;
expect(fontWeight).toBeUndefined();

// submit (item in dropdown is not selected)
let submitButton = await $('button*=Submit');
await submitButton.click();

// verify error message
let errorMessage = await $('div[data-testid="error-message"]');
expect(await errorMessage.getText()).toBe(
'Business Service must be selected in the dropdown'
);

let clearInput = await $(
`.//*[local-name()="svg" and @data-wdio="clear-input"]`
);
await clearInput.click();

let checkbox = await $('input[id="checkbox-show-all-bservices"]');
await browser.execute(function (checkboxElem) {
checkboxElem.click();
}, checkbox);

// make dropdown visible
await bsInput.click();
// type valid input and select item in dropdown
await bsInput.addValue('PolicyEnforcementService.GLB');
let dropdownOption = await $('div*=PolicyEnforcementService.GLB');
await dropdownOption.click();

// verify input contains pes service
expect(await bsInput.getValue()).toBe('PolicyEnforcementService.GLB');

// verify input is in bold
fontWeight = await bsInput.getCSSProperty('font-weight');
expect(fontWeight.value === 700).toBe(true);

// submit
submitButton = await $('button*=Submit');
await submitButton.click();

// business service can be seen added to domain
addBusinessService = await $(
'a[data-testid="business-service-athenz.dev.functional-test"]'
);
await expect(addBusinessService).toHaveTextContaining(
'PolicyEnforcementService.GLB'
);

// click add business service
await browser.waitUntil(
async () => await addBusinessService.isClickable()
);
await addBusinessService.click();

// clear current input
clearInput = await $(
`.//*[local-name()="svg" and @data-wdio="clear-input"]`
);
await browser.waitUntil(async () => await clearInput.isClickable());
await clearInput.click();

// submit empty input
submitButton = await $('button*=Submit');
await submitButton.click();

// business service for the domain should be empty
await browser.waitUntil(
async () => await addBusinessService.isClickable()
);
expect(addBusinessService).toHaveTextContaining('add');
});
it(
TEST_MANAGE_DOMAINS_CHANGE_BUSINESS_SERVICE_INPUT_PRESERVES_CONTENTS_ON_BLUR,
async () => {
currentTest =
TEST_MANAGE_DOMAINS_CHANGE_BUSINESS_SERVICE_INPUT_PRESERVES_CONTENTS_ON_BLUR;

await browser.newUser();

// open athenz manage domains page
await browser.url(`/domain/manage`);
await expect(browser).toHaveUrlContaining('athenz');

// click add business service
let addBusinessService = await $(
'a[data-testid="business-service-athenz.dev.functional-test"]'
);
await browser.waitUntil(
async () => await addBusinessService.isClickable()
);
await addBusinessService.click();

await browser.pause(4000); // wait to make sure dropdown options are loaded

// add random text
let bsInput = await $('input[name="business-service-drop"]');
await bsInput.addValue('nonexistent.service');

// blur
await browser.keys('Tab');

// input did not change
expect(await bsInput.getValue()).toBe('nonexistent.service');

// input is not bold
let fontWeight = await bsInput.getCSSProperty('font-weight').value;
expect(fontWeight).toBeUndefined();

// submit (item in dropdown is not selected)
let submitButton = await $('button*=Submit');
await submitButton.click();

// verify error message
let errorMessage = await $('div[data-testid="error-message"]');
expect(await errorMessage.getText()).toBe(
'Business Service must be selected in the dropdown'
);

let clearInput = await $(
`.//*[local-name()="svg" and @data-wdio="clear-input"]`
);
await clearInput.click();

let checkbox = await $('input[id="checkbox-show-all-bservices"]');
await browser.execute(function (checkboxElem) {
checkboxElem.click();
}, checkbox);

// make dropdown visible
await bsInput.click();
// type valid input and select item in dropdown
await bsInput.addValue('PolicyEnforcementService.GLB');
let dropdownOption = await $('div*=PolicyEnforcementService.GLB');
await dropdownOption.click();

// verify input contains pes service
expect(await bsInput.getValue()).toBe(
'PolicyEnforcementService.GLB'
);

// verify input is in bold
fontWeight = await bsInput.getCSSProperty('font-weight');
expect(fontWeight.value === 700).toBe(true);

// submit
submitButton = await $('button*=Submit');
await submitButton.click();

// business service can be seen added to domain
addBusinessService = await $(
'a[data-testid="business-service-athenz.dev.functional-test"]'
);
await expect(addBusinessService).toHaveTextContaining(
'PolicyEnforcementService.GLB'
);
}
);

it('Domain History - modal to change add business service - should preserve input on blur, make input bold when selected in dropdown', async () => {
await browser.newUser();
Expand Down Expand Up @@ -342,4 +313,54 @@ describe('Domain', () => {
fontWeight = await input.getCSSProperty('font-weight');
expect(fontWeight.value === 700).toBe(true);
});

afterEach(async () => {
// runs after each test and checks what currentTest value was set and executes appropriate cleanup logic if defined
if (
currentTest ===
TEST_ADD_BUSINESS_SERVICE_INPUT_PRESERVES_CONTENTS_ON_BLUR ||
currentTest ===
TEST_MANAGE_DOMAINS_CHANGE_BUSINESS_SERVICE_INPUT_PRESERVES_CONTENTS_ON_BLUR
) {
// remove business service name that was added during test
await browser.newUser();
await browser.url(`/domain/athenz.dev.functional-test/role`);

// expand domain details
let expand = await $(
`.//*[local-name()="svg" and @data-wdio="domain-details-expand-icon"]`
);
await browser.waitUntil(async () => await expand.isClickable());
await expand.click();

// click add business service
let addBusinessService = await $(
'a[data-testid="add-business-service"]'
);
await browser.waitUntil(
async () => await addBusinessService.isClickable()
);
await addBusinessService.click();

let bsInput = await $('input[name="business-service-drop"]');
let inputText = await bsInput.getValue();
console.log(inputText);
// if business service is present - clear and submit
if (inputText !== '') {
// clear current input
let clearInput = await $(
`.//*[local-name()="svg" and @data-wdio="clear-input"]`
);
await browser.waitUntil(
async () => await clearInput.isClickable()
);
await clearInput.click();

let submitButton = await $('button*=Submit');
await submitButton.click();
}
}
// reset current test name
currentTest = '';
});
});
Loading
Loading