Skip to content

Commit

Permalink
Add: Form manager tests (#2537)
Browse files Browse the repository at this point in the history
* Update reporters

* Update: menu manager locator reference

* Add: form manager tests

* Add: get admin settings api tests

* Add: custom field tests

* Remove: unused codes
  • Loading branch information
shashwatahalder01 authored Jan 27, 2025
1 parent e97ff28 commit ddf6850
Show file tree
Hide file tree
Showing 15 changed files with 1,429 additions and 51 deletions.
11 changes: 10 additions & 1 deletion tests/pw/pages/basePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,14 @@ export class BasePage {
}
}

// click if enabled
async clickIfEnabled(selector: string): Promise<void> {
const isEnabled = await this.isEnabled(selector);
if (isEnabled) {
await this.click(selector);
}
}

// click and wait for response if visible
async clickAndWaitForResponseIfVisible(subUrl: string, selector: string): Promise<void> {
const isVisible = await this.isVisible(selector);
Expand Down Expand Up @@ -723,7 +731,8 @@ export class BasePage {

// clear input field and type
async clearAndTypeByPage(selector: string, text: string): Promise<void> {
await this.clearInputFieldByMultipleClick(selector);
await this.clearInputField(selector);
// await this.clearInputFieldByMultipleClick(selector);
await this.type(selector, text);
}

Expand Down
66 changes: 32 additions & 34 deletions tests/pw/pages/menuManagerPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { data } from '@utils/testData';

// selectors
const settingsAdmin = selector.admin.dokan.settings;
const menuManager = selector.admin.dokan.settings.menuManager;
const vendorDashboard = selector.vendor.vDashboard;

export class MenuManagerPage extends BasePage {
Expand All @@ -18,10 +19,7 @@ export class MenuManagerPage extends BasePage {
await this.click(settingsAdmin.menus.menuManager);
}

// save settings
async saveSettings() {
await this.toContainText(settingsAdmin.dokanUpdateSuccessMessage, 'Setting has been saved successfully.');
}


// update menu status
async updateMenuStatus(menu: string, action: string, menuLink: string) {
Expand All @@ -30,25 +28,25 @@ export class MenuManagerPage extends BasePage {

switch (action) {
case 'activate':
await this.enableSwitcher(settingsAdmin.menuManager.menuSwitcher(menu));
await this.enableSwitcher(menuManager.menuSwitcher(menu));
await this.clickAndWaitForResponseAndLoadStateUntilNetworkIdle(data.subUrls.ajax, settingsAdmin.saveChanges);
await this.toHaveBackgroundColor(settingsAdmin.menuManager.menuSwitcher(menu) + '//span', 'rgb(0, 144, 255)');
await this.toHaveBackgroundColor(menuManager.menuSwitcher(menu) + '//span', 'rgb(0, 144, 255)');
//assertion
await this.goto(data.subUrls.frontend.vDashboard.dashboard);
await this.toBeVisible((vendorDashboard.menus.primary as any)[menuLink]);
await this.goto((data.subUrls.frontend.vDashboard as any)[menuLink]);
await this.notToBeVisible(settingsAdmin.menuManager.noPermissionNotice);
await this.notToBeVisible(menuManager.noPermissionNotice);
break;

case 'deactivate':
await this.disableSwitcher(settingsAdmin.menuManager.menuSwitcher(menu));
await this.disableSwitcher(menuManager.menuSwitcher(menu));
await this.clickAndWaitForResponseAndLoadStateUntilNetworkIdle(data.subUrls.ajax, settingsAdmin.saveChanges);
await this.toHaveBackgroundColor(settingsAdmin.menuManager.menuSwitcher(menu) + '//span', 'rgb(215, 218, 221)');
await this.toHaveBackgroundColor(menuManager.menuSwitcher(menu) + '//span', 'rgb(215, 218, 221)');
//assertion
await this.goto(data.subUrls.frontend.vDashboard.dashboard);
await this.notToBeVisible((vendorDashboard.menus.primary as any)[menuLink]);
await this.goto((data.subUrls.frontend.vDashboard as any)[menuLink]);
await this.toBeVisible(settingsAdmin.menuManager.noPermissionNotice);
await this.toBeVisible(menuManager.noPermissionNotice);
break;

default:
Expand All @@ -61,11 +59,11 @@ export class MenuManagerPage extends BasePage {
await this.goToMenuManagerSettings();

//rename
await this.click(settingsAdmin.menuManager.menuEdit(currentMenu));
await this.clearAndType(settingsAdmin.menuManager.menuNameInput, newMenu);
await this.click(settingsAdmin.menuManager.menuNameConfirm);
await this.click(menuManager.menuEdit(currentMenu));
await this.clearAndType(menuManager.menuNameInput, newMenu);
await this.click(menuManager.menuNameConfirm);
await this.clickAndWaitForResponseAndLoadState(data.subUrls.ajax, settingsAdmin.saveChanges);
await this.toBeVisible(settingsAdmin.menuManager.menuEdit(newMenu));
await this.toBeVisible(menuManager.menuEdit(newMenu));

await this.goto(data.subUrls.frontend.vDashboard.dashboard);
await this.toBeVisible(vendorDashboard.menus.menuByText(newMenu));
Expand All @@ -75,41 +73,41 @@ export class MenuManagerPage extends BasePage {
await this.goToMenuManagerSettings();

//rename
await this.click(settingsAdmin.menuManager.menuEdit(currentMenu));
await this.clearAndType(settingsAdmin.menuManager.menuNameInput, newMenu);
await this.toHaveAttribute(settingsAdmin.menuManager.menuNameInput, 'maxlength', '45');
await this.click(settingsAdmin.menuManager.menuNameConfirm);
// await this.clickAndWaitForResponseAndLoadState(data.subUrls.ajax, settingsAdmin.menuManager.menuManagerSaveChanges);
await this.toBeVisible(settingsAdmin.menuManager.menuEdit(newMenu.substring(0, 45)));
await this.notToBeVisible(settingsAdmin.menuManager.menuEdit(newMenu));
await this.click(menuManager.menuEdit(currentMenu));
await this.clearAndType(menuManager.menuNameInput, newMenu);
await this.toHaveAttribute(menuManager.menuNameInput, 'maxlength', '45');
await this.click(menuManager.menuNameConfirm);
// await this.clickAndWaitForResponseAndLoadState(data.subUrls.ajax, menuManager.menuManagerSaveChanges);
await this.toBeVisible(menuManager.menuEdit(newMenu.substring(0, 45)));
await this.notToBeVisible(menuManager.menuEdit(newMenu));
}

async cantRenameMenu(menu: string) {
await this.goToMenuManagerSettings();
await this.disableSwitcher(settingsAdmin.menuManager.menuSwitcher(menu));
await this.notToBeVisible(settingsAdmin.menuManager.menuEdit(menu));
await this.disableSwitcher(menuManager.menuSwitcher(menu));
await this.notToBeVisible(menuManager.menuEdit(menu));
}

// dashboard cant be altered
async cantAlterMenu(menu: string, isSubmenu?: boolean) {
await this.goToMenuManagerSettings();
if (isSubmenu) await this.click(settingsAdmin.menuManager.settingsSubMenu);
if (isSubmenu) await this.click(menuManager.settingsSubMenu);

await this.hasClass(settingsAdmin.menuManager.menuGrabber(menu), 'not-sortable');
await this.notToBeVisible(settingsAdmin.menuManager.menuSwitcher(menu));
await this.hasClass(menuManager.menuGrabber(menu), 'not-sortable');
await this.notToBeVisible(menuManager.menuSwitcher(menu));
}

// reorderMenu
async reorderMenu(source: string, target: string) {
await this.goToMenuManagerSettings();
const initialSourceIndex = await this.getLocatorIndex(settingsAdmin.menuManager.menuParent, settingsAdmin.menuManager.menuGrabber(source));
const initialTargetIndex = await this.getLocatorIndex(settingsAdmin.menuManager.menuParent, settingsAdmin.menuManager.menuGrabber(target));
const initialSourceIndex = await this.getLocatorIndex(menuManager.menuParent, menuManager.menuGrabber(source));
const initialTargetIndex = await this.getLocatorIndex(menuManager.menuParent, menuManager.menuGrabber(target));

await this.dragToTargetLocator(settingsAdmin.menuManager.menuGrabber(source), settingsAdmin.menuManager.menuGrabber(target));
await this.dragToTargetLocator(menuManager.menuGrabber(source), menuManager.menuGrabber(target));
await this.clickAndWaitForResponseAndLoadState(data.subUrls.ajax, settingsAdmin.saveChanges);

const newSourceIndex = await this.getLocatorIndex(settingsAdmin.menuManager.menuParent, settingsAdmin.menuManager.menuGrabber(source));
const newTargetIndex = await this.getLocatorIndex(settingsAdmin.menuManager.menuParent, settingsAdmin.menuManager.menuGrabber(target));
const newSourceIndex = await this.getLocatorIndex(menuManager.menuParent, menuManager.menuGrabber(source));
const newTargetIndex = await this.getLocatorIndex(menuManager.menuParent, menuManager.menuGrabber(target));

expect(newSourceIndex).toEqual(initialTargetIndex);
expect(newTargetIndex).toEqual(initialSourceIndex);
Expand All @@ -127,10 +125,10 @@ export class MenuManagerPage extends BasePage {
await this.goToMenuManagerSettings();

// reset
await this.click(settingsAdmin.menuManager.resetAll);
await this.click(settingsAdmin.menuManager.confirmReset);
await this.click(menuManager.resetAll);
await this.click(menuManager.confirmReset);
await this.clickAndWaitForResponseAndLoadState(data.subUrls.ajax, settingsAdmin.saveChanges);

await this.toHaveBackgroundColor(settingsAdmin.menuManager.menuSwitcher(menu) + '//span', 'rgb(0, 144, 255)');
await this.toHaveBackgroundColor(menuManager.menuSwitcher(menu) + '//span', 'rgb(0, 144, 255)');
}
}
171 changes: 171 additions & 0 deletions tests/pw/pages/productFormManagerPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import { Page } from '@playwright/test';
import { AdminPage } from '@pages/adminPage';
import { selector } from '@pages/selectors';
import { data } from '@utils/testData';
import { block, field } from '@utils/interfaces';
// selectors
const settingsAdmin = selector.admin.dokan.settings;
const formManagerAdmin = selector.admin.dokan.settings.productFormManager;

export class ProductFormManager extends AdminPage {
constructor(page: Page) {
super(page);
}

// navigation
async goToProductFormManagerSettings(force = false) {
if (force) {
await this.reload();
}
await this.goIfNotThere(data.subUrls.backend.dokan.settings);
await this.click(settingsAdmin.menus.productFormManager);
}

// save settings
async saveSettings() {
await this.clickAndWaitForResponseAndLoadState(data.subUrls.ajax, settingsAdmin.saveChanges);
await this.toContainText(settingsAdmin.dokanUpdateSuccessMessage, 'Setting has been saved successfully.');
}

// enable product form manager module
async enableProductFormManagerModule() {
// dokan settings
await this.goto(data.subUrls.backend.dokan.settings);
await this.toBeVisible(selector.admin.dokan.settings.menus.productFormManager);
}

// disable product form manager module
async disableProductFormManagerModule() {
// dokan settings
await this.goto(data.subUrls.backend.dokan.settings, { waitUntil: 'domcontentloaded' }, true);
await this.notToBeVisible(selector.admin.dokan.settings.menus.productFormManager);
}

// reset product form manager settings
async resetProductFormManagerSettings(blockLabel: string) {
await this.goToProductFormManagerSettings(true);
await this.click(formManagerAdmin.resetAll);
await this.saveSettings();
await this.notToBeVisible(formManagerAdmin.blockSection(blockLabel));
}

// admin can add custom block
async addCustomBlock(block: block, edit = false) {
await this.goToProductFormManagerSettings();
if (!edit) {
await this.click(formManagerAdmin.createCustomBlock);
}
// collapse field if expanded
await this.clickIfVisible(formManagerAdmin.blockContents.cancel(block.currentLabel));

await this.click(formManagerAdmin.editBlock(block.currentLabel));
await this.clearAndType(formManagerAdmin.blockContents.label(block.currentLabel), block.label);
await this.clearAndType(formManagerAdmin.blockContents.description(block.currentLabel), block.description);
await this.click(formManagerAdmin.blockContents.specificProductTypeDropdown(block.currentLabel));
await this.click(formManagerAdmin.blockContents.productType(block.productType));
await this.toBeVisible(formManagerAdmin.blockContents.selectedProductType(block.currentLabel, block.productType));

await this.click(formManagerAdmin.blockContents.specificProductCategoryDropdown(block.currentLabel));
await this.clearAndType(formManagerAdmin.blockContents.inputProductCategory(block.currentLabel), block.productCategory);
await this.click(formManagerAdmin.blockContents.searchedResult(block.currentLabel));
await this.toBeVisible(formManagerAdmin.blockContents.selectedProductCategory(block.currentLabel, block.productCategory));
await this.click(formManagerAdmin.blockContents.done(block.currentLabel));
await this.saveSettings();

await this.toBeVisible(formManagerAdmin.blockSection(block.label));
await this.click(formManagerAdmin.editBlock(block.label));
await this.toHaveValue(formManagerAdmin.blockContents.label(block.label), block.label);
await this.toHaveValue(formManagerAdmin.blockContents.description(block.label), block.description);
await this.toBeVisible(formManagerAdmin.blockContents.selectedProductType(block.label, block.productType));
await this.toBeVisible(formManagerAdmin.blockContents.selectedProductCategory(block.label, block.productCategory));

return block.label;
}

// admin can delete custom block
async deleteCustomBlock(blockLabel: string) {
await this.goToProductFormManagerSettings();
await this.click(formManagerAdmin.deleteBlock(blockLabel));
await this.click(formManagerAdmin.confirmRemove);
await this.saveSettings();
await this.notToBeVisible(formManagerAdmin.blockSection(blockLabel));
}

// admin can add custom field
async toggleFieldActiveStatus(field: field, status: boolean) {
await this.goToProductFormManagerSettings();

if (status == true) {
await this.enableSwitcher(formManagerAdmin.enableField(field.block, field.currentLabel));
} else {
await this.disableSwitcher(formManagerAdmin.enableField(field.block, field.currentLabel));
}

await this.saveSettings();
if (status == true) {
await this.toHaveBackgroundColor(formManagerAdmin.enableField(field.block, field.currentLabel) + '//span', 'rgb(33, 150, 243)');
} else {
await this.toHaveBackgroundColor(formManagerAdmin.enableField(field.block, field.currentLabel) + '//span', 'rgb(204, 204, 204)');
}
}

// admin can add custom field
async toggleFieldRequiredStatus(field: field, status: boolean) {
await this.goToProductFormManagerSettings();

if (status == true) {
await this.enableSwitcher(formManagerAdmin.requireField(field.block, field.currentLabel));
} else {
await this.disableSwitcher(formManagerAdmin.requireField(field.block, field.currentLabel));
}

await this.saveSettings();
if (status == true) {
await this.toHaveBackgroundColor(formManagerAdmin.requireField(field.block, field.currentLabel) + '//span', 'rgb(33, 150, 243)');
} else {
await this.toHaveBackgroundColor(formManagerAdmin.requireField(field.block, field.currentLabel) + '//span', 'rgb(204, 204, 204)');
}
}

// admin can add custom field
async addCustomField(field: field, edit = false) {
await this.goToProductFormManagerSettings();
if (!edit) {
await this.click(formManagerAdmin.addField(field.block));
}
// collapse field if expanded
await this.clickIfVisible(formManagerAdmin.fieldContents.cancel(field.block, field.currentLabel));

await this.click(formManagerAdmin.editField(field.block, field.currentLabel));
await this.click(formManagerAdmin.editCustomField);
await this.clearAndType(formManagerAdmin.fieldContents.label(field.block, field.currentLabel), field.label);
await this.selectByValue(formManagerAdmin.fieldContents.type(field.block, field.currentLabel), field.type);
await this.clearAndType(formManagerAdmin.fieldContents.placeholder(field.block, field.currentLabel), field.placeholder);
await this.clearAndType(formManagerAdmin.fieldContents.helpContent(field.block, field.currentLabel), field.helpContent);
await this.click(formManagerAdmin.fieldContents.done(field.block, field.currentLabel));
await this.saveSettings();

await this.toBeVisible(formManagerAdmin.fieldSection(field.block, field.label));
await this.click(formManagerAdmin.editField(field.block, field.label));
await this.click(formManagerAdmin.editCustomField);
await this.toHaveValue(formManagerAdmin.fieldContents.label(field.block, field.label), field.label);
await this.toHaveSelectedValue(formManagerAdmin.fieldContents.type(field.block, field.label), field.type);
await this.toHaveValue(formManagerAdmin.fieldContents.placeholder(field.block, field.label), field.placeholder);
await this.toHaveValue(formManagerAdmin.fieldContents.helpContent(field.block, field.label), field.helpContent);

return field.label;
}

// admin can delete custom field
async deleteCustomField(field: { block: string; label: any }) {
await this.goToProductFormManagerSettings();
// collapse field if expanded
await this.clickIfVisible(formManagerAdmin.fieldContents.cancel(field.block, field.label));

await this.click(formManagerAdmin.editField(field.block, field.label));
await this.click(formManagerAdmin.deleteCustomField);
await this.click(formManagerAdmin.confirmRemove);
await this.saveSettings();
await this.notToBeVisible(formManagerAdmin.fieldSection(field.block, field.label));
}
}
Loading

0 comments on commit ddf6850

Please sign in to comment.