Skip to content

Commit

Permalink
Add: product form tests (other options, catalog) (getdokan#2393)
Browse files Browse the repository at this point in the history
* Add: product form tests (other options, catalog)

* Add: add product form tests( shipping, tax, linked products)

* Fix: PR reviews

* Fix: pr reviews

* Update: remove duplicate method

* Update: update login method

* Fix: pr reviews
  • Loading branch information
shashwatahalder01 authored Oct 7, 2024
1 parent dedf360 commit b2ce2cc
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 3 deletions.
9 changes: 9 additions & 0 deletions tests/pw/feature-map/feature-map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@
vendor can add product catalog mode (with price hidden) [lite]: true
vendor can remove product catalog mode [lite]: true
vendor can remove product catalog mode (price hidden option) [lite]: true
vendor can add product shipping: true
vendor can update product shipping: true
vendor can remove product shipping: true
vendor can add product tax: true
vendor can add product tax (with tax class): true
vendor can add product linked products (up-sells): true
vendor can add product linked products (cross-sells): true
vendor can remove product linked products (up-sells): true
vendor can remove product linked products (cross-sells): true

- page: 'MyOrders'
features:
Expand Down
4 changes: 2 additions & 2 deletions tests/pw/pages/loginPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ export class LoginPage extends BasePage {

// user login backend
async loginBackend(user: user, url: string = data.subUrls.backend.login, storageState?: string): Promise<void> {
await this.goIfNotThere(url);
await this.gotoUntilNetworkidle(url);
const emailField = await this.isVisible(selector.backend.email);
if (emailField) {
await this.clearAndType(selector.backend.email, user.username);
await this.clearAndType(selector.backend.password, user.password);
await this.clickAndWaitForResponseAndLoadState(data.subUrls.backend.login, selector.backend.login, 302);
await this.clickAndWaitForResponseAndLoadState(data.subUrls.backend.adminDashboard, selector.backend.login);
if (storageState) {
await this.page.context().storageState({ path: storageState });
}
Expand Down
115 changes: 115 additions & 0 deletions tests/pw/pages/productsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,121 @@ export class ProductsPage extends AdminPage {
}
}

// dokan pro features

// add product shipping
async addProductShipping(productName: string, shipping: product['productInfo']['shipping']): Promise<void> {
await this.goToProductEdit(productName);
await this.check(productsVendor.shipping.requiresShipping);
await this.clearAndType(productsVendor.shipping.weight, shipping.weight);
await this.clearAndType(productsVendor.shipping.length, shipping.length);
await this.clearAndType(productsVendor.shipping.width, shipping.width);
await this.clearAndType(productsVendor.shipping.height, shipping.height);
await this.selectByLabel(productsVendor.shipping.shippingClass, shipping.shippingClass);
await this.saveProduct();
await this.toBeChecked(productsVendor.shipping.requiresShipping);
await this.toHaveValue(productsVendor.shipping.weight, shipping.weight);
await this.toHaveValue(productsVendor.shipping.length, shipping.length);
await this.toHaveValue(productsVendor.shipping.width, shipping.width);
await this.toHaveValue(productsVendor.shipping.height, shipping.height);
await this.toHaveSelectedLabel(productsVendor.shipping.shippingClass, shipping.shippingClass);
}
// add product shipping
async removeProductShipping(productName: string): Promise<void> {
await this.goToProductEdit(productName);
await this.uncheck(productsVendor.shipping.requiresShipping);
await this.saveProduct();
await this.notToBeChecked(productsVendor.shipping.requiresShipping);
}

// add product tax
async addProductTax(productName: string, tax: product['productInfo']['tax'], hasClass: boolean = false): Promise<void> {
await this.goToProductEdit(productName);
await this.selectByValue(productsVendor.tax.status, tax.status);
if (hasClass) await this.selectByValue(productsVendor.tax.class, tax.class);
await this.saveProduct();
await this.toHaveSelectedValue(productsVendor.tax.status, tax.status);
if (hasClass) await this.toHaveSelectedValue(productsVendor.tax.class, tax.class);
}

// add product linked products
async addProductLinkedProducts(productName: string, linkedProducts: product['productInfo']['linkedProducts'], choice: string): Promise<void> {
await this.goToProductEdit(productName);
switch (choice) {
case 'up-sells':
for (const linkedProduct of linkedProducts.upSells) {
await this.typeAndWaitForResponse(data.subUrls.ajax, productsVendor.linkedProducts.upSells, linkedProduct);
await this.click(productsVendor.linkedProducts.searchedResult(linkedProduct));
await this.toBeVisible(productsVendor.linkedProducts.selectedUpSellProduct(linkedProduct));
}
break;
case 'cross-sells':
for (const linkedProduct of linkedProducts.crossSells) {
await this.typeAndWaitForResponse(data.subUrls.ajax, productsVendor.linkedProducts.crossSells, linkedProduct);
await this.click(productsVendor.linkedProducts.searchedResult(linkedProduct));
await this.toBeVisible(productsVendor.linkedProducts.selectedCrossSellProduct(linkedProduct));
}
break;
default:
break;
}

await this.saveProduct();

switch (choice) {
case 'up-sells':
for (const linkedProduct of linkedProducts.upSells) {
await this.toBeVisible(productsVendor.linkedProducts.selectedUpSellProduct(linkedProduct));
}
break;
case 'cross-sells':
for (const linkedProduct of linkedProducts.crossSells) {
await this.toBeVisible(productsVendor.linkedProducts.selectedCrossSellProduct(linkedProduct));
}
break;
default:
break;
}
}

// add product linked products
async removeProductLinkedProducts(productName: string, linkedProducts: product['productInfo']['linkedProducts'], choice: string): Promise<void> {
await this.goToProductEdit(productName);
switch (choice) {
case 'up-sells':
for (const linkedProduct of linkedProducts.upSells) {
await this.click(productsVendor.linkedProducts.removeSelectedUpSellProduct(linkedProduct));
await this.press('Escape'); // shift focus from element
}
break;
case 'cross-sells':
for (const linkedProduct of linkedProducts.crossSells) {
await this.click(productsVendor.linkedProducts.removeSelectedCrossSellProduct(linkedProduct));
await this.press('Escape'); // shift focus from element
}
break;
default:
break;
}

await this.saveProduct();

switch (choice) {
case 'up-sells':
for (const linkedProduct of linkedProducts.upSells) {
await this.notToBeVisible(productsVendor.linkedProducts.selectedUpSellProduct(linkedProduct));
}
break;
case 'cross-sells':
for (const linkedProduct of linkedProducts.crossSells) {
await this.notToBeVisible(productsVendor.linkedProducts.selectedCrossSellProduct(linkedProduct));
}
break;
default:
break;
}
}

// add product EU compliance
async addProductEuCompliance(productName: string, euCompliance: product['productInfo']['euCompliance']): Promise<void> {
await this.goToProductEdit(productName);
Expand Down
40 changes: 40 additions & 0 deletions tests/pw/tests/e2e/productsDetails.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,44 @@ test.describe('Product details functionality test', () => {
await dbUtils.updateOptionValue(dbData.dokan.optionName.selling, { catalog_mode_hide_add_to_cart_button: 'on', catalog_mode_hide_product_price: 'on' });
await vendor.removeProductCatalogMode(productName, true);
});

// shipping and tax

test('vendor can add product shipping', { tag: ['@pro', '@vendor'] }, async () => {
await vendor.addProductShipping(productName1, data.product.productInfo.shipping);
});

test('vendor can update product shipping', { tag: ['@pro', '@vendor'] }, async () => {
await vendor.addProductShipping(productName, data.product.productInfo.shipping);
});

test('vendor can remove product shipping', { tag: ['@pro', '@vendor'] }, async () => {
await vendor.removeProductShipping(productName);
});

test('vendor can add product tax', { tag: ['@pro', '@vendor'] }, async () => {
await vendor.addProductTax(productName1, data.product.productInfo.tax);
});

test('vendor can add product tax (with tax class)', { tag: ['@pro', '@vendor'] }, async () => {
await vendor.addProductTax(productName1, data.product.productInfo.tax, true);
});

// linked products

test('vendor can add product linked products (up-sells)', { tag: ['@pro', '@vendor'] }, async () => {
await vendor.addProductLinkedProducts(productName1, data.product.productInfo.linkedProducts, 'up-sells');
});

test('vendor can add product linked products (cross-sells)', { tag: ['@pro', '@vendor'] }, async () => {
await vendor.addProductLinkedProducts(productName1, data.product.productInfo.linkedProducts, 'cross-sells');
});

test('vendor can remove product linked products (up-sells)', { tag: ['@pro', '@vendor'] }, async () => {
await vendor.removeProductLinkedProducts(productName, data.product.productInfo.linkedProducts, 'up-sells');
});

test('vendor can remove product linked products (cross-sells)', { tag: ['@pro', '@vendor'] }, async () => {
await vendor.removeProductLinkedProducts(productName, data.product.productInfo.linkedProducts, 'cross-sells');
});
});
2 changes: 1 addition & 1 deletion tests/pw/tests/e2e/vendorSettings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ test.describe('Vendor settings test', () => {
await vendor.setSocialProfile(data.vendor.socialProfileUrls);
});

test('vendor can set rma settings (no warranty):', { tag: ['@pro', '@vendor'] }, async () => {
test('vendor can set rma settings (no warranty)', { tag: ['@pro', '@vendor'] }, async () => {
await vendor.setRmaSettings({ ...data.vendor.rma, type: 'no_warranty' });
});

Expand Down

0 comments on commit b2ce2cc

Please sign in to comment.