Skip to content

Commit

Permalink
update productQA tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shashwatahalder01 committed Feb 28, 2024
1 parent f788c29 commit c4de91e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e_api_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
- name: Npm install and build (Dokan-lite)
if: success()
run: |
npm ci
npm ci || npm i
npm run build
# Install test dependencies
Expand Down
4 changes: 3 additions & 1 deletion tests/pw/pages/basePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class BasePage {

// goto subUrl
async goto(subPath: string): Promise<void> {
await this.page.goto(subPath, { waitUntil: 'networkidle' });
await this.page.goto(subPath, { waitUntil: 'domcontentloaded' });
}

// go forward
Expand Down Expand Up @@ -94,6 +94,8 @@ export class BasePage {
const url = this.createUrl(subPath);
await this.page.goto(url, { waitUntil: 'networkidle' });
// await this.page.goto(url, { waitUntil: 'domcontentloaded' }); //don't work for backend
// this.page.waitForURL(url, { waitUntil: 'networkidle' })
// this.page.waitForURL(url, { waitUntil: 'domcontentloaded' })
const currentUrl = this.getCurrentUrl();
expect(currentUrl).toMatch(subPath);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/pw/pages/productQAPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ export class ProductQAPage extends BasePage {

// delete answer
async deleteAnswer(questionId: string): Promise<void> {
await this.goIfNotThere(data.subUrls.backend.dokan.questionDetails(questionId));
await this.goto(data.subUrls.backend.dokan.questionDetails(questionId));
await this.click(productQAAdmin.questionDetails.answer.deleteAnswer);
await this.clickAndWaitForResponse(data.subUrls.api.dokan.productAnswers, productQAAdmin.questionDetails.confirmAction, 204);
await this.toBeVisible(productQAAdmin.questionDetails.answerDeleteSuccessMessage);
await this.toBeVisible(productQAAdmin.questionDetails.answer.saveAnswer);

}

// delete question
Expand Down Expand Up @@ -256,7 +256,7 @@ export class ProductQAPage extends BasePage {

// delete question
async vendorDeleteQuestion(questionId: string): Promise<void> {
await this.goIfNotThere(data.subUrls.frontend.vDashboard.questionDetails(questionId));
await this.goto(data.subUrls.frontend.vDashboard.questionDetails(questionId));
await this.click(productQAVendor.questionDetails.status.deleteQuestion);
await this.clickAndWaitForResponse(data.subUrls.ajax, productQAVendor.questionDetails.confirmAction);
await this.toBeVisible(productQAVendor.questionDetails.questionDeleteSuccessMessage);
Expand Down
20 changes: 12 additions & 8 deletions tests/pw/tests/e2e/productQA.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ test.describe('Product QA functionality test', () => {
let admin: ProductQAPage;
let vendor: ProductQAPage;
let customer: ProductQAPage;
let guest: ProductQAPage;
let aPage: Page, vPage: Page, cPage: Page;
let apiUtils: ApiUtils;
let questionId: string;
let answerId: string;

test.beforeAll(async ({ browser }) => {
const adminContext = await browser.newContext(data.auth.adminAuth);
Expand All @@ -32,10 +30,11 @@ test.describe('Product QA functionality test', () => {

apiUtils = new ApiUtils(await request.newContext());
[, questionId] = await apiUtils.createProductQuestion({ ...payloads.createProductQuestion(), product_id: PRODUCT_ID }, payloads.customerAuth);
[, answerId] = await apiUtils.createProductQuestionAnswer({ ...payloads.createProductQuestionAnswer(), question_id: questionId }, payloads.vendorAuth);
await apiUtils.createProductQuestionAnswer({ ...payloads.createProductQuestionAnswer(), question_id: questionId }, payloads.adminAuth);
});

test.afterAll(async () => {
await apiUtils.deleteAllProductQuestions(payloads.adminAuth);
await aPage.close();
await vPage.close();
await cPage.close();
Expand All @@ -49,7 +48,6 @@ test.describe('Product QA functionality test', () => {
});

test('admin can view product question details @pro @exp @a', async () => {
const [, questionId] = await apiUtils.createProductQuestion({ ...payloads.createProductQuestion(), product_id: PRODUCT_ID }, payloads.customerAuth);
await admin.viewQuestionDetails(questionId);
});

Expand Down Expand Up @@ -81,14 +79,17 @@ test.describe('Product QA functionality test', () => {
});

test('admin can delete answer @pro @a', async () => {
const [, questionId] = await apiUtils.createProductQuestion({ ...payloads.createProductQuestion(), product_id: PRODUCT_ID }, payloads.customerAuth);
await apiUtils.createProductQuestionAnswer({ ...payloads.createProductQuestionAnswer(), question_id: questionId }, payloads.adminAuth);
await admin.deleteAnswer(questionId);
});

test('admin can edit (hide) question visibility @pro @a', async () => {
test('admin can edit(hide) question visibility @pro @a', async () => {
await admin.editQuestionVisibility(questionId, 'hide');
});

test('admin can edit (show) question visibility @pro @a', async () => {
test('admin can edit(show) question visibility @pro @a', async () => {
const [, questionId] = await apiUtils.createProductQuestion({ ...payloads.createProductQuestion(), product_id: PRODUCT_ID }, payloads.customerAuth);
await apiUtils.updateProductQuestion(questionId, payloads.updateProductQuestion(), payloads.adminAuth);
await admin.editQuestionVisibility(questionId, 'show');
});
Expand Down Expand Up @@ -133,10 +134,13 @@ test.describe('Product QA functionality test', () => {
});

test('vendor can delete a answer @pro @v', async () => {
const [, questionId] = await apiUtils.createProductQuestion({ ...payloads.createProductQuestion(), product_id: PRODUCT_ID }, payloads.customerAuth);
await apiUtils.createProductQuestionAnswer({ ...payloads.createProductQuestionAnswer(), question_id: questionId }, payloads.adminAuth);
await vendor.vendorDeleteAnswer(questionId);
});

test('vendor can delete a question @pro @v', async () => {
test.skip('vendor can delete a question @pro @v', async () => {
const [, questionId] = await apiUtils.createProductQuestion({ ...payloads.createProductQuestion(), product_id: PRODUCT_ID }, payloads.customerAuth);
await vendor.vendorDeleteQuestion(questionId);
});

Expand All @@ -153,7 +157,7 @@ test.describe('Product QA functionality test', () => {
// guest

test('guest customer need to sign-in/signup post question @pro @g', async ({ page }) => {
guest = new ProductQAPage(page);
const guest = new ProductQAPage(page);
await guest.postQuestion(data.predefined.simpleProduct.product1.name, data.questionAnswers);
});
});
1 change: 1 addition & 0 deletions tests/pw/utils/apiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,7 @@ export class ApiUtils {
return;
}
const allProductQuestionIds = allProductQuestions.map((o: { id: unknown }) => o.id);
// console.log(allProductQuestionIds);
const [, responseBody] = await this.put(endPoints.updateBatchProductQuestions, { data: { action: 'delete', ids: allProductQuestionIds }, headers: auth });
return responseBody;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/pw/utils/payloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3206,7 +3206,7 @@ export const payloads = {
}),

createProductQuestionAnswer: () => ({
answer: 'test answer_' + faker.string.nanoid(10),
answer: '<p>test answer_' + faker.string.nanoid(10) + '</p>',
question_id: '',
}),

Expand Down

0 comments on commit c4de91e

Please sign in to comment.