Skip to content

Commit

Permalink
fixed menu-manager tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shashwatahalder01 committed Feb 23, 2024
1 parent 04caf67 commit f788c29
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 26 deletions.
2 changes: 1 addition & 1 deletion tests/pw/pages/basePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ export class BasePage {
await expect(this.page.locator(selector)).toHaveValue(value);
}

// assert element to have attribute
// assert element to have attribute along with attirbute value
async toHaveAttribute(selector: string, attribute: string, value: string) {
await expect(this.page.locator(selector)).toHaveAttribute(attribute, value);
}
Expand Down
19 changes: 17 additions & 2 deletions tests/pw/pages/menuManagerPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ export class MenuManagerPage extends BasePage {

// update menu status
async updateMenuStatus(menu: string, action: string, menuLink: string) {
await this.goIfNotThere(data.subUrls.backend.dokan.settings);
await this.goto(data.subUrls.backend.dokan.settings);
await this.click(settingsAdmin.menus.menuManager);

switch (action) {
case 'activate':
await this.enableSwitcher(settingsAdmin.menuManager.menuSwithcher(menu));
Expand Down Expand Up @@ -64,10 +65,24 @@ export class MenuManagerPage extends BasePage {
await this.toBeVisible(selector.vendor.vDashboard.menus.menuByText(newMenu));
}

async cantRenameMenu(menu: string) {
async cantRenameMenuBeyondLimit(currentMenu: string, newMenu: string) {
await this.goIfNotThere(data.subUrls.backend.dokan.settings);
await this.click(settingsAdmin.menus.menuManager);

//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));
}

async cantRenameMenu(menu: string) {
await this.goIfNotThere(data.subUrls.backend.dokan.settings);
await this.click(settingsAdmin.menus.menuManager);
await this.disableSwitcher(settingsAdmin.menuManager.menuSwithcher(menu));
await this.notToBeVisible(settingsAdmin.menuManager.menuEdit(menu));
}

Expand Down
4 changes: 2 additions & 2 deletions tests/pw/pages/productQAPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ export class ProductQAPage extends BasePage {
await this.toBeVisible(productQAAdmin.questionDetails.goBack);

// question details elements are visible
const { questionInput, saveQuestion, questionText, ...questionDetails } = productQAAdmin.questionDetails.questionDetails; // todo: need to add questiontext
const { questionInput, saveQuestion, ...questionDetails } = productQAAdmin.questionDetails.questionDetails;
await this.multipleElementVisible(questionDetails);

// status elements are visible
const { hiddenStatus, showInProductPage, ...status } = productQAAdmin.questionDetails.status;
await this.multipleElementVisible(status);

// answer elements are visible
const { questionAnswerHtmlBody, editAnswer, ...answer } = productQAAdmin.questionDetails.answer;
const { questionAnswerIframe, questionAnswerHtmlBody, saveAnswer, ...answer } = productQAAdmin.questionDetails.answer;
await this.multipleElementVisible(answer);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/pw/pages/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ export const selector = {
editQuestion: '(//button[normalize-space()="Edit"])[1]',
questionInput: 'textarea#comment.block',
saveQuestion: '(//button[normalize-space()="Save"])[1]',
questionText: 'div.break-words',
questionText: '//div[ contains(@class, "break-words") and not(contains(@class, "prose")) ]',
},

status: {
Expand Down Expand Up @@ -2055,7 +2055,7 @@ export const selector = {
resetAll: 'div.menu-manager-reset-all',
confirmReset: '.swal2-confirm',
cancelReset: '.swal2-cancel',
menuParent:'(//div[@class="tabs-details"]//div)[2]',
menuParent: '(//div[@class="tabs-details"]//div)[2]',
allMenus: 'div.menu_manager_menu_tab div.menu-item',
menuGrabber: (menuName: string) => `//span[text()='${menuName}']/../..`,
menuEdit: (menuName: string) => `//span[text()='${menuName}']/../..//div[@class='action-icon-wrapper edit-icon-wrapper']`,
Expand Down
8 changes: 4 additions & 4 deletions tests/pw/tests/api/productQA.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ test.describe('product questions and answeres api test', () => {
// questions

test('get all product questions @pro', async () => {
const [response, responseBody] = await apiUtils.get(endPoints.getAllProductQuestions, { headers: payloads.vendorAuth });
const [response, responseBody] = await apiUtils.get(endPoints.getAllProductQuestions, { headers: payloads.adminAuth });
expect(response.ok()).toBeTruthy();
expect(responseBody).toBeTruthy();
expect(responseBody).toMatchSchema(schemas.productQaSchema.productQuestionsSchema);
});

test('get single product question @pro', async () => {
const [response, responseBody] = await apiUtils.get(endPoints.getSingleProductQuestion(questionId), { headers: payloads.vendorAuth });
const [response, responseBody] = await apiUtils.get(endPoints.getSingleProductQuestion(questionId), { headers: payloads.adminAuth });
expect(response.ok()).toBeTruthy();
expect(responseBody).toBeTruthy();
expect(responseBody).toMatchSchema(schemas.productQaSchema.productQuestionSchema);
Expand Down Expand Up @@ -87,14 +87,14 @@ test.describe('product questions and answeres api test', () => {
// answers

test('get all product question answers @pro', async () => {
const [response, responseBody] = await apiUtils.get(endPoints.getAllProductQuestionAnswers, { headers: payloads.vendorAuth });
const [response, responseBody] = await apiUtils.get(endPoints.getAllProductQuestionAnswers, { headers: payloads.adminAuth });
expect(response.ok()).toBeTruthy();
expect(responseBody).toBeTruthy();
expect(responseBody).toMatchSchema(schemas.productQaSchema.productQuestionAnswersSchema);
});

test('get single product question answer @pro', async () => {
const [response, responseBody] = await apiUtils.get(endPoints.getSingleProductQuestionAnswer(answerId), { headers: payloads.vendorAuth });
const [response, responseBody] = await apiUtils.get(endPoints.getSingleProductQuestionAnswer(answerId), { headers: payloads.adminAuth });
expect(response.ok()).toBeTruthy();
expect(responseBody).toBeTruthy();
expect(responseBody).toMatchSchema(schemas.productQaSchema.productQuestionAnswerSchema);
Expand Down
20 changes: 12 additions & 8 deletions tests/pw/tests/e2e/menuManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test.describe('Menu Manager test', () => {
test('admin can deactivate menu @pro @a', async () => {
await admin.updateMenuStatus('Analytics', 'deactivate', 'analytics');
//reset
await dbUtils.setDokanSettings(dbData.dokan.optionName.menuManager, dbData.dokan.menuManagerSettings);
// await dbUtils.setDokanSettings(dbData.dokan.optionName.menuManager, dbData.dokan.menuManagerSettings);
});

test('admin can activate menu@pro @a', async () => {
Expand All @@ -36,14 +36,17 @@ test.describe('Menu Manager test', () => {
test('admin can rename menu @pro @a', async () => {
await admin.renameMenu('Request Quotes', 'Quotations');
//reset
await dbUtils.setDokanSettings(dbData.dokan.optionName.menuManager, dbData.dokan.menuManagerSettings);
// await dbUtils.setDokanSettings(dbData.dokan.optionName.menuManager, dbData.dokan.menuManagerSettings);
});

test("admin can't rename disabled menu @pro @a", async () => {
await updateMenuStatusByDB('auction', 'false');
await admin.cantRenameMenu('Auction');
test("admin can't rename menu with more than 45 characters @pro @a", async () => {
await admin.cantRenameMenuBeyondLimit('Subscription', 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz');
});

test("admin can't rename disabled menu @pro @a", async () => {
await admin.cantRenameMenu('Coupons');
});

test('admin can redorder menu @pro @a', async () => {
await admin.reorderMenu('Orders', 'Products');
});
Expand All @@ -54,14 +57,15 @@ test.describe('Menu Manager test', () => {
});

test('admin can reset menu manager settings @pro @a', async () => {
await updateMenuStatusByDB('auction', 'false');
await admin.resetMenuManagerSettings('Auction');
await updateMenuStatusByDB('tools', 'false');
await admin.resetMenuManagerSettings('Tools');
});
});

// update menu switch status
async function updateMenuStatusByDB(key: string, value: string) {
const menuManagerSettings = dbData.dokan.menuManagerSettings;
const menuManagerSettings = JSON.parse(JSON.stringify(dbData.dokan.menuManagerSettings));
menuManagerSettings.dashboard_menu_manager.left_menus[key as keyof typeof menuManagerSettings.dashboard_menu_manager.left_menus].is_switched_on = value;
await dbUtils.setDokanSettings(dbData.dokan.optionName.menuManager, menuManagerSettings);
}

15 changes: 8 additions & 7 deletions tests/pw/tests/e2e/productAddons.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ test.describe('Product addon functionality test', () => {
let categoryName: string;
let apiUtils: ApiUtils;

async function createVendorProductAddon(): Promise<[string, string, string, string]> {
const [, categoryId, categoryName] = await apiUtils.createCategory(payloads.createCategoryRandom(), payloads.adminAuth);
const [, addonId, addonName, addonFieldTitle] = await apiUtils.createProductAddon({ ...payloads.createProductAddons(), restrict_to_categories: [categoryId] }, payloads.adminAuth);
await dbUtils.updateCell(addonId, VENDOR_ID);
return [addonId, addonName, addonFieldTitle, categoryName];
}

test.beforeAll(async ({ browser }) => {
const vendorContext = await browser.newContext(data.auth.vendorAuth);
vPage = await vendorContext.newPage();
Expand Down Expand Up @@ -54,3 +47,11 @@ test.describe('Product addon functionality test', () => {
await vendor.deleteAddon({ ...data.vendor.addon(), name: addonName });
});
});

// create product addon
async function createVendorProductAddon(): Promise<[string, string, string, string]> {
const [, categoryId, categoryName] = await apiUtils.createCategory(payloads.createCategoryRandom(), payloads.adminAuth);
const [, addonId, addonName, addonFieldTitle] = await apiUtils.createProductAddon({ ...payloads.createProductAddons(), restrict_to_categories: [categoryId] }, payloads.adminAuth);
await dbUtils.updateCell(addonId, VENDOR_ID);
return [addonId, addonName, addonFieldTitle, categoryName];
}

0 comments on commit f788c29

Please sign in to comment.