Skip to content

Commit

Permalink
Add: add product form tests (download options, inventory) (getdokan#2389
Browse files Browse the repository at this point in the history
)

* Add: add product form tests (download options, inventory)

* Fix : revert unwanted changes
  • Loading branch information
shashwatahalder01 authored Oct 4, 2024
1 parent 2fdcc42 commit 51bf060
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 1 deletion.
12 changes: 12 additions & 0 deletions tests/pw/feature-map/feature-map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
98 changes: 97 additions & 1 deletion tests/pw/pages/productsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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<void> {
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<void> {
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<void> {
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<void> {
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<void> {
Expand Down
54 changes: 54 additions & 0 deletions tests/pw/tests/e2e/productsDetails.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
11 changes: 11 additions & 0 deletions tests/pw/tests/e2e/vendorSettings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
});
Expand Down Expand Up @@ -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');
});
Expand Down

0 comments on commit 51bf060

Please sign in to comment.