From 9a21a8422dc7593dd2630aca200f56e7ab985848 Mon Sep 17 00:00:00 2001 From: shashwata Halder Date: Wed, 2 Oct 2024 08:41:55 +0600 Subject: [PATCH] Add: add product form tests (#2385) --- tests/pw/feature-map/feature-map.yml | 10 +++ tests/pw/pages/productsPage.ts | 76 ++++++++++++++++++++++ tests/pw/tests/e2e/productsDetails.spec.ts | 56 ++++++++++++++++ 3 files changed, 142 insertions(+) diff --git a/tests/pw/feature-map/feature-map.yml b/tests/pw/feature-map/feature-map.yml index 8e32b04d70..fc0572af2b 100644 --- a/tests/pw/feature-map/feature-map.yml +++ b/tests/pw/feature-map/feature-map.yml @@ -136,6 +136,16 @@ vendor can add product tags [lite]: true vendor can remove product tags [lite]: true vendor can create product tags: true + vendor can add product cover image [lite]: true + vendor can update product cover image [lite]: true + vendor can remove product cover image [lite]: true + vendor can add product gallery image [lite]: true + vendor can update product gallery image [lite]: true + vendor can remove product gallery image [lite]: true + vendor can add product short description [lite]: true + vendor can update product short description [lite]: true + vendor can remove product short description [lite]: true + vendor can update product description [lite]: true - page: 'MyOrders' features: diff --git a/tests/pw/pages/productsPage.ts b/tests/pw/pages/productsPage.ts index e884b42d25..a802e6abe9 100644 --- a/tests/pw/pages/productsPage.ts +++ b/tests/pw/pages/productsPage.ts @@ -928,6 +928,82 @@ export class ProductsPage extends AdminPage { } } + // add product cover image + async addProductCoverImage(productName: string, coverImage: string, removePrevious: boolean = false): Promise { + await this.goToProductEdit(productName); + // remove previous cover image + if (removePrevious) { + await this.hover(productsVendor.image.coverImageDiv); + await this.click(productsVendor.image.removeFeatureImage); + await this.toBeVisible(productsVendor.image.uploadImageText); + } + await this.click(productsVendor.image.cover); + await this.uploadMedia(coverImage); + await this.saveProduct(); + await this.toHaveAttribute(productsVendor.image.uploadedFeatureImage, 'src', /.+/); // Ensures 'src' has any non-falsy value + await this.notToBeVisible(productsVendor.image.uploadImageText); + } + + // remove product cover image + async removeProductCoverImage(productName: string): Promise { + await this.goToProductEdit(productName); + await this.hover(productsVendor.image.coverImageDiv); + await this.click(productsVendor.image.removeFeatureImage); + await this.saveProduct(); + await this.toHaveAttribute(productsVendor.image.uploadedFeatureImage, 'src', /^$/); + await this.toBeVisible(productsVendor.image.uploadImageText); + } + + // add product gallery images + async addProductGalleryImages(productName: string, galleryImages: string[], removePrevious: boolean = false): Promise { + await this.goToProductEdit(productName); + // remove previous gallery images + if (removePrevious) { + const imageCount = await this.getElementCount(productsVendor.image.uploadedGalleryImage); + for (let i = 0; i < imageCount; i++) { + await this.hover(productsVendor.image.galleryImageDiv); + await this.click(productsVendor.image.removeGalleryImage); + } + await this.toHaveCount(productsVendor.image.uploadedGalleryImage, 0); + } + + for (const galleryImage of galleryImages) { + await this.click(productsVendor.image.gallery); + await this.uploadMedia(galleryImage); + } + await this.saveProduct(); + await this.toHaveCount(productsVendor.image.uploadedGalleryImage, galleryImages.length); + } + + // remove product gallery images + async removeProductGalleryImages(productName: string): Promise { + await this.goToProductEdit(productName); + const imageCount = await this.getElementCount(productsVendor.image.uploadedGalleryImage); + for (let i = 0; i < imageCount; i++) { + await this.hover(productsVendor.image.galleryImageDiv); + await this.click(productsVendor.image.removeGalleryImage); + } + await this.saveProduct(); + await this.toHaveCount(productsVendor.image.uploadedGalleryImage, 0); + } + + // add product short description + async addProductShortDescription(productName: string, shortDescription: string): Promise { + await this.goToProductEdit(productName); + await this.typeFrameSelector(productsVendor.shortDescription.shortDescriptionIframe, productsVendor.shortDescription.shortDescriptionHtmlBody, shortDescription); + await this.saveProduct(); + await this.toContainTextFrameLocator(productsVendor.shortDescription.shortDescriptionIframe, productsVendor.shortDescription.shortDescriptionHtmlBody, shortDescription); + } + + // add product description + async addProductDescription(productName: string, description: string): Promise { + await this.goToProductEdit(productName); + await this.typeFrameSelector(productsVendor.description.descriptionIframe, productsVendor.description.descriptionHtmlBody, description); + await this.saveProduct(); + await this.toContainTextFrameLocator(productsVendor.description.descriptionIframe, productsVendor.description.descriptionHtmlBody, description); + } + + // add product catalog mode async addProductCatalogMode(productName: string, hidePrice: boolean = false): Promise { await this.goToProductEdit(productName); diff --git a/tests/pw/tests/e2e/productsDetails.spec.ts b/tests/pw/tests/e2e/productsDetails.spec.ts index 0038c48432..ffbedaa490 100644 --- a/tests/pw/tests/e2e/productsDetails.spec.ts +++ b/tests/pw/tests/e2e/productsDetails.spec.ts @@ -156,4 +156,60 @@ test.describe('Product details functionality test', () => { await vendor.addProductTags(productName, data.product.productInfo.tags.randomTags); }); + // product cover image + + test('vendor can add product cover image', { tag: ['@lite', '@vendor'] }, async () => { + await vendor.addProductCoverImage(productName1, data.product.productInfo.images.cover); + }); + + test('vendor can update product cover image', { tag: ['@lite', '@vendor'] }, async () => { + // todo: need a product with cover image + await vendor.addProductCoverImage(productName, data.product.productInfo.images.cover); + await vendor.addProductCoverImage(productName, data.product.productInfo.images.cover, true); + }); + + test('vendor can remove product cover image', { tag: ['@lite', '@vendor'] }, async () => { + // todo: need a product with cover image + await vendor.addProductCoverImage(productName, data.product.productInfo.images.cover, true); + await vendor.removeProductCoverImage(productName); + }); + + // product gallery image + + test('vendor can add product gallery image', { tag: ['@lite', '@vendor'] }, async () => { + await vendor.addProductGalleryImages(productName1, data.product.productInfo.images.gallery); + }); + + test('vendor can update product gallery image', { tag: ['@lite', '@vendor'] }, async () => { + // todo: need a product with gallery images + await vendor.addProductGalleryImages(productName, data.product.productInfo.images.gallery); + await vendor.addProductGalleryImages(productName, data.product.productInfo.images.gallery, true); + }); + + test('vendor can remove product gallery image', { tag: ['@lite', '@vendor'] }, async () => { + // todo: need a product with gallery images + await vendor.addProductGalleryImages(productName, data.product.productInfo.images.gallery, true); + await vendor.removeProductGalleryImages(productName); + }); + + // product short description + + test('vendor can add product short description', { tag: ['@lite', '@vendor'] }, async () => { + await vendor.addProductShortDescription(productName1, data.product.productInfo.description.shortDescription); + }); + + test('vendor can update product short description', { tag: ['@lite', '@vendor'] }, async () => { + await vendor.addProductShortDescription(productName, data.product.productInfo.description.shortDescription); + }); + + test('vendor can remove product short description', { tag: ['@lite', '@vendor'] }, async () => { + await vendor.addProductShortDescription(productName, ''); + }); + + // product description + + test('vendor can update product description', { tag: ['@lite', '@vendor'] }, async () => { + await vendor.addProductDescription(productName, data.product.productInfo.description.description); + }); + });