From 51bf06048926a6f2cc869bd6ee4500c106766a7e Mon Sep 17 00:00:00 2001 From: shashwata Halder Date: Fri, 4 Oct 2024 09:22:09 +0600 Subject: [PATCH] Add: add product form tests (download options, inventory) (#2389) * Add: add product form tests (download options, inventory) * Fix : revert unwanted changes --- tests/pw/feature-map/feature-map.yml | 12 +++ tests/pw/pages/productsPage.ts | 98 +++++++++++++++++++++- tests/pw/tests/e2e/productsDetails.spec.ts | 54 ++++++++++++ tests/pw/tests/e2e/vendorSettings.spec.ts | 11 +++ 4 files changed, 174 insertions(+), 1 deletion(-) diff --git a/tests/pw/feature-map/feature-map.yml b/tests/pw/feature-map/feature-map.yml index e7758eee31..5c445ecc78 100644 --- a/tests/pw/feature-map/feature-map.yml +++ b/tests/pw/feature-map/feature-map.yml @@ -146,6 +146,18 @@ vendor can update product short description [lite]: true vendor can remove product short description [lite]: true vendor can update product description [lite]: true + vendor can add product downloadable options [lite]: true + vendor can update product downloadable options [lite]: true + vendor can remove product downloadable file [lite]: true + vendor can add product inventory options (SKU) [lite]: true + vendor can update product inventory options (SKU) [lite]: true + vendor can remove product inventory options (SKU) [lite]: true + vendor can add product inventory options (stock status) [lite]: true + vendor can add product inventory options (stock management) [lite]: true + vendor can update product inventory options (stock management) [lite]: true + vendor can remove product inventory options (stock management) [lite]: true + vendor can add product inventory options (allow single quantity) [lite]: true + vendor can remove product inventory options (allow single quantity) [lite]: true - page: 'MyOrders' features: diff --git a/tests/pw/pages/productsPage.ts b/tests/pw/pages/productsPage.ts index a802e6abe9..a0d1c2c8fe 100644 --- a/tests/pw/pages/productsPage.ts +++ b/tests/pw/pages/productsPage.ts @@ -919,7 +919,7 @@ export class ProductsPage extends AdminPage { await this.goToProductEdit(productName); for (const tag of tags) { await this.click(productsVendor.tags.removeSelectedTags(tag)); - await this.press('Escape'); // shift focus from element + await this.press('Escape'); // shift focus from element } await this.saveProduct(); @@ -1003,6 +1003,102 @@ export class ProductsPage extends AdminPage { await this.toContainTextFrameLocator(productsVendor.description.descriptionIframe, productsVendor.description.descriptionHtmlBody, description); } + // add product downloadable options + async addProductDownloadableOptions(productName: string, downloadableOption: product['productInfo']['downloadableOptions']): Promise { + await this.goToProductEdit(productName); + await this.check(productsVendor.downloadable); + await this.click(productsVendor.downloadableOptions.addFile); + await this.clearAndType(productsVendor.downloadableOptions.fileName, downloadableOption.fileName); + await this.click(productsVendor.downloadableOptions.chooseFile); + await this.uploadMedia(downloadableOption.fileUrl); + await this.clearAndType(productsVendor.downloadableOptions.downloadLimit, downloadableOption.downloadLimit); + await this.clearAndType(productsVendor.downloadableOptions.downloadExpiry, downloadableOption.downloadExpiry); + await this.saveProduct(); + await this.toBeChecked(productsVendor.downloadable); + await this.toHaveValue(productsVendor.downloadableOptions.fileName, downloadableOption.fileName); + await this.toHaveValue(productsVendor.downloadableOptions.downloadLimit, downloadableOption.downloadLimit); + await this.toHaveValue(productsVendor.downloadableOptions.downloadExpiry, downloadableOption.downloadExpiry); + } + + // remove product downloadable files + async removeDownloadableFile(productName: string, downloadableOption: product['productInfo']['downloadableOptions']): Promise { + await this.goToProductEdit(productName); + const fileCount = await this.getElementCount(productsVendor.downloadableOptions.deleteFile); + for (let i = 0; i < fileCount; i++) { + await this.clickFirstLocator(productsVendor.downloadableOptions.deleteFile); + } + await this.clearAndType(productsVendor.downloadableOptions.downloadLimit, downloadableOption.downloadLimit); + await this.clearAndType(productsVendor.downloadableOptions.downloadExpiry, downloadableOption.downloadExpiry); + await this.saveProduct(); + await this.notToBeVisible(productsVendor.downloadableOptions.deleteFile); + await this.toHaveValue(productsVendor.downloadableOptions.downloadLimit, downloadableOption.downloadLimit); + await this.toHaveValue(productsVendor.downloadableOptions.downloadExpiry, downloadableOption.downloadExpiry); + } + + // add product inventory + async addProductInventory(productName: string, inventory: product['productInfo']['inventory'], choice: string): Promise { + await this.goToProductEdit(productName); + + switch (choice) { + case 'sku': + await this.clearAndType(productsVendor.inventory.sku, inventory.sku); + break; + case 'stock-status': + await this.selectByValue(productsVendor.inventory.stockStatus, inventory.stockStatus); + break; + case 'stock-management': + await this.check(productsVendor.inventory.enableStockManagement); + await this.clearAndType(productsVendor.inventory.stockQuantity, inventory.stockQuantity); + await this.clearAndType(productsVendor.inventory.lowStockThreshold, inventory.lowStockThreshold); + await this.selectByValue(productsVendor.inventory.allowBackorders, inventory.backorders); + break; + case 'one-quantity': + if (inventory.oneQuantity) { + await this.check(productsVendor.inventory.allowOnlyOneQuantity); + } else { + await this.uncheck(productsVendor.inventory.allowOnlyOneQuantity); + } + break; + default: + break; + } + + await this.saveProduct(); + + // todo: replace switch with all method action and assertion as object member and loop through to call them + + switch (choice) { + case 'sku': + await this.toHaveValue(productsVendor.inventory.sku, inventory.sku); + break; + case 'stock-status': + await this.toHaveSelectedValue(productsVendor.inventory.stockStatus, inventory.stockStatus); + break; + case 'stock-management': + await this.toBeChecked(productsVendor.inventory.enableStockManagement); + await this.toHaveValue(productsVendor.inventory.stockQuantity, inventory.stockQuantity); + await this.toHaveValue(productsVendor.inventory.lowStockThreshold, inventory.lowStockThreshold); + await this.toHaveSelectedValue(productsVendor.inventory.allowBackorders, inventory.backorders); + await this.notToBeVisible(productsVendor.inventory.stockStatus); + break; + case 'one-quantity': + if (inventory.oneQuantity) { + await this.toBeChecked(productsVendor.inventory.allowOnlyOneQuantity); + } else { + await this.notToBeChecked(productsVendor.inventory.allowOnlyOneQuantity); + } + break; + default: + break; + } + } + // remove product inventory [stock management] + async removeProductInventory(productName: string): Promise { + await this.goToProductEdit(productName); + await this.uncheck(productsVendor.inventory.enableStockManagement); + await this.saveProduct(); + await this.notToBeChecked(productsVendor.inventory.enableStockManagement); + } // add product catalog mode async addProductCatalogMode(productName: string, hidePrice: boolean = false): Promise { diff --git a/tests/pw/tests/e2e/productsDetails.spec.ts b/tests/pw/tests/e2e/productsDetails.spec.ts index ffbedaa490..c6dde8b3ce 100644 --- a/tests/pw/tests/e2e/productsDetails.spec.ts +++ b/tests/pw/tests/e2e/productsDetails.spec.ts @@ -212,4 +212,58 @@ test.describe('Product details functionality test', () => { await vendor.addProductDescription(productName, data.product.productInfo.description.description); }); + // product downloadable options + + test('vendor can add product downloadable options', { tag: ['@lite', '@vendor'] }, async () => { + await vendor.addProductDownloadableOptions(productName1, data.product.productInfo.downloadableOptions); + }); + + test('vendor can update product downloadable options', { tag: ['@lite', '@vendor'] }, async () => { + // todo: need a product with downloadable file + await vendor.addProductDownloadableOptions(productName, data.product.productInfo.downloadableOptions); + }); + + test('vendor can remove product downloadable file', { tag: ['@lite', '@vendor'] }, async () => { + // todo: need a product with downloadable file + await vendor.addProductDownloadableOptions(productName, data.product.productInfo.downloadableOptions); + await vendor.removeDownloadableFile(productName, { ...data.product.productInfo.downloadableOptions, downloadLimit: '', downloadExpiry: '' }); + }); + + // product inventory options + + test('vendor can add product inventory options (SKU)', { tag: ['@lite', '@vendor'] }, async () => { + await vendor.addProductInventory(productName1, data.product.productInfo.inventory(), 'sku'); + }); + + test('vendor can update product inventory options (SKU)', { tag: ['@lite', '@vendor'] }, async () => { + await vendor.addProductInventory(productName, data.product.productInfo.inventory(), 'sku'); + }); + + test('vendor can remove product inventory options (SKU)', { tag: ['@lite', '@vendor'] }, async () => { + await vendor.addProductInventory(productName, { ...data.product.productInfo.inventory(), sku: '' }, 'sku'); + }); + + test('vendor can add product inventory options (stock status)', { tag: ['@lite', '@vendor'] }, async () => { + await vendor.addProductInventory(productName1, data.product.productInfo.inventory(), 'stock-status'); + }); + + test('vendor can add product inventory options (stock management)', { tag: ['@lite', '@vendor'] }, async () => { + await vendor.addProductInventory(productName1, data.product.productInfo.inventory(), 'stock-management'); + }); + + test('vendor can update product inventory options (stock management)', { tag: ['@lite', '@vendor'] }, async () => { + await vendor.addProductInventory(productName1, data.product.productInfo.inventory(), 'stock-management'); + }); + + test('vendor can remove product inventory options (stock management)', { tag: ['@lite', '@vendor'] }, async () => { + await vendor.removeProductInventory(productName); + }); + + test('vendor can add product inventory options (allow single quantity)', { tag: ['@lite', '@vendor'] }, async () => { + await vendor.addProductInventory(productName1, data.product.productInfo.inventory(), 'one-quantity'); + }); + + test('vendor can remove product inventory options (allow single quantity)', { tag: ['@lite', '@vendor'] }, async () => { + await vendor.addProductInventory(productName, { ...data.product.productInfo.inventory(), oneQuantity: false }, 'one-quantity'); + }); }); diff --git a/tests/pw/tests/e2e/vendorSettings.spec.ts b/tests/pw/tests/e2e/vendorSettings.spec.ts index 0345f0ab35..8649629d1d 100644 --- a/tests/pw/tests/e2e/vendorSettings.spec.ts +++ b/tests/pw/tests/e2e/vendorSettings.spec.ts @@ -6,6 +6,8 @@ import { dbUtils } from '@utils/dbUtils'; import { data } from '@utils/testData'; import { payloads } from '@utils/payloads'; +const { VENDOR_ID } = process.env; + test.describe('Vendor settings test', () => { let vendor: VendorSettingsPage; let vPage: Page; @@ -21,6 +23,7 @@ test.describe('Vendor settings test', () => { test.afterAll(async () => { await apiUtils.setStoreSettings(payloads.defaultStoreSettings, payloads.vendorAuth); + await dbUtils.setUserMeta(VENDOR_ID, '_dokan_rma_settings', dbData.testData.dokan.rmaSettings, true); await vPage.close(); await apiUtils.dispose(); }); @@ -49,6 +52,14 @@ test.describe('Vendor settings test', () => { // store settings + test.skip('vendor can set store banner settings', { tag: ['@lite', '@vendor'] }, async () => { + await vendor.setStoreSettings(data.vendor.vendorInfo, 'banner'); + }); + + test.skip('vendor can set store profile picture settings', { tag: ['@lite', '@vendor'] }, async () => { + await vendor.setStoreSettings(data.vendor.vendorInfo, 'profile-picture'); + }); + test('vendor can set store basic settings', { tag: ['@lite', '@vendor'] }, async () => { await vendor.setStoreSettings(data.vendor.vendorInfo, 'basic'); });