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

Update RFQ tests for new changes #2394

Merged
merged 14 commits into from
Oct 7, 2024
15 changes: 13 additions & 2 deletions tests/pw/pages/basePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ export class BasePage {
}

// goto subPath if not already there
async goIfNotThere(subPath: string, waitUntil: 'load' | 'domcontentloaded' | 'networkidle' | 'commit' = 'domcontentloaded'): Promise<void> {
if (!this.isCurrentUrl(subPath)) {
async goIfNotThere(subPath: string, waitUntil: 'load' | 'domcontentloaded' | 'networkidle' | 'commit' = 'domcontentloaded', force = false): Promise<void> {
const alreadyThere = this.isCurrentUrl(subPath);
if (!alreadyThere) {
const url = this.createUrl(subPath);
// console.log('url: ', url);
await this.toPass(async () => {
Expand All @@ -101,6 +102,9 @@ export class BasePage {
expect(currentUrl).toMatch(subPath);
});
}
if (force) {
await this.reload();
}
}

// goto subPath if about:blank is loaded
Expand Down Expand Up @@ -1614,6 +1618,13 @@ export class BasePage {
await this.toHaveBackgroundColor(selector, color);
}

async forceLinkToSameTab(selector: string): Promise<void> {
// ensure link suppose to open on new tab
await this.toHaveAttribute(selector, 'target', '_blank');
// force link to open on the same tab
await this.setAttributeValue(selector, 'target', '_self');
}

/**
* Custom methods
*/
Expand Down
5 changes: 1 addition & 4 deletions tests/pw/pages/privacyPolicyPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ export class PrivacyPolicyPage extends CustomerPage {
// go to privacy policy
async goToPrivacyPolicy(storeName: string) {
await this.gotoSingleStore(storeName);
// ensure link suppose to open on new tab
await this.toHaveAttribute(singleStoreCustomer.storeContactForm.privacyPolicyLink, 'target', '_blank');
// force link to open on the same tab
await this.setAttributeValue(singleStoreCustomer.storeContactForm.privacyPolicyLink, 'target', '_self');
await this.forceLinkToSameTab(singleStoreCustomer.storeContactForm.privacyPolicyLink);
await this.clickAndWaitForUrl(helpers.stringToRegex('privacy-policy'), singleStoreCustomer.storeContactForm.privacyPolicyLink);
}

Expand Down
194 changes: 135 additions & 59 deletions tests/pw/pages/requestForQuotationsPage.ts

Large diffs are not rendered by default.

116 changes: 77 additions & 39 deletions tests/pw/pages/selectors.ts

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions tests/pw/pages/singleStorePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ export class SingleStorePage extends CustomerPage {
async storeShare(storeName: string, site: string): Promise<void> {
await this.gotoSingleStore(storeName);
await this.click(singleStoreCustomer.storeTabs.share);
// ensure link suppose to open on new tab
await this.toHaveAttribute(singleStoreCustomer.sharePlatForms[site as keyof typeof singleStoreCustomer.sharePlatForms], 'target', '_blank');
// force link to open on the same tab
await this.setAttributeValue(singleStoreCustomer.sharePlatForms[site as keyof typeof singleStoreCustomer.sharePlatForms], 'target', '_self');
await this.forceLinkToSameTab(singleStoreCustomer.sharePlatForms[site as keyof typeof singleStoreCustomer.sharePlatForms]);
await this.clickAndWaitForUrl(new RegExp('.*' + site + '.*'), singleStoreCustomer.sharePlatForms[site as keyof typeof singleStoreCustomer.sharePlatForms]);
}
}
5 changes: 1 addition & 4 deletions tests/pw/pages/vendorPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,7 @@ export class VendorPage extends BasePage {
// visit store
async visitStore(storeName: string) {
await this.goIfNotThere(data.subUrls.frontend.vDashboard.dashboard);
// ensure link suppose to open on new tab
await this.toHaveAttribute(vendorDashboard.menus.primary.visitStore, 'target', '_blank');
// force link to open on the same tab
await this.setAttributeValue(vendorDashboard.menus.primary.visitStore, 'target', '_self');
await this.forceLinkToSameTab(vendorDashboard.menus.primary.visitStore);
await this.click(vendorDashboard.menus.primary.visitStore);
await expect(this.page).toHaveURL(data.subUrls.frontend.vendorDetails(helpers.slugify(storeName)) + '/');
}
Expand Down
12 changes: 2 additions & 10 deletions tests/pw/pages/vendorVerificationsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,7 @@ export class VendorVerificationsPage extends AdminPage {
async viewVerificationRequestDocument(requestId: string): Promise<void> {
await this.goIfNotThere(data.subUrls.backend.dokan.verifications);
await this.reloadIfVisible(verificationsAdmin.filters.reset);

// ensure link suppose to open on new tab
await this.toHaveAttribute(verificationsAdmin.verificationRequestDocument(requestId), 'target', '_blank');
// force link to open on the same tab
await this.setAttributeValue(verificationsAdmin.verificationRequestDocument(requestId), 'target', '_self');
await this.forceLinkToSameTab(verificationsAdmin.verificationRequestDocument(requestId));
const documentLink = (await this.getAttributeValue(verificationsAdmin.verificationRequestDocument(requestId), 'href')) as string;
await this.clickAndWaitForUrl(documentLink, verificationsAdmin.verificationRequestDocument(requestId));
await this.toHaveAttribute('body img', 'src', documentLink);
Expand Down Expand Up @@ -322,11 +318,7 @@ export class VendorVerificationsPage extends AdminPage {
// await this.click(setupWizardVendor.skipTheStepStoreSetup);
await this.click(setupWizardVendor.skipTheStepPaymentSetup);
}

// ensure link suppose to open on new tab
await this.toHaveAttribute(verificationsVendor.verificationRequestDocument(methodName), 'target', '_blank');
// force link to open on the same tab
await this.setAttributeValue(verificationsVendor.verificationRequestDocument(methodName), 'target', '_self');
await this.forceLinkToSameTab(verificationsVendor.verificationRequestDocument(methodName));
const documentLink = (await this.getAttributeValue(verificationsVendor.verificationRequestDocument(methodName), 'href')) as string;
await this.clickAndWaitForUrl(documentLink, verificationsVendor.verificationRequestDocument(methodName));
await this.toHaveAttribute('body img', 'src', documentLink);
Expand Down
2 changes: 1 addition & 1 deletion tests/pw/tests/api/quoteRequests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test.describe('request quote api test', () => {
expect(responseBody).toMatchSchema(schemas.quoteRequestsSchema.quoteRequestSchema);
});

test('update batch request quote', { tag: ['@pro'] }, async () => {
test.skip('update batch request quote', { tag: ['@pro'] }, async () => {
const allRequestQuoteIds = (await apiUtils.getAllQuoteRequests()).map((a: { id: unknown }) => a.id);
const [response, responseBody] = await apiUtils.put(endPoints.updateBatchRequestQuotes, { data: { trash: allRequestQuoteIds } });
expect(response.ok()).toBeTruthy();
Expand Down
5 changes: 3 additions & 2 deletions tests/pw/tests/e2e/catalogmode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ test.describe('Catalog mode test', () => {

test('vendor can enable RFQ in catalog mode', { tag: ['@pro', '@admin'] }, async () => {
const [previousMeta] = await dbUtils.updateUserMeta(sellerId, 'dokan_profile_settings', { catalog_mode: { ...payloads.catalogModeSetting, request_a_quote_enabled: 'on' } });
const [, productId, productName] = await apiUtils.createProduct(helpers.deepMergeObjects(payloads.createProduct(), payloads.catalogMode), payloads.userAuth(vendorName));
await apiUtils.createQuoteRule({ ...payloads.createQuoteRule(), apply_on_all_product: '', product_ids: [productId] }, payloads.adminAuth);
const [, productId, productName] = await apiUtils.createProduct(payloads.createProduct(), payloads.userAuth(vendorName));
const [, quoteRuleId] = await apiUtils.createQuoteRule({ ...payloads.createQuoteRule(), product_ids: [productId] }, payloads.adminAuth);
await dbUtils.updateQuoteRuleContent(quoteRuleId, { switches: { product_switch: 'true' } }); // todo: remove after api fix
shashwatahalder01 marked this conversation as resolved.
Show resolved Hide resolved
await customer.viewRfqInCatalogMode(productName, vendorName, ShopPage, SingleStorePage);

// reset
Expand Down
8 changes: 4 additions & 4 deletions tests/pw/tests/e2e/requestForQuoteRules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ test.describe('Request for quotation Rules test', () => {
admin = new RequestForQuotationsPage(aPage);

apiUtils = new ApiUtils(await request.newContext());
[, , quoteRuleTitle] = await apiUtils.createQuoteRule(payloads.createQuoteRule(), payloads.adminAuth);
[, , quoteRuleTitle] = await apiUtils.createQuoteRule(payloads.createQuoteRule(), payloads.adminAuth); // todo: fix after api is updated
});

test.afterAll(async () => {
await apiUtils.deleteAllQuoteRules(payloads.adminAuth); //todo: remove in future
await aPage.close();
await apiUtils.dispose();
});
Expand All @@ -34,11 +33,12 @@ test.describe('Request for quotation Rules test', () => {
});

test('admin can add quote rule', { tag: ['@pro', '@admin'] }, async () => {
await admin.addQuoteRule(data.requestForQuotation.quoteRule());
const [, , productName] = await apiUtils.createProduct(payloads.createProduct(), payloads.vendorAuth);
await admin.addQuoteRule({ ...data.requestForQuotation.quoteRule(), includeProducts: productName });
});

test('admin can edit quote rule', { tag: ['@pro', '@admin'] }, async () => {
await admin.editQuoteRule({ ...data.requestForQuotation.quoteRule(), title: quoteRuleTitle });
await admin.editQuoteRule({ ...data.requestForQuotation.quoteRule(), title: quoteRuleTitle, specificProducts: false, });
});

test('admin can trash quote rule', { tag: ['@pro', '@admin'] }, async () => {
Expand Down
41 changes: 21 additions & 20 deletions tests/pw/tests/e2e/requestForQuotes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RequestForQuotationsPage } from '@pages/requestForQuotationsPage';
import { ApiUtils } from '@utils/apiUtils';
import { data } from '@utils/testData';
import { payloads } from '@utils/payloads';
import { dbUtils } from '@utils/dbUtils';

const { CUSTOMER_ID } = process.env;

Expand All @@ -11,7 +12,7 @@ test.describe('Request for quotation test admin', () => {
let aPage: Page;
let apiUtils: ApiUtils;
const productId: string[] = [];
let quoteTitle: string;
let quoteId: string;

test.beforeAll(async ({ browser }) => {
const adminContext = await browser.newContext(data.auth.adminAuth);
Expand All @@ -20,7 +21,7 @@ test.describe('Request for quotation test admin', () => {

apiUtils = new ApiUtils(await request.newContext());
[, productId[0]] = await apiUtils.createProduct(payloads.createProduct(), payloads.vendorAuth);
[, , quoteTitle] = await apiUtils.createQuoteRequest({ ...payloads.createQuoteRequest(), product_ids: productId, user_id: CUSTOMER_ID }, payloads.adminAuth);
[, quoteId] = await apiUtils.createQuoteRequest({ ...payloads.createQuoteRequest(), product_ids: productId, user_id: CUSTOMER_ID }, payloads.adminAuth);
});

test.afterAll(async () => {
Expand All @@ -40,33 +41,33 @@ test.describe('Request for quotation test admin', () => {
await admin.addQuote(data.requestForQuotation.quote());
});

test('admin can edit quote', { tag: ['@pro', '@admin'] }, async () => {
await admin.editQuote({ ...data.requestForQuotation.quote(), title: quoteTitle });
test.skip('admin can edit quote', { tag: ['@pro', '@admin'] }, async () => {
await admin.editQuote({ ...data.requestForQuotation.quote(), id: quoteId });
});

test('admin can trash quote', { tag: ['@pro', '@admin'] }, async () => {
const [, , quoteTitle] = await apiUtils.createQuoteRequest({ ...payloads.createQuoteRequest(), product_ids: productId, user_id: CUSTOMER_ID }, payloads.adminAuth);
await admin.updateQuote(quoteTitle, 'trash');
const [, quoteId] = await apiUtils.createQuoteRequest({ ...payloads.createQuoteRequest(), product_ids: productId, user_id: CUSTOMER_ID }, payloads.adminAuth);
await admin.updateQuote(quoteId, 'trash');
});

test('admin can restore quote', { tag: ['@pro', '@admin'] }, async () => {
const [, , quoteTitle] = await apiUtils.createQuoteRequest({ ...payloads.createQuoteRequest(), product_ids: productId, status: 'trash', user_id: CUSTOMER_ID }, payloads.adminAuth);
await admin.updateQuote(quoteTitle, 'restore');
const [, quoteId] = await apiUtils.createQuoteRequest({ ...payloads.createQuoteRequest(), product_ids: productId, status: 'trash', user_id: CUSTOMER_ID }, payloads.adminAuth);
await admin.updateQuote(quoteId, 'restore');
});

test('admin can permanently delete quote', { tag: ['@pro', '@admin'] }, async () => {
const [, , quoteTitle] = await apiUtils.createQuoteRequest({ ...payloads.createQuoteRequest(), product_ids: productId, status: 'trash', user_id: CUSTOMER_ID }, payloads.adminAuth);
await admin.updateQuote(quoteTitle, 'permanently-delete');
const [, quoteId] = await apiUtils.createQuoteRequest({ ...payloads.createQuoteRequest(), product_ids: productId, status: 'trash', user_id: CUSTOMER_ID }, payloads.adminAuth);
await admin.updateQuote(quoteId, 'permanently-delete');
});

test('admin can approve quote', { tag: ['@pro', '@admin'] }, async () => {
const [, , quoteTitle] = await apiUtils.createQuoteRequest({ ...payloads.createQuoteRequest(), product_ids: productId, user_id: CUSTOMER_ID }, payloads.adminAuth);
await admin.approveQuote(quoteTitle);
const [, quoteId] = await apiUtils.createQuoteRequest({ ...payloads.createQuoteRequest(), product_ids: productId, user_id: CUSTOMER_ID }, payloads.adminAuth);
await admin.approveQuote(quoteId);
});

test('admin can convert quote to order', { tag: ['@pro', '@admin'] }, async () => {
const [, , quoteTitle] = await apiUtils.createQuoteRequest({ ...payloads.createQuoteRequest(), product_ids: productId, status: 'approve', user_id: CUSTOMER_ID }, payloads.adminAuth);
await admin.convertQuoteToOrder(quoteTitle);
const [, quoteId] = await apiUtils.createQuoteRequest({ ...payloads.createQuoteRequest(), product_ids: productId, status: 'approve', user_id: CUSTOMER_ID }, payloads.adminAuth);
await admin.convertQuoteToOrder(quoteId);
});

test('admin can perform quote bulk actions', { tag: ['@pro', '@admin', '@serial'] }, async () => {
Expand All @@ -79,9 +80,8 @@ test.describe('Request for quotation test vendor', () => {
let vPage: Page;
let apiUtils: ApiUtils;
const productId: string[] = [];
let quoteTitle: string;
let productName: string;
let quoteId: string;
let productName: string;

test.beforeAll(async ({ browser }) => {
const vendorContext = await browser.newContext(data.auth.vendorAuth);
Expand All @@ -90,7 +90,7 @@ test.describe('Request for quotation test vendor', () => {

apiUtils = new ApiUtils(await request.newContext());
[, productId[0], productName] = await apiUtils.createProduct(payloads.createProduct(), payloads.vendorAuth);
[, quoteId, quoteTitle] = await apiUtils.createQuoteRequest({ ...payloads.createQuoteRequest(), product_ids: productId, user_id: CUSTOMER_ID }, payloads.adminAuth);
[, quoteId] = await apiUtils.createQuoteRequest({ ...payloads.createQuoteRequest(), product_ids: productId, user_id: CUSTOMER_ID }, payloads.adminAuth);
});

test.afterAll(async () => {
Expand All @@ -103,7 +103,7 @@ test.describe('Request for quotation test vendor', () => {
});

test('vendor can view request quote details', { tag: ['@pro', '@exploratory', '@vendor'] }, async () => {
await vendor.vendorViewQuoteDetails(quoteTitle);
await vendor.vendorViewQuoteDetails(quoteId);
});

test('vendor can update quote request', { tag: ['@pro', '@vendor'] }, async () => {
Expand Down Expand Up @@ -138,7 +138,8 @@ test.describe('Request for quotation test customer', () => {
apiUtils = new ApiUtils(await request.newContext());

[, productId[0], productName] = await apiUtils.createProduct(payloads.createProduct(), payloads.vendorAuth);
await apiUtils.createQuoteRule({ ...payloads.createQuoteRule(), product_ids: productId, apply_on_all_product: '0' }, payloads.adminAuth);
const [, quoteRuleId] = await apiUtils.createQuoteRule({ ...payloads.createQuoteRule(), product_ids: productId }, payloads.adminAuth);
await dbUtils.updateQuoteRuleContent(quoteRuleId, { switches: { product_switch: 'true' } }); // todo: remove after api fix
[, quoteId] = await apiUtils.createQuoteRequest({ ...payloads.createQuoteRequest(), product_ids: productId, user_id: CUSTOMER_ID }, payloads.adminAuth);
});

Expand All @@ -161,7 +162,7 @@ test.describe('Request for quotation test customer', () => {
await customer.customerViewRequestedQuoteDetails(quoteId);
});

test('customer can update quote request', { tag: ['@pro', '@customer'] }, async () => {
test.skip('customer can update quote request', { tag: ['@pro', '@customer'] }, async () => {
await customer.customerUpdateRequestedQuote(quoteId, { ...data.requestForQuotation.customerQuoteProduct, productName: productName });
});

Expand Down
4 changes: 2 additions & 2 deletions tests/pw/tests/e2e/vendorStaff.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ApiUtils } from '@utils/apiUtils';
import { data } from '@utils/testData';
import { payloads } from '@utils/payloads';

test.describe('Vendor staff test', () => {
test.describe('Vendor staff test (vendor)', () => {
let vendor: VendorStaffPage;
let vPage: Page;
let apiUtils: ApiUtils;
Expand Down Expand Up @@ -45,7 +45,7 @@ test.describe('Vendor staff test', () => {
});
});

test.describe('Wholesale test (customer)', () => {
test.describe('Vendor staff test (vendorStaff)', () => {
let staff: VendorStaffPage;
let sPage: Page;
let apiUtils: ApiUtils;
Expand Down
11 changes: 11 additions & 0 deletions tests/pw/utils/dbUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,15 @@ export const dbUtils = {
const updateCountQuery = `UPDATE ${dbPrefix}_term_taxonomy SET count = count + 1 WHERE term_taxonomy_id = ?;`;
await dbUtils.dbQuery(updateCountQuery, [subscriptionTermTaxonomyId]);
},

async updateQuoteRuleContent(quoted: string, updatedRuleContent: object) {
const querySelect = `SELECT rule_contents FROM ${dbPrefix}_dokan_request_quote_rules WHERE id = ?`;
const res = await dbUtils.dbQuery(querySelect, [quoted]);

const currentRuleContent = unserialize(res[0].rule_contents);
const newRuleContent = helpers.deepMergeObjects(currentRuleContent, updatedRuleContent);

const queryUpdate = `UPDATE ${dbPrefix}_dokan_request_quote_rules SET rule_contents = ? WHERE id = ?`;
await dbUtils.dbQuery(queryUpdate, [serialize(newRuleContent), quoted]);
},
shashwatahalder01 marked this conversation as resolved.
Show resolved Hide resolved
};
Loading
Loading