From 2491055292371bc579a318a01a25408515b29a12 Mon Sep 17 00:00:00 2001
From: wojteknowacki <124166231+wojteknowacki@users.noreply.github.com>
Date: Mon, 24 Jul 2023 09:47:11 +0200
Subject: [PATCH] test for updating presets (#3977)
---
.../products/productsList/productPresets.js | 34 +++++++++++++++++--
cypress/elements/shared/presetsAndSearch.js | 2 ++
cypress/fixtures/index.js | 1 +
cypress/fixtures/localStorage/keys.js | 3 ++
.../support/pages/catalog/presetsAndSearch.js | 9 +++++
.../FilterPresetsSelect/FilterPresetItem.tsx | 4 ++-
6 files changed, 50 insertions(+), 3 deletions(-)
create mode 100644 cypress/fixtures/localStorage/keys.js
diff --git a/cypress/e2e/products/productsList/productPresets.js b/cypress/e2e/products/productsList/productPresets.js
index 428391e4b..e9f46f3b1 100644
--- a/cypress/e2e/products/productsList/productPresets.js
+++ b/cypress/e2e/products/productsList/productPresets.js
@@ -2,10 +2,14 @@
///
import { PRODUCTS_LIST } from "../../../elements/catalog/products/products-list";
-import { urlList } from "../../../fixtures/urlList";
+import { SEARCH } from "../../../elements/shared";
+import { LOCAL_STORAGE_KEYS, urlList } from "../../../fixtures/";
import { ensureCanvasStatic } from "../../../support/customCommands/sharedElementsOperations/canvas";
import {
addPresetWithName,
+ clickSavedPresetContain,
+ clickShowSavedPresetsButton,
+ clickUpdatePresetButton,
confirmActivePresetName,
confirmGridRowsContainsText,
searchItems,
@@ -14,13 +18,14 @@ import {
describe("As a user I should be able to save selected filters with search queries under the given name", () => {
beforeEach(() => {
cy.clearSessionData().loginUserViaRequest();
- cy.visit(urlList.products);
});
it(
"should be able to add preset. TC: SALEOR_3802",
{ tags: ["@productsList", "@allEnv", "@stable"] },
() => {
+ cy.visit(urlList.products);
+
ensureCanvasStatic(PRODUCTS_LIST.dataGridTable).then(() => {
cy.assertCanvasRowsNumber(PRODUCTS_LIST.dataGridTable, 21);
});
@@ -34,4 +39,29 @@ describe("As a user I should be able to save selected filters with search querie
});
},
);
+ it(
+ "should be able to update preset. TC: SALEOR_2713",
+ { tags: ["@productsList", "@allEnv", "@stable"] },
+ () => {
+ const searchQuery = "bean";
+ // space is needed since we add second part of query into input
+ const updatedSearchQuery = " juice";
+ window.localStorage.setItem(
+ LOCAL_STORAGE_KEYS.keys.productPresets,
+ `[{"data":"query=${searchQuery}","name":"${searchQuery}"}]`,
+ );
+ cy.visit(urlList.products);
+ ensureCanvasStatic(PRODUCTS_LIST.dataGridTable);
+ clickShowSavedPresetsButton();
+ clickSavedPresetContain(searchQuery);
+ cy.get(SEARCH.searchInput).click().type(updatedSearchQuery);
+ ensureCanvasStatic(PRODUCTS_LIST.dataGridTable);
+ clickUpdatePresetButton();
+ ensureCanvasStatic(PRODUCTS_LIST.dataGridTable).then(() => {
+ expect(
+ localStorage.getItem(LOCAL_STORAGE_KEYS.keys.productPresets),
+ ).to.contains(`query=${searchQuery}%20${updatedSearchQuery.trim()}`);
+ });
+ },
+ );
});
diff --git a/cypress/elements/shared/presetsAndSearch.js b/cypress/elements/shared/presetsAndSearch.js
index e70e88466..99ef7db38 100644
--- a/cypress/elements/shared/presetsAndSearch.js
+++ b/cypress/elements/shared/presetsAndSearch.js
@@ -3,6 +3,8 @@ export const PRESETS = {
presetNameTextField: '[data-test-id="preset-name-text-field"]',
savePresetNameButton: '[data-test-id="save-preset-button"]',
activePresetName: '[data-test-id="show-saved-filters-button"]',
+ savedPreset: '[data-test-id="preset"]',
+ updatePresetButton: '[data-test-id="update-preset-button"]',
};
export const SEARCH = {
searchInput: "[data-test-id='search-input']",
diff --git a/cypress/fixtures/index.js b/cypress/fixtures/index.js
index 8c3355f74..2ff875026 100644
--- a/cypress/fixtures/index.js
+++ b/cypress/fixtures/index.js
@@ -4,3 +4,4 @@ export { urlList } from "./urlList";
export { ONE_PERMISSION_USERS, TEST_ADMIN_USER } from "./users";
export { MESSAGES } from "./messages";
export * as LOCAL_STORAGE_FOR_COLUMN_PICKER from "./localStorage/columnPickerMocks";
+export * as LOCAL_STORAGE_KEYS from "./localStorage/keys";
diff --git a/cypress/fixtures/localStorage/keys.js b/cypress/fixtures/localStorage/keys.js
new file mode 100644
index 000000000..0ceb80fe2
--- /dev/null
+++ b/cypress/fixtures/localStorage/keys.js
@@ -0,0 +1,3 @@
+export const keys = {
+ productPresets: "productPresets",
+};
diff --git a/cypress/support/pages/catalog/presetsAndSearch.js b/cypress/support/pages/catalog/presetsAndSearch.js
index 4703b870b..b3276a160 100644
--- a/cypress/support/pages/catalog/presetsAndSearch.js
+++ b/cypress/support/pages/catalog/presetsAndSearch.js
@@ -28,3 +28,12 @@ export function confirmGridRowsContainsText(name) {
export function confirmActivePresetName(name) {
return cy.get(PRESETS.activePresetName).should("contain.text", name);
}
+export function clickShowSavedPresetsButton() {
+ cy.get(PRESETS.activePresetName).click();
+}
+export function clickSavedPresetContain(presetName) {
+ cy.get(PRESETS.savedPreset).contains(presetName).click();
+}
+export function clickUpdatePresetButton() {
+ cy.get(PRESETS.updatePresetButton).click();
+}
diff --git a/src/components/FilterPresetsSelect/FilterPresetItem.tsx b/src/components/FilterPresetsSelect/FilterPresetItem.tsx
index 92a0e824b..b6f862017 100644
--- a/src/components/FilterPresetsSelect/FilterPresetItem.tsx
+++ b/src/components/FilterPresetsSelect/FilterPresetItem.tsx
@@ -1,6 +1,7 @@
-import { Box, Dropdown, List, RemoveIcon, Text } from "@saleor/macaw-ui/next";
import React, { MouseEvent } from "react";
+import { Box, Dropdown, List, RemoveIcon, Text } from "@saleor/macaw-ui/next";
+
interface FilterPresetItemProps {
onSelect: (e: MouseEvent) => void;
onRemove: () => void;
@@ -30,6 +31,7 @@ export const FilterPresetItem = ({
onClick={onSelect}
onMouseOver={() => setHasHover(true)}
onMouseLeave={() => setHasHover(false)}
+ data-test-id="preset"
>
{children}