From 9c605f8d1ba4bdcb28e0caac994f99854c4ee726 Mon Sep 17 00:00:00 2001 From: Karol Date: Tue, 13 Dec 2022 08:04:54 +0100 Subject: [PATCH] [cypress] add tests for gift cards bulk create and export (#2801) * first draft * fixed data-test-id * done * restore port for cypress * change email * pr improvments * add csv check * adjustments * added check for xlsx * change name * change name * remove cy log * remove cy log * add yaml cypress mailhog var --- .github/workflows/e2e.yml | 1 + .github/workflows/test-env-deploy.yml | 1 + cypress.config.js | 2 +- .../e2e/catalog/giftCards/exportGiftCards.js | 144 ++++++++++++++++++ .../catalog/giftCards/updatingGiftCards.js | 2 +- .../catalog/giftCard/giftCardShowMore.js | 9 ++ cypress/support/api/requests/Plugins.js | 2 +- cypress/support/api/utils/users.js | 40 +++++ .../GiftCardExportDialogContent.tsx | 2 +- 9 files changed, 199 insertions(+), 4 deletions(-) create mode 100644 cypress/e2e/catalog/giftCards/exportGiftCards.js create mode 100644 cypress/elements/catalog/giftCard/giftCardShowMore.js diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 7dbebf417..9a3d5ff0b 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -123,6 +123,7 @@ jobs: CYPRESS_USER_PASSWORD: ${{ secrets.CYPRESS_USER_PASSWORD }} CYPRESS_PERMISSIONS_USERS_PASSWORD: ${{ secrets.CYPRESS_PERMISSIONS_USERS_PASSWORD }} CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} + CYPRESS_mailHogUrl: ${{ secrets.CYPRESS_MAILHOG }} COMMIT_INFO_MESSAGE: Tests triggered on PR - ${{ github.ref_name }} with selected tags CYPRESS_grepTags: ${{ needs.get-selected-tags-and-containers.outputs.tags }} with: diff --git a/.github/workflows/test-env-deploy.yml b/.github/workflows/test-env-deploy.yml index ffef47ebc..de267ea62 100644 --- a/.github/workflows/test-env-deploy.yml +++ b/.github/workflows/test-env-deploy.yml @@ -225,6 +225,7 @@ jobs: CYPRESS_USER_PASSWORD: ${{ secrets.CYPRESS_USER_PASSWORD }} CYPRESS_PERMISSIONS_USERS_PASSWORD: ${{ secrets.CYPRESS_PERMISSIONS_USERS_PASSWORD }} CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} + CYPRESS_mailHogUrl: ${{ secrets.CYPRESS_MAILHOG }} COMMIT_INFO_MESSAGE: Critical tests triggered on PR - ${{ github.ref_name }} CYPRESS_grepTags: ${{ needs.prepare-tests.outputs.tags }} with: diff --git a/cypress.config.js b/cypress.config.js index dc6bdd7ed..37080d858 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -34,7 +34,7 @@ module.exports = defineConfig({ }); return config; }, - baseUrl: "http://localhost:9000/", + baseUrl: "http://localhost:4173/", specPattern: "cypress/e2e/**/*.{js,jsx,ts,tsx}", }, }); diff --git a/cypress/e2e/catalog/giftCards/exportGiftCards.js b/cypress/e2e/catalog/giftCards/exportGiftCards.js new file mode 100644 index 000000000..2fa77e12b --- /dev/null +++ b/cypress/e2e/catalog/giftCards/exportGiftCards.js @@ -0,0 +1,144 @@ +/// +/// + +import faker from "faker"; + +import { GIFT_CARD_LIST } from "../../../elements/catalog/giftCard/giftCardList"; +import { GIFT_CARD_SHOW_MORE } from "../../../elements/catalog/giftCard/giftCardShowMore"; +import { ASSIGN_ELEMENTS_SELECTORS } from "../../../elements/shared/assign-elements-selectors.js"; +import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors"; +import { TEST_ADMIN_USER } from "../../../fixtures/users"; +import { createGiftCard } from "../../../support/api/requests/GiftCard"; +import { updatePlugin } from "../../../support/api/requests/Plugins"; +import { deleteGiftCardsWithTagStartsWith } from "../../../support/api/utils/catalog/giftCardUtils"; +import { getMailWithGiftCardExportWithAttachment } from "../../../support/api/utils/users"; +import { enterAndSelectGiftCards } from "../../../support/pages/catalog/giftCardPage"; + +describe("As an admin I want to export gift card", () => { + const startsWith = "updateGCard"; + + before(() => { + cy.clearSessionData().loginUserViaRequest(); + deleteGiftCardsWithTagStartsWith(startsWith); + }); + + beforeEach(() => { + cy.clearSessionData().loginUserViaRequest(); + }); + + it( + "should be able to export several gift cards to csv file. TC: SALEOR_1010", + { tags: ["@giftCard", "@allEnv", "@stable"] }, + () => { + const giftCard01 = `${startsWith}${faker.datatype.number()}`; + const giftCard02 = `${startsWith}${faker.datatype.number()}`; + const exportId = `${faker.datatype.number()}`; + let giftCard01hash; + let giftCard02hash; + + updatePlugin( + "mirumee.notifications.admin_email", + "csv_export_success_subject", + `Your exported {{ data_type }} data #${exportId} is ready`, + ); + createGiftCard({ + tag: giftCard01, + amount: 5, + currency: "THB", + }) + .then(hash => { + giftCard01hash = hash.id; + createGiftCard({ + tag: giftCard02, + amount: 10, + currency: "THB", + }); + }) + .then(hash2 => { + giftCard02hash = hash2.id; + enterAndSelectGiftCards([giftCard01hash, giftCard02hash]); + cy + .get(ASSIGN_ELEMENTS_SELECTORS.checkbox) + .first() + .check() + .should("be.checked") + .get(GIFT_CARD_LIST.selectedAmount) + .contains("Selected 2 items") + .should("be.visible") + .get(BUTTON_SELECTORS.showMoreButton) + .click({ force: true }) + .get(GIFT_CARD_SHOW_MORE.exportCodesMenu) + .click() + .get(GIFT_CARD_SHOW_MORE.exportAsRadioBtn.csv) + .click() + .get(BUTTON_SELECTORS.submit) + .click().confirmationMessageShouldDisappear; + getMailWithGiftCardExportWithAttachment( + TEST_ADMIN_USER.email, + `Your exported gift cards data #${exportId} is ready`, + "csv", + ).then(body => { + expect(body).to.contain(".csv"); + }); + }); + }, + ); + + it( + "should be able to export several gift cards to xlsx file. TC: SALEOR_1014", + { tags: ["@giftCard", "@allEnv", "@stable"] }, + () => { + const giftCard01 = `${startsWith}${faker.datatype.number()}`; + const giftCard02 = `${startsWith}${faker.datatype.number()}`; + const exportId = `${faker.datatype.number()}`; + let giftCard01hash; + let giftCard02hash; + + updatePlugin( + "mirumee.notifications.admin_email", + "csv_export_success_subject", + `Your exported {{ data_type }} data #${exportId} is ready`, + ); + createGiftCard({ + tag: giftCard01, + amount: 5, + currency: "THB", + }) + .then(hash => { + giftCard01hash = hash.id; + createGiftCard({ + tag: giftCard02, + amount: 10, + currency: "THB", + }); + }) + .then(hash2 => { + giftCard02hash = hash2.id; + enterAndSelectGiftCards([giftCard01hash, giftCard02hash]); + cy + .get(ASSIGN_ELEMENTS_SELECTORS.checkbox) + .first() + .check() + .should("be.checked") + .get(GIFT_CARD_LIST.selectedAmount) + .contains("Selected 2 items") + .should("be.visible") + .get(BUTTON_SELECTORS.showMoreButton) + .click({ force: true }) + .get(GIFT_CARD_SHOW_MORE.exportCodesMenu) + .click() + .get(GIFT_CARD_SHOW_MORE.exportAsRadioBtn.xlsx) + .click() + .get(BUTTON_SELECTORS.submit) + .click().confirmationMessageShouldDisappear; + getMailWithGiftCardExportWithAttachment( + TEST_ADMIN_USER.email, + `Your exported gift cards data #${exportId} is ready`, + "xlsx", + ).then(body => { + expect(body).to.contain(".xlsx"); + }); + }); + }, + ); +}); diff --git a/cypress/e2e/catalog/giftCards/updatingGiftCards.js b/cypress/e2e/catalog/giftCards/updatingGiftCards.js index aabeadc1c..c61259fad 100644 --- a/cypress/e2e/catalog/giftCards/updatingGiftCards.js +++ b/cypress/e2e/catalog/giftCards/updatingGiftCards.js @@ -97,7 +97,7 @@ describe("As an admin I want to update gift card", () => { ); it( - "should be able to delete several gift cards. TC: SALEOR_1009", + "should be able to delete several gift cards. TC: SALEOR_1011", { tags: ["@giftCard", "@allEnv", "@stable"] }, () => { const giftCard01 = `${startsWith}${faker.datatype.number()}`; diff --git a/cypress/elements/catalog/giftCard/giftCardShowMore.js b/cypress/elements/catalog/giftCard/giftCardShowMore.js new file mode 100644 index 000000000..7f459141c --- /dev/null +++ b/cypress/elements/catalog/giftCard/giftCardShowMore.js @@ -0,0 +1,9 @@ +export const GIFT_CARD_SHOW_MORE = { + settingsMenu: '[data-test-id="settingsMenuItem"]', + bulkIssueMenu: '[data-test-id="bulkIssueMenuItem"]', + exportCodesMenu: '[data-test-id="exportCodesMenuItem"]', + exportAsRadioBtn: { + csv: 'input[value="CSV"]', + xlsx: 'input[value="XLSX"]', + }, +}; diff --git a/cypress/support/api/requests/Plugins.js b/cypress/support/api/requests/Plugins.js index 0821c5f34..91b44f429 100644 --- a/cypress/support/api/requests/Plugins.js +++ b/cypress/support/api/requests/Plugins.js @@ -25,7 +25,7 @@ export function activatePlugin({ id, channel, active = true }) { const mutation = `mutation{ pluginUpdate(id: "${id}" ${channelLine} input:{ - active:${active} + active:${active},configuration: }){ errors{ field diff --git a/cypress/support/api/utils/users.js b/cypress/support/api/utils/users.js index 7422a32c6..a543362b3 100644 --- a/cypress/support/api/utils/users.js +++ b/cypress/support/api/utils/users.js @@ -126,3 +126,43 @@ export function getMailsForUser(email, i = 0) { } }); } + +export function getMailWithGiftCardExportWithAttachment( + email, + subject, + attachmentFileType, + i = 0, +) { + if (i > 5) { + throw new Error(`There is no email Gift Card export for user ${email}`); + } + return cy.mhGetMailsByRecipient(email).should(mails => { + if (!mails.length) { + cy.wait(3000); + getMailWithGiftCardExportWithAttachment( + email, + subject, + attachmentFileType, + i + 1, + ); + } else { + cy.mhGetMailsBySubject(subject).should(mailsWithSubject => { + if (!mailsWithSubject.length) { + cy.wait(10000); + getMailWithGiftCardExportWithAttachment( + email, + subject, + attachmentFileType, + i + 1, + ); + } else { + cy.wrap(mailsWithSubject) + .mhFirst() + .should("not.eq", undefined) + .mhGetBody() + .then(body => body); + } + }); + } + }); +} diff --git a/src/giftCards/GiftCardExportDialogContent/GiftCardExportDialogContent.tsx b/src/giftCards/GiftCardExportDialogContent/GiftCardExportDialogContent.tsx index 5357e22df..01858b267 100644 --- a/src/giftCards/GiftCardExportDialogContent/GiftCardExportDialogContent.tsx +++ b/src/giftCards/GiftCardExportDialogContent/GiftCardExportDialogContent.tsx @@ -148,7 +148,7 @@ const GiftCardExportDialog: React.FC & { transitionState={exportGiftCardsOpts.status} variant="primary" type="submit" - data-test="submit" + data-test-id="submit" onClick={submit} >