[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
This commit is contained in:
parent
d19427784a
commit
9c605f8d1b
9 changed files with 199 additions and 4 deletions
1
.github/workflows/e2e.yml
vendored
1
.github/workflows/e2e.yml
vendored
|
@ -123,6 +123,7 @@ jobs:
|
||||||
CYPRESS_USER_PASSWORD: ${{ secrets.CYPRESS_USER_PASSWORD }}
|
CYPRESS_USER_PASSWORD: ${{ secrets.CYPRESS_USER_PASSWORD }}
|
||||||
CYPRESS_PERMISSIONS_USERS_PASSWORD: ${{ secrets.CYPRESS_PERMISSIONS_USERS_PASSWORD }}
|
CYPRESS_PERMISSIONS_USERS_PASSWORD: ${{ secrets.CYPRESS_PERMISSIONS_USERS_PASSWORD }}
|
||||||
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
|
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
|
COMMIT_INFO_MESSAGE: Tests triggered on PR - ${{ github.ref_name }} with selected tags
|
||||||
CYPRESS_grepTags: ${{ needs.get-selected-tags-and-containers.outputs.tags }}
|
CYPRESS_grepTags: ${{ needs.get-selected-tags-and-containers.outputs.tags }}
|
||||||
with:
|
with:
|
||||||
|
|
1
.github/workflows/test-env-deploy.yml
vendored
1
.github/workflows/test-env-deploy.yml
vendored
|
@ -225,6 +225,7 @@ jobs:
|
||||||
CYPRESS_USER_PASSWORD: ${{ secrets.CYPRESS_USER_PASSWORD }}
|
CYPRESS_USER_PASSWORD: ${{ secrets.CYPRESS_USER_PASSWORD }}
|
||||||
CYPRESS_PERMISSIONS_USERS_PASSWORD: ${{ secrets.CYPRESS_PERMISSIONS_USERS_PASSWORD }}
|
CYPRESS_PERMISSIONS_USERS_PASSWORD: ${{ secrets.CYPRESS_PERMISSIONS_USERS_PASSWORD }}
|
||||||
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
|
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
|
||||||
|
CYPRESS_mailHogUrl: ${{ secrets.CYPRESS_MAILHOG }}
|
||||||
COMMIT_INFO_MESSAGE: Critical tests triggered on PR - ${{ github.ref_name }}
|
COMMIT_INFO_MESSAGE: Critical tests triggered on PR - ${{ github.ref_name }}
|
||||||
CYPRESS_grepTags: ${{ needs.prepare-tests.outputs.tags }}
|
CYPRESS_grepTags: ${{ needs.prepare-tests.outputs.tags }}
|
||||||
with:
|
with:
|
||||||
|
|
|
@ -34,7 +34,7 @@ module.exports = defineConfig({
|
||||||
});
|
});
|
||||||
return config;
|
return config;
|
||||||
},
|
},
|
||||||
baseUrl: "http://localhost:9000/",
|
baseUrl: "http://localhost:4173/",
|
||||||
specPattern: "cypress/e2e/**/*.{js,jsx,ts,tsx}",
|
specPattern: "cypress/e2e/**/*.{js,jsx,ts,tsx}",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
144
cypress/e2e/catalog/giftCards/exportGiftCards.js
Normal file
144
cypress/e2e/catalog/giftCards/exportGiftCards.js
Normal file
|
@ -0,0 +1,144 @@
|
||||||
|
/// <reference types="cypress" />
|
||||||
|
/// <reference types="../../../support"/>
|
||||||
|
|
||||||
|
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");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
|
@ -97,7 +97,7 @@ describe("As an admin I want to update gift card", () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
it(
|
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"] },
|
{ tags: ["@giftCard", "@allEnv", "@stable"] },
|
||||||
() => {
|
() => {
|
||||||
const giftCard01 = `${startsWith}${faker.datatype.number()}`;
|
const giftCard01 = `${startsWith}${faker.datatype.number()}`;
|
||||||
|
|
9
cypress/elements/catalog/giftCard/giftCardShowMore.js
Normal file
9
cypress/elements/catalog/giftCard/giftCardShowMore.js
Normal file
|
@ -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"]',
|
||||||
|
},
|
||||||
|
};
|
|
@ -25,7 +25,7 @@ export function activatePlugin({ id, channel, active = true }) {
|
||||||
|
|
||||||
const mutation = `mutation{
|
const mutation = `mutation{
|
||||||
pluginUpdate(id: "${id}" ${channelLine} input:{
|
pluginUpdate(id: "${id}" ${channelLine} input:{
|
||||||
active:${active}
|
active:${active},configuration:
|
||||||
}){
|
}){
|
||||||
errors{
|
errors{
|
||||||
field
|
field
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -148,7 +148,7 @@ const GiftCardExportDialog: React.FC<Pick<DialogProps, "onClose"> & {
|
||||||
transitionState={exportGiftCardsOpts.status}
|
transitionState={exportGiftCardsOpts.status}
|
||||||
variant="primary"
|
variant="primary"
|
||||||
type="submit"
|
type="submit"
|
||||||
data-test="submit"
|
data-test-id="submit"
|
||||||
onClick={submit}
|
onClick={submit}
|
||||||
>
|
>
|
||||||
<FormattedMessage {...messages.confirmButtonLabel} />
|
<FormattedMessage {...messages.confirmButtonLabel} />
|
||||||
|
|
Loading…
Reference in a new issue