Skip to content

Commit

Permalink
Cleanup inputs and close modal windows tests (#1165)
Browse files Browse the repository at this point in the history
* Added new test-cases with cleanup inputs and close modal windows
Co-authored-by: Ilgam Shakirov <[email protected]>
  • Loading branch information
makonakro authored Dec 20, 2022
1 parent 8030b84 commit 284318d
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 9 deletions.
37 changes: 32 additions & 5 deletions tests/features/owners/add-owner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ import { expect } from '@playwright/test';
import { test } from '../../config/test-base';

test.describe('Owners', () => {
test('Add new Owner', async ({ workerId, steps: { pages }, page }) => {
const ownerName = `Test_ownerName + ${workerId}`;

await test.step('I open Owners page', async () => {
test.beforeEach(async ({ steps: { pages }, page }) => {
await test.step(`I open Owners page`, async () => {
await page.goto('');
await pages.topPanel.clickTab('Management');
await pages.management.owners.click();
});
await test.step("And click on 'Create Owner' button", async () => {
await test.step(`And Click on 'Create owner' button`, async () => {
await pages.owners.createOwner.click();
expect(await pages.modals.addOwner.isOpened()).toBeTruthy();
});
});
/**
* /project/1/test-cases/1
*/
test('Add new Owner', async ({ workerId, steps: { pages }, page }) => {
const ownerName = `Test_ownerName + ${workerId}`;
await test.step(`I fill owner name ${ownerName} and click 'create' button.`, async () => {
await pages.modals.addOwner.ownerNameField.fill(`${ownerName}`);
await pages.modals.addOwner.addNewOwner.click();
Expand All @@ -22,4 +26,27 @@ test.describe('Owners', () => {
expect(await pages.owners.ownersList.isVisible()).toBeTruthy();
});
});
/**
* /project/1/test-cases/2
*/
test(`Cleanup input in popup window Owners`, async ({ workerId, steps: { pages } }) => {
const ownerName = `Test_ownerName + ${workerId}`;
await test.step(`I fill owner name ${ownerName} and click 'create' button.`, async () => {
await pages.modals.addOwner.ownerNameField.fill(`${ownerName}`);
});
await test.step(`I clean the input`, async () => {
await pages.modals.addOwner.ownerNameCleanButton.click();
expect(await pages.modals.addOwner.ownerNameField.innerText()).toEqual('');
expect(await pages.modals.addOwner.addNewOwner.isDisabled()).toBeTruthy();
});
});
/**
* /project/1/test-cases/3
*/
test(`Close the popup window Add owner`, async ({ steps: { pages } }) => {
await test.step(`I close the popup`, async () => {
await pages.modals.addOwner.closeDialog.click();
expect(await pages.modals.addOwner.dialogTitle.isHidden()).toBeTruthy();
});
});
});
12 changes: 12 additions & 0 deletions tests/features/search/search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,17 @@ test.describe('Search by name of data-entity', () => {
expect(await pages.catalog.isAlertVisible()).toBeTruthy();
});
});
/**
* /project/1/test-cases/22
*/
test(`Cleanup the search bar`, async ({ steps: { pages } }) => {
await test.step(`When fill an expression`, async () => {
await pages.catalog.searchBy('ticket');
});
await test.step(`When clean the input`, async () => {
await pages.catalog.cleanSearchBar.click();
expect(await pages.catalog.searchBar.innerText()).toEqual('');
});
});
});
});
51 changes: 51 additions & 0 deletions tests/features/tags/add-tag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,55 @@ test.describe('Tags', () => {
await expect(pages.tags.importantTag(`${tagNamePrefix}_1`)).toBeVisible();
});
});
/**
* /project/1/test-cases/8
*/
test(`Cleanup input in popup window Tags`, async ({ steps: { pages } }) => {
await test.step(`I fill the input`, async () => {
await pages.modals.addTag.fillAllTagName('tag');
});
await test.step(`I cleanup the input`, async () => {
await pages.modals.addTag.tagNameCleanButton.click();
expect(await pages.modals.addTag.tagNameField.innerText()).toEqual('');
expect(await pages.modals.addTag.addNewTag.isDisabled()).toBeTruthy();
});
});
/**
* /project/1/test-cases/11
*/
test(`Close the popup window Create tag`, async ({ steps: { pages } }) => {
await test.step(`I close the popup`, async () => {
await pages.modals.addTag.closeDialog.click();
expect(await pages.modals.addTag.dialogTitle.isHidden()).toBeTruthy();
});
});
/**
* /project/1/test-cases/9
*/
test(`Delete tag in popup window`, async ({ steps: { pages } }) => {
await test.step(`I add one more tag`, async () => {
await pages.modals.addTag.addOneMoreTag.click();
await expect(pages.modals.addTag.tagNameField.locator).toHaveCount(2);
});
await test.step(`I delete one tag`, async () => {
await pages.modals.addTag.deleteTag(1);
await expect(pages.modals.addTag.tagNameField.locator).toHaveCount(1);
});
});
/**
* /project/1/test-cases/10
*/
test(`Delete important tag in popup window`, async ({ steps: { pages } }) => {
await test.step(`Add one more tag`, async () => {
await pages.modals.addTag.addOneMoreTag.click();
await expect(pages.modals.addTag.tagNameField.locator).toHaveCount(2);
});
await test.step(`Click 'important'`, async () => {
await pages.modals.addTag.checkImportant(1);
});
await test.step(`Delete important tag`, async () => {
await pages.modals.addTag.deleteTag(1);
await expect(pages.modals.addTag.tagNameField.locator).toHaveCount(1);
});
});
});
15 changes: 11 additions & 4 deletions tests/ui/elements/custom-element.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { Locator, Page } from '@playwright/test';

export default class CustomElement {
constructor(protected readonly context: Page, customElement: string | Locator) {
this.customElementContext = this.getLocator(customElement);
}

/**
* @returns Returns locator of the matching element
*/
get locator(): Locator {
return this.customElementContext;
}

private customElementContext: Locator;

/**
Expand All @@ -27,10 +38,6 @@ export default class CustomElement {
this.customElementContext = customElement;
}

constructor(protected readonly context: Page, customElement: string | Locator) {
this.customElementContext = this.getLocator(customElement);
}

/**
* Wraps the customElementContext in a Proxy class to dynamically deal with loading status before and after each PW command
*/
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/pages/catalog/catalog.page.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Button from '../../elements/button';
import InputField from '../../elements/input-field';
import List from '../../elements/list';
import TextBox from '../../elements/text-box';
Expand All @@ -7,6 +8,7 @@ const SELECTORS = {
filterWithSelect: filterName => `#select-label-id:has-text('${filterName}') >> ..`,
filterWithInput: filterName => `label:text-is("${filterName}") >> ..`,
searchBar: `[placeholder="Search"]`,
cleanSearchBarButton: `[placeholder="Search"] >> .. >> [title="Clear"]`,
filterList: `[role="listbox"]`,
filterOption: `[role="option"]`,
filterWithInputOption: `[role="presentation"]`,
Expand All @@ -30,6 +32,10 @@ export default class CatalogPage extends BasePage {
return new List(this.page, SELECTORS.resultList, SELECTORS.listItem);
}

get cleanSearchBar() {
return new Button(this.page, SELECTORS.cleanSearchBarButton);
}

async openFilterWithSelect(filterName: string) {
await this.page.locator(SELECTORS.filterWithSelect(filterName)).click();
}
Expand Down
16 changes: 16 additions & 0 deletions tests/ui/pages/modals/add-owner-modal.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import Button from '../../elements/button';
import InputField from '../../elements/input-field';
import TextBox from '../../elements/text-box';
import { Pages } from '../index';
import BaseModal from './base-modal';

const SELECTORS = {
thisDialog: 'div[role="dialog"]',
dialogTitle: 'div[role="dialog"] h2',
ownerName: 'input[name="name"]',
ownerNameCleanButton: 'input[name="name"] >> .. >> [type="button"]',
addOwner: 'button:has-text("Add new owner")',
closeDialogButton: 'div[role="dialog"] h2 >> [type="button"]',
};

export default class AddOwnerModal extends BaseModal {
Expand All @@ -27,4 +31,16 @@ export default class AddOwnerModal extends BaseModal {
get addNewOwner() {
return new Button(this.page, SELECTORS.addOwner);
}

get ownerNameCleanButton() {
return new Button(this.page, SELECTORS.ownerNameCleanButton);
}

get closeDialog() {
return new Button(this.page, SELECTORS.closeDialogButton);
}

get dialogTitle() {
return new TextBox(this.page, SELECTORS.dialogTitle);
}
}
25 changes: 25 additions & 0 deletions tests/ui/pages/modals/add-tag-modal.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
import Button from '../../elements/button';
import InputField from '../../elements/input-field';
import TextBox from '../../elements/text-box';
import { Pages } from '../index';
import BaseModal from './base-modal';

const SELECTORS = {
thisDialog: 'div[role="dialog"]',
dialogTitle: 'div[role="dialog"] h2',
tagName: '[placeholder="Tag Name"]',
tagNameCleanButton: '[placeholder="Tag Name"] >> .. >> [type="button"]',
closeDialogButton: 'div[role="dialog"] h2 >> [type="button"]',
addTag: '[type="submit"]',
importantTag: '[type="checkbox"]',
addOneMoreTag: 'div[role="dialog"] button:has-text("Create tag")',
tagLineRoot: '.infinite-scroll-component',
deleteTagButton: '[type="button"]:has-text("Delete")',
};
export default class AddTagModal extends BaseModal {
constructor(pages: Pages) {
super(pages, SELECTORS.thisDialog);
}

get closeDialog() {
return new Button(this.page, SELECTORS.closeDialogButton);
}

get dialogTitle() {
return new TextBox(this.page, SELECTORS.dialogTitle);
}

get tagNameField() {
return new InputField(this.page, SELECTORS.tagName);
}
Expand All @@ -24,6 +37,14 @@ export default class AddTagModal extends BaseModal {
return new Button(this.page, SELECTORS.addTag);
}

get tagNameCleanButton() {
return new Button(this.page, SELECTORS.tagNameCleanButton);
}

get deleteButton() {
return new Button(this.page, SELECTORS.deleteTagButton);
}

async checkImportant(indexOfCheckbox: number) {
await this.page.locator(SELECTORS.importantTag).nth(indexOfCheckbox).click();
}
Expand All @@ -32,6 +53,10 @@ export default class AddTagModal extends BaseModal {
return new Button(this.page, SELECTORS.addOneMoreTag);
}

async deleteTag(numberOfButton: number) {
await this.modal.locator(SELECTORS.deleteTagButton).nth(numberOfButton).click();
}

async fillAllTagName(name: string) {
const newTags = [];
const inputCount = await this.page.locator(SELECTORS.tagName).count();
Expand Down

0 comments on commit 284318d

Please sign in to comment.