@eox/itemfilter 0.14.0 → 0.14.2-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@eox/itemfilter",
3
- "version": "0.14.0",
3
+ "version": "0.14.2-dev.0",
4
4
  "type": "module",
5
5
  "devDependencies": {
6
6
  "@eox/eslint-config": "^1.0.0",
7
+ "@types/geojson": "^7946.0.14",
7
8
  "@types/lodash.debounce": "^4.0.7",
8
9
  "@typescript-eslint/eslint-plugin": "^7.0.1",
9
10
  "@typescript-eslint/parser": "^7.0.1",
@@ -29,11 +30,13 @@
29
30
  },
30
31
  "dependencies": {
31
32
  "@floating-ui/dom": "^1.5.3",
32
- "@turf/boolean-intersects": "^6.5.0",
33
- "@turf/boolean-within": "^6.5.0",
33
+ "@turf/boolean-intersects": "^7.0.0",
34
+ "@turf/boolean-within": "^7.0.0",
34
35
  "fuse.js": "^7.0.0",
35
36
  "lit": "^3.0.2",
36
37
  "lodash.debounce": "^4.0.8",
38
+ "lodash.flatmap": "^4.5.0",
39
+ "lodash.uniq": "^4.5.0",
37
40
  "toolcool-range-slider": "^4.0.27"
38
41
  }
39
42
  }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Tests the accordion functionality of the eox-itemfilter component to ensure only one accordion is open at a time.
