Skip to content

Commit

Permalink
fixing attr test
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowee committed Jul 30, 2024
1 parent 19258cb commit 36dd31e
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 39 deletions.
134 changes: 98 additions & 36 deletions playwright/tests/attributes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import { ATTRIBUTES } from "@data/e2eTestData";
import { AttributesPage } from "@pages/attributesPage";
import { ConfigurationPage } from "@pages/configurationPage";
import { BrowserContext, expect, test } from "@playwright/test";
import { expect, test } from "@playwright/test";
import faker from "faker";

let context: BrowserContext;
test.use({ storageState: "./playwright/.auth/admin.json" });

let attributesPage: AttributesPage;
let configurationPage: ConfigurationPage;

test.beforeEach(async ({ browser }) => {
context = await browser.newContext({
storageState: "playwright/.auth/admin.json",
});

const page = await context.newPage();

test.beforeEach(({ page }) => {
attributesPage = new AttributesPage(page);
configurationPage = new ConfigurationPage(page);
});
Expand All @@ -24,9 +19,17 @@ const attributeClasses = ["PRODUCT_TYPE", "PAGE_TYPE"];

for (const attr of attributeClasses) {
for (const type of ATTRIBUTES.attributeTypesWithAbilityToAddValues.names) {
const uniqueSlug = `${attr}-${type.replace(" ", "-")}-${SALEOR_124_uuid}`;
const uniqueSlug = `${attr}-${type}-${SALEOR_124_uuid}`.replace(
/\s+/g,
"-",
);

test(`TC: SALEOR_124 User should be able to create ${attr} ${type} attribute with ability to add values, required, public @e2e @attributes`, async () => {
test(`TC: SALEOR_124 User should be able to create ${attr} ${type} attribute with ability to add values, required, public @e2e @attributes`, async ({
page,
}) => {
await page
.context()
.storageState({ path: "./playwright/.auth/admin.json" });
await configurationPage.goToConfigurationView();
await configurationPage.openAttributes();
await attributesPage.clickCreateAttributeButton();
Expand All @@ -37,7 +40,9 @@ for (const attr of attributeClasses) {
await expect(attributesPage.attrValuesSection).toBeVisible();
await attributesPage.clickAssignAttributeValueButton();
await attributesPage.addValueDialog.typeAndSaveAttributeValue();
await attributesPage.waitForNetworkIdleAfterAction(() => attributesPage.clickSaveButton());
await attributesPage.waitForNetworkIdleAfterAction(() =>
attributesPage.clickSaveButton(),
);
await attributesPage.expectSuccessBanner();
await expect(await attributesPage.attributesRows.count()).toEqual(1);
await attributesPage.valueRequiredCheckbox.waitFor({
Expand All @@ -55,9 +60,17 @@ const SALEOR_125_uuid = faker.datatype.uuid();

for (const attr of attributeClasses) {
for (const type of ATTRIBUTES.attributeTypesWithoutAbilityToAddValues.names) {
const uniqueSlug = `${attr}-${type.replace(" ", "-")}-${SALEOR_125_uuid}`;
const uniqueSlug = `${attr}-${type}-${SALEOR_125_uuid}`.replace(
/\s+/g,
"-",
);

test(`TC: SALEOR_125 User should be able to create ${attr} ${type} attribute without ability to add values, NOT required, private @e2e @attributes`, async () => {
test(`TC: SALEOR_125 User should be able to create ${attr} ${type} attribute without ability to add values, NOT required, private @e2e @attributes`, async ({
page,
}) => {
await page
.context()
.storageState({ path: "./playwright/.auth/admin.json" });
await configurationPage.goToConfigurationView();
await configurationPage.openAttributes();
await attributesPage.waitForDOMToFullyLoad();
Expand All @@ -70,14 +83,18 @@ for (const attr of attributeClasses) {
await expect(attributesPage.assignAttributeValueButton).not.toBeVisible();
await attributesPage.clickValueRequiredCheckbox();
await attributesPage.changeAttributeVisibility();
await attributesPage.waitForNetworkIdleAfterAction(() => attributesPage.clickSaveButton());
await attributesPage.waitForNetworkIdleAfterAction(() =>
attributesPage.clickSaveButton(),
);
await attributesPage.expectSuccessBanner();
await attributesPage.valueRequiredCheckbox.waitFor({
state: "visible",
timeout: 10000,
});
await expect(attributesPage.valueRequiredCheckbox).toBeEnabled();
await expect(attributesPage.attrVisibleInStorefrontSwitch).not.toBeChecked();
await expect(
attributesPage.attrVisibleInStorefrontSwitch,
).not.toBeChecked();
await expect(attributesPage.valueRequiredCheckbox).not.toBeChecked();
});
}
Expand All @@ -87,20 +104,32 @@ const SALEOR_126_uuid = faker.datatype.uuid();

for (const attr of attributeClasses) {
for (const entity of ATTRIBUTES.attributeReferencesEntities.names) {
const uniqueSlug = `${attr}-${entity.replaceAll(" ", "-")}-${SALEOR_126_uuid}`;
const uniqueSlug = `${attr}-${entity}-${SALEOR_126_uuid}`.replace(
/\s+/g,
"-",
);

test(`TC: SALEOR_126 User should be able to create ${attr} References attribute for ${entity}, NOT required, public @e2e @attributes`, async () => {
test(`TC: SALEOR_126 User should be able to create ${attr} References attribute for ${entity}, NOT required, public @e2e @attributes`, async ({
page,
}) => {
await page
.context()
.storageState({ path: "./playwright/.auth/admin.json" });
await configurationPage.goToConfigurationView();
await configurationPage.openAttributes();
await attributesPage.waitForDOMToFullyLoad();
await attributesPage.clickCreateAttributeButton();
await attributesPage.selectAttributeType(attr);
await attributesPage.typeAttributeDefaultLabel(`${attr} - REFERENCES for ${entity}`);
await attributesPage.typeAttributeDefaultLabel(
`${attr} - REFERENCES for ${entity}`,
);
await attributesPage.fillAttributeSlug(uniqueSlug);
await attributesPage.selectAttributeInputType("Reference");
await attributesPage.selectAttributeInputType("REFERENCE");
await attributesPage.selectAttributeEntityType(entity);
await attributesPage.clickValueRequiredCheckbox();
await attributesPage.waitForNetworkIdleAfterAction(() => attributesPage.clickSaveButton());
await attributesPage.waitForNetworkIdleAfterAction(() =>
attributesPage.clickSaveButton(),
);
await attributesPage.expectSuccessBanner();
await attributesPage.valueRequiredCheckbox.waitFor({
state: "visible",
Expand All @@ -116,20 +145,29 @@ for (const attr of attributeClasses) {
const productAttrWithValues = {
id: ATTRIBUTES.productAttributeWithValuesToBeUpdated.id,
name: ATTRIBUTES.productAttributeWithValuesToBeUpdated.name,
valueToBeDeleted: ATTRIBUTES.productAttributeWithValuesToBeUpdated.valueToBeDeleted,
valueToBeUpdated: ATTRIBUTES.productAttributeWithValuesToBeUpdated.valueToBeUpdated,
valueToBeDeleted:
ATTRIBUTES.productAttributeWithValuesToBeUpdated.valueToBeDeleted,
valueToBeUpdated:
ATTRIBUTES.productAttributeWithValuesToBeUpdated.valueToBeUpdated,
};
const contentAttrWithValues = {
id: ATTRIBUTES.contentAttributeWithValuesToBeUpdated.id,
name: ATTRIBUTES.contentAttributeWithValuesToBeUpdated.name,
valueToBeDeleted: ATTRIBUTES.contentAttributeWithValuesToBeUpdated.valueToBeDeleted,
valueToBeUpdated: ATTRIBUTES.contentAttributeWithValuesToBeUpdated.valueToBeUpdated,
valueToBeDeleted:
ATTRIBUTES.contentAttributeWithValuesToBeUpdated.valueToBeDeleted,
valueToBeUpdated:
ATTRIBUTES.contentAttributeWithValuesToBeUpdated.valueToBeUpdated,
};
const attributesWithValuesToBeUpdated = [productAttrWithValues, contentAttrWithValues];
const attributesWithValuesToBeUpdated = [
productAttrWithValues,
contentAttrWithValues,
];

for (const attribute of attributesWithValuesToBeUpdated) {
test(`TC: SALEOR_127 User should be able to update attribute values in existing ${attribute.name} attribute @e2e @attributes`, async () => {
await attributesPage.gotoExistingAttributePage(attribute.id, attribute.name);
await attributesPage.waitForNetworkIdleAfterAction(() =>
attributesPage.gotoExistingAttributePage(attribute.id, attribute.name),
);
await attributesPage.clickDeleteAttrValueButton(attribute.valueToBeDeleted);
await expect(attributesPage.dialog).toBeVisible();
await attributesPage.deleteAttributeValueDialog.deleteAttributeValue();
Expand All @@ -144,30 +182,49 @@ for (const attribute of attributesWithValuesToBeUpdated) {
`new value for ${attribute.name}`,
);
await attributesPage.expectSuccessBanner();
await attributesPage.waitForNetworkIdleAfterAction(() => attributesPage.clickSaveButton());
await attributesPage.waitForNetworkIdleAfterAction(() =>
attributesPage.clickSaveButton(),
);
await attributesPage.expectSuccessBanner();
await expect(attributesPage.attrValuesSection).not.toContainText(attribute.valueToBeDeleted);
await expect(attributesPage.attrValuesSection).not.toContainText(
attribute.valueToBeDeleted,
);
await expect(attributesPage.attrValuesSection).toContainText(
`updated value for ${attribute.name}`,
);
await expect(attributesPage.attrValuesSection).toContainText(`new value for ${attribute.name}`);
await expect(attributesPage.attrValuesSection).toContainText(
`new value for ${attribute.name}`,
);
});
}

for (const attr of ATTRIBUTES.attributesToBeUpdated) {
test(`TC: SALEOR_128 User should be able to edit existing ${attr.name} attribute @e2e @attributes`, async () => {
await attributesPage.gotoExistingAttributePage(attr.id, attr.name);
await attributesPage.waitForNetworkIdleAfterAction(() =>
attributesPage.gotoExistingAttributePage(attr.id, attr.name),
);
await attributesPage.attributeDefaultLabelInput.clear();
await attributesPage.typeAttributeDefaultLabel(`updated ${attr.name}`);
await attributesPage.expandMetadataSection();
await attributesPage.metadataAddFieldButton.click();
await attributesPage.fillMetadataFields("new key", "new value");
await attributesPage.clickSaveButton();
await attributesPage.waitForNetworkIdleAfterAction(() =>
attributesPage.clickSaveButton(),
);
await attributesPage.expectSuccessBanner();
await expect(attributesPage.attributeSelect).toHaveAttribute("aria-disabled", "true");
await attributesPage.expectElementIsHidden(attributesPage.successBanner);
await attributesPage.attributeSelect
.locator("div")
.getByRole("button")
.waitFor({ state: "visible" });
await expect(
attributesPage.attributeSelect.locator("div").getByRole("button"),
).toHaveAttribute("aria-disabled", "true");
await expect(attributesPage.metadataKeyInput).toHaveValue("new key");
await expect(attributesPage.metadataValueInput).toHaveValue("new value");
await expect(attributesPage.attributeDefaultLabelInput).toHaveValue(`updated ${attr.name}`);
await expect(attributesPage.attributeDefaultLabelInput).toHaveValue(
`updated ${attr.name}`,
);
});
}

Expand All @@ -183,7 +240,10 @@ const attributesToBeDeleted = [productAttribute, contentAttribute];

for (const attribute of attributesToBeDeleted) {
test(`TC: SALEOR_129 Delete a single ${attribute.name} @e2e @attributes`, async () => {
await attributesPage.gotoExistingAttributePage(attribute.id, attribute.name);
await attributesPage.gotoExistingAttributePage(
attribute.id,
attribute.name,
);
await attributesPage.clickDeleteButton();
await attributesPage.dialog.waitFor({
state: "visible",
Expand All @@ -199,7 +259,9 @@ for (const attribute of attributesToBeDeleted) {

test("TC: SALEOR_130 Bulk delete attributes @e2e @attributes", async () => {
await attributesPage.gotoListView();
await attributesPage.searchAndFindRowIndexes("e2e attribute to be bulk deleted");
await attributesPage.searchAndFindRowIndexes(
"e2e attribute to be bulk deleted",
);
await attributesPage.clickGridCell(0, 0);
await attributesPage.clickGridCell(0, 1);
await attributesPage.clickGridCell(0, 2);
Expand Down
5 changes: 2 additions & 3 deletions playwright/tests/customers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ test("TC: SALEOR_207 Issue a new gift card for the customer @e2e @customer", asy
await giftCardsPage.issueGiftCardDialog.clickOkButton();
await giftCardsPage.expectElementIsHidden(giftCardsPage.giftCardDialog);
await giftCardsPage.expectSuccessBannerMessage("Successfully created gift card");
await giftCardsPage.expectElementIsHidden(giftCardsPage.successBanner);
// await giftCardsPage.gotoGiftCardsListView();
// await giftCardsPage.waitForCanvasContainsText(`Code ending with ${code}`);
await giftCardsPage.gotoGiftCardsListView();
await giftCardsPage.waitForCanvasContainsText(`Code ending with ${code}`);
});

0 comments on commit 36dd31e

Please sign in to comment.