3
+ */
4
+ const accordionTest = () => {
5
+ // Set the configuration to disable multiple filters and results expansion
6
+ cy.get("eox-itemfilter").then(($el) => {
7
+ $el[0].config.expandMultipleFilters = false;
8
+ $el[0].config.expandMultipleResults = false;
9
+ });
10
+
11
+ /**
12
+ * Checks that only one accordion is open at a time for the given selector.
13
+ *
14
+ * @param {string} selector - The CSS selector for the accordion elements.
15
+ * @param {boolean} isSubcomponent - Flag indicating if the selector targets subcomponents.
16
+ */
17
+ const checkExclusiveOpen = (selector, isSubcomponent) => {
18
+ cy.get("eox-itemfilter")
19
+ .shadow()
20
+ .within(() => {
21
+ cy.get(selector).then((accordions) => {
22
+ for (let i = 0; i < accordions.length; i++) {
23
+ const accordionToClick = isSubcomponent
24
+ ? cy
25
+ .get(selector)
26
+ .eq(i)
27
+ .find("eox-itemfilter-expandcontainer")
28
+ .shadow()
29
+ .find("details")
30
+ : cy.get(selector).eq(i).find("details");
31
+
32
+ accordionToClick.click({ multiple: true, force: true });
33
+ accordionToClick.should("have.attr", "open");
34
+
35
+ // Check that all other accordions are closed
36
+ for (let j = 0; j < accordions.length; j++) {
37
+ if (i !== j) {
38
+ const accordionToCheck = isSubcomponent
39
+ ? cy
40
+ .get(selector)
41
+ .eq(j)
42
+ .find("eox-itemfilter-expandcontainer")
43
+ .shadow()
44
+ .find("details")
45
+ : cy.get(selector).eq(j).find("details");
46
+
47
+ accordionToCheck.should("not.have.attr", "open");
48
+ }
49
+ }
50
+ }
51
+ });
52
+ });
53
+ };
54
+
55
+ // Check exclusive open behavior for filters and results
56
+ checkExclusiveOpen("ul#filters", true);
57
+ checkExclusiveOpen("ul#results");
58
+ };
59
+
60
+ export default accordionTest;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Tests the behavior of the eox-itemfilter-select component to ensure checkboxes can be toggled correctly.
3
+ */
4
+ const disableHighlightTest = () => {
5
+ cy.get("eox-itemfilter")
6
+ .shadow()
7
+ .within(() => {
8
+ cy.get("eox-itemfilter-select")
9
+ .shadow()
10
+ .within(() => {
11
+ cy.get('[type="checkbox"]').first().check();
12
+ cy.get('[type="checkbox"]').eq(1).check();
13
+ cy.get('[type="checkbox"]').first().check();
14
+ cy.get('[type="checkbox"]').first().should("be.checked");
15
+ cy.get('[type="checkbox"]').eq(1).check();
16
+ cy.get('[type="checkbox"]').eq(1).should("be.checked");
17
+ });
18
+ });
19
+ };
20
+
21
+ export default disableHighlightTest;
@@ -0,0 +1,38 @@
1
+ import testItems from "../../testItems.json";
2
+
3
+ /**
4
+ * Tests the external filtering functionality in the eox-itemfilter component.
5
+ */
6
+ const externalFilterTest = () => {
7
+ cy.intercept("https://external-api-url.com", [{ ...testItems[5] }]);
8
+
9
+ cy.get("eox-itemfilter").then(($el) => {
10
+ $el[0].config = {
11
+ ...$el[0].config,
12
+ externalFilter: (items, filter) => {
13
+ expect(filter.themes.dirty).to.be.equal($el[0].filters.themes.dirty);
14
+ return "https://external-api-url.com";
15
+ },
16
+ };
17
+ });
18
+
19
+ cy.get("eox-itemfilter")
20
+ .shadow()
21
+ .within(() => {
22
+ cy.get("[data-details=themes]").within(() => {
23
+ cy.get("eox-itemfilter-select")
24
+ .shadow()
25
+ .within(() => {
26
+ cy.get("[data-title=agriculture]").click();
27
+ });
28
+ });
29
+ cy.get("eox-itemfilter-results summary .title")
30
+ .first()
31
+ .contains(testItems[5].themes[0]);
32
+ cy.get("eox-itemfilter-results label .title")
33
+ .first()
34
+ .contains(testItems[5].title);
35
+ });
36
+ };
37
+
38
+ export default externalFilterTest;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Tests the highlighting functionality in the eox-itemfilter-results component.
3
+ * It types a search query and checks if the expected text is highlighted.
4
+ */
5
+ const highlightResultTest = () => {
6
+ cy.get("eox-itemfilter")
7
+ .shadow()
8
+ .within(() => {
9
+ cy.get("[data-cy='search']").type("white");
10
+ cy.get("eox-itemfilter-results").within(() => {
11
+ cy.get("mark.highlight").contains("White");
12
+ });
13
+ });
14
+ };
15
+
16
+ export default highlightResultTest;
@@ -0,0 +1,10 @@
1
+ // Exported test methods
2
+
3
+ export { default as searchBarTest } from "./search-bar";
4
+ export { default as searchResultTest } from "./search-result";
5
+ export { default as highlightResultTest } from "./highlight-result";
6
+ export { default as multipleResultTest } from "./multiple-filters";
7
+ export { default as disableHighlightTest } from "./disable-highlight";
8
+ export { default as accordionTest } from "./accordion";
9
+ export { default as spatialFilterTest } from "./spatial-filter";
10
+ export { default as externalFilterTest } from "./external-filter";
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Tests the behavior of the eox-itemfilter-select component to ensure multiple checkboxes can be toggled correctly.
3
+ */
4
+ const multipleResultTest = () => {
5
+ cy.get("eox-itemfilter")
6
+ .shadow()
7
+ .within(() => {
8
+ cy.get("eox-itemfilter-select")
9
+ .shadow()
10
+ .within(() => {
11
+ cy.get('[type="checkbox"]').first().check();
12
+ cy.get('[type="checkbox"]').eq(1).check();
13
+ cy.get('[type="checkbox"]').first().check();
14
+ cy.get('[type="checkbox"]').first().should("be.checked");
15
+ cy.get('[type="checkbox"]').eq(1).check();
16
+ cy.get('[type="checkbox"]').eq(1).should("be.checked");
17
+ });
18
+ });
19
+ };
20
+
21
+ export default multipleResultTest;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Tests the existence of the search bar in the eox-itemfilter component.
3
+ */
4
+ const searchBarTest = () => {
5
+ cy.get("eox-itemfilter")
6
+ .shadow()
7
+ .within(() => {
8
+ cy.get("[data-cy='search']").should("exist");
9
+ });
10
+ };
11
+
12
+ export default searchBarTest;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Tests the search functionality in the eox-itemfilter component.
3
+ * It types a search query and verifies that search results are displayed.
4
+ */
5
+ const searchResultTest = () => {
6
+ cy.get("eox-itemfilter")
7
+ .shadow()
8
+ .within(() => {
9
+ cy.get("[data-cy='search']").type("white");
10
+ cy.get("ul#results").children();
11
+ });
12
+ };
13
+
14
+ export default searchResultTest;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Tests the behavior of the checkboxes within the eox-itemfilter-select component,
3
+ * ensuring that checkboxes can be toggled correctly.
4
+ */
5
+ const spatialFilterTest = () => {
6
+ cy.get("eox-itemfilter")
7
+ .shadow()
8
+ .within(() => {
9
+ cy.get("eox-itemfilter-select")
10
+ .shadow()
11
+ .within(() => {
12
+ cy.get('[type="checkbox"]').first().check();
13
+ cy.get('[type="checkbox"]').eq(1).check();
14
+ cy.get('[type="checkbox"]').first().check();
15
+ cy.get('[type="checkbox"]').first().should("be.checked");
16
+ cy.get('[type="checkbox"]').eq(1).check();
17
+ cy.get('[type="checkbox"]').eq(1).should("be.checked");
18
+ });
19
+ });
20
+ };
21
+
22
+ export default spatialFilterTest;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Tests the custom order of items within the eox-itemfilter-select component.
3
+ * It verifies that the items are ordered according to the provided custom order.
4
+ *
5
+ * @param {Object} customOrder - An object representing the custom order, where keys are item states and values are their expected positions.
6
+ */
7
+ const customOrderTest = (customOrder) => {
8
+ cy.get("eox-itemfilter")
9
+ .shadow()
10
+ .within(() => {
11
+ cy.get("eox-itemfilter-select")
12
+ .shadow()
13
+ .within(() => {
14
+ Object.keys(customOrder).forEach((state) => {
15
+ cy.get("ul [data-identifier]")
16
+ .eq(customOrder[state])
17
+ .invoke("attr", "data-identifier")
18
+ .should("eq", state);
19
+ });
20
+ });
21
+ });
22
+ };
23
+
24
+ export default customOrderTest;
@@ -0,0 +1,6 @@
1
+ // Exported test methods
2
+
3
+ export { default as renderCheckboxTest } from "./render-checkbox";
4
+ export { default as resultsWithPreSetFiltersTest } from "./results-with-pre-set-filters";
5
+ export { default as resultPreCheckedTest } from "./result-pre-checked";
6
+ export { default as customOrderTest } from "./custom-order";
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Tests the rendering of checkboxes within the eox-itemfilter-select component.
3
+ * It verifies that the expected number of checkboxes are checked.
4
+ */
5
+ const renderCheckboxTest = () => {
6
+ cy.get("eox-itemfilter")
7
+ .shadow()
8
+ .within(() => {
9
+ cy.get("eox-itemfilter-select")
10
+ .shadow()
11
+ .within(() => {
12
+ cy.get('[type="checkbox"]:checked').should("have.length", 2);
13
+ });
14
+ });
15
+ };
16
+
17
+ export default renderCheckboxTest;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Tests that the specified result is pre-checked in the eox-itemfilter-results component.
3
+ * It verifies that the radio button at the specified index is checked and that only one radio button is checked.
4
+ *
5
+ * @param {number} selectedResultIndex - The index of the result that should be pre-checked.
6
+ */
7
+ const resultPreCheckedTest = (selectedResultIndex) => {
8
+ cy.get("eox-itemfilter")
9
+ .shadow()
10
+ .within(() => {
11
+ cy.get("eox-itemfilter-results").within(() => {
12
+ cy.get("input[data-cy=result-radio]")
13
+ .eq(selectedResultIndex)
14
+ .should("be.checked");
15
+ cy.get("input[data-cy=result-radio][checked]").should("have.length", 1);
16
+ });
17
+ });
18
+ };
19
+
20
+ export default resultPreCheckedTest;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Tests that the results in the eox-itemfilter-results component are correctly displayed
3
+ * based on the pre-set filters provided in the state.
4
+ *
5
+ * @param {Object} state - An object representing the pre-set filters, where keys are filter names.
6
+ */
7
+ const resultsWithPreSetFiltersTest = (state) => {
8
+ cy.get("eox-itemfilter")
9
+ .shadow()
10
+ .within(() => {
11
+ cy.get("eox-itemfilter-results").within(() => {
12
+ Object.keys(state).forEach((key) => {
13
+ cy.get(".details-results > summary > .title").should(
14
+ "contain.text",
15
+ key
16
+ );
17
+ cy.get(".details-results > summary > .title").should(
18
+ "contain.text",
19
+ key
20
+ );
21
+ });
22
+ cy.get(".details-results > summary > .title").should(
23
+ "have.length",
24
+ Object.keys(state).length
25
+ );
26
+ });
27
+ });
28
+ };
29
+
30
+ export default resultsWithPreSetFiltersTest;
@@ -0,0 +1,89 @@
1
+ import "../src/main";
2
+ import "./_mockMap";
3
+ import testItems from "./testItems.json";
4
+ import {
5
+ searchBarTest,
6
+ searchResultTest,
7
+ highlightResultTest,
8
+ multipleResultTest,
9
+ disableHighlightTest,
10
+ accordionTest,
11
+ spatialFilterTest,
12
+ externalFilterTest,
13
+ } from "./cases/general/";
14
+
15
+ /**
16
+ * Test suite for the EOX Item Filter component configuration.
17
+ */
18
+ describe("Item Filter Config", () => {
19
+ /**
20
+ * Runs before each test case to mount the eox-itemfilter component and configure it.
21
+ */
22
+ beforeEach(() => {
23
+ cy.mount(`<eox-itemfilter></eox-itemfilter>`)
24
+ .as("eox-itemfilter")
25
+ .then(($el) => {
26
+ const eoxItemFilter = $el[0];
27
+ // Set the configuration and items for the eox-itemfilter component
28
+ Object.assign(eoxItemFilter, {
29
+ config: {
30
+ titleProperty: "title",
31
+ filterProperties: [
32
+ {
33
+ keys: ["title", "themes"],
34
+ title: "Search",
35
+ type: "text",
36
+ expanded: true,
37
+ },
38
+ { key: "themes", expanded: true },
39
+ ],
40
+ aggregateResults: "themes",
41
+ enableHighlighting: true,
42
+ },
43
+ items: testItems,
44
+ });
45
+ });
46
+ });
47
+
48
+ /**
49
+ * Test case to verify the existence of the search bar.
50
+ */
51
+ it("should have a search bar", () => searchBarTest());
52
+
53
+ /**
54
+ * Test case to verify filtering results based on the search string.
55
+ */
56
+ it("should filter results based on search string", () => searchResultTest());
57
+
58
+ /**
59
+ * Test case to verify highlighting of results.
60
+ */
61
+ it("should highlight results", () => highlightResultTest());
62
+
63
+ /**
64
+ * Test case to verify disabling of highlight.
65
+ */
66
+ it("should disable highlight", () => disableHighlightTest());
67
+
68
+ /**
69
+ * Test case to verify allowing multiple filters.
70
+ */
71
+ it("should allow multiple filters", () => multipleResultTest());
72
+
73
+ /**
74
+ * Test case to verify that only one accordion of each type can be open at a time if configured.
75
+ */
76
+ it("should allow only one accordion of each type to be open at a time if configured", () =>
77
+ accordionTest());
78
+
79
+ /**
80
+ * Test case to verify the display of the map when the spatial filter is enabled.
81
+ */
82
+ it("should show the map when spatial filter is enabled", () =>
83
+ spatialFilterTest());
84
+
85
+ /**
86
+ * Test case to check whether itemfilter is using external filter correctly or not.
87
+ */
88
+ it("should run external filter", () => externalFilterTest());
89
+ });
@@ -0,0 +1,75 @@
1
+ import "../src/main";
2
+ import testItems from "./testItems.json";
3
+ import {
4
+ customOrderTest,
5
+ renderCheckboxTest,
6
+ resultPreCheckedTest,
7
+ resultsWithPreSetFiltersTest,
8
+ } from "./cases/state/";
9
+
10
+ describe("Item Filter Config", () => {
11
+ const state = {
12
+ agriculture: true,
13
+ health: true,
14
+ };
15
+
16
+ const customOrder = {
17
+ health: 0,
18
+ water: 1,
19
+ air: 2,
20
+ economy: 3,
21
+ agriculture: 4,
22
+ };
23
+
24
+ const selectedResultIndex = 1;
25
+
26
+ /**
27
+ * Runs before each test case to mount the eox-itemfilter component and configure it.
28
+ */
29
+ beforeEach(() => {
30
+ cy.mount(`<eox-itemfilter></eox-itemfilter>`)
31
+ .as("eox-itemfilter")
32
+ .then(($el) => {
33
+ const eoxItemFilter = $el[0];
34
+ Object.assign(eoxItemFilter, {
35
+ config: {
36
+ titleProperty: "title",
37
+ filterProperties: [
38
+ {
39
+ key: "themes",
40
+ type: "multiselect",
41
+ expanded: true,
42
+ sort: (a, b) => customOrder[a] - customOrder[b],
43
+ state,
44
+ },
45
+ ],
46
+ aggregateResults: "themes",
47
+ },
48
+ items: testItems,
49
+ selectedResult: testItems[selectedResultIndex],
50
+ });
51
+ });
52
+ });
53
+
54
+ /**
55
+ * Test case to render the checkboxes as checked
56
+ */
57
+ it("should render the checkboxes as checked", () => renderCheckboxTest());
58
+
59
+ /**
60
+ * Test case to only show the results of the pre-set filters
61
+ */
62
+ it("should only show the results of the pre-set filters", () =>
63
+ resultsWithPreSetFiltersTest(state));
64
+
65
+ /**
66
+ * Test case to render the pre-set result as checked
67
+ */
68
+ it("should render the pre-set result as checked", () =>
69
+ resultPreCheckedTest(selectedResultIndex));
70
+
71
+ /**
72
+ * Test case to have a custom order
73
+ */
74
+ it("should have a custom order", () => customOrderTest(customOrder));
75
+ });