@eox/itemfilter 0.2.2 → 0.3.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.
@@ -0,0 +1,161 @@
1
+ import { EOxItemFilter } from "../src/main";
2
+ import testItems from "./testItems.json";
3
+
4
+ describe("Item Filter Config", () => {
5
+ beforeEach(() => {
6
+ cy.visit("/elements/itemfilter/test/general.html");
7
+ cy.get("eox-itemfilter").should(($el) => {
8
+ const EOxItemFilter = <EOxItemFilter>$el[0];
9
+ // default config
10
+ EOxItemFilter.config = {
11
+ titleProperty: "title",
12
+ filterProperties: ["themes"],
13
+ aggregateResults: "themes",
14
+ enableSearch: true,
15
+ enableHighlighting: true,
16
+ fuseConfig: {
17
+ keys: ["title", "description", "themes"],
18
+ },
19
+ // onSelect: (item: any) => {
20
+ // console.log(item);
21
+ // },
22
+ // matchAllWhenEmpty: true,
23
+ // exclusiveFilters: true,
24
+ };
25
+ EOxItemFilter.apply(testItems);
26
+ });
27
+ });
28
+
29
+ it("should have a search bar", () => {
30
+ cy.get("eox-itemfilter")
31
+ .shadow()
32
+ .find("input")
33
+ .should("not.have.css", "display", "none");
34
+ });
35
+
36
+ it("should filter results based on search string", () => {
37
+ cy.get("eox-itemfilter")
38
+ .shadow()
39
+ .within(() => {
40
+ cy.get("[data-cy='search']").type("white");
41
+ cy.get("ul#results").children();
42
+ });
43
+ });
44
+
45
+ it("should highlight results", () => {
46
+ cy.get("eox-itemfilter")
47
+ .shadow()
48
+ .within(() => {
49
+ cy.get("[data-cy='search']").type("white");
50
+ cy.get("mark.highlight").contains("White");
51
+ });
52
+ });
53
+
54
+ it("should disable highlight", () => {
55
+ cy.get("eox-itemfilter").should(($el) => {
56
+ const EOxItemFilter = <EOxItemFilter>$el[0];
57
+ EOxItemFilter.config.enableHighlighting = false;
58
+ });
59
+ cy.get("eox-itemfilter")
60
+ .shadow()
61
+ .within(() => {
62
+ cy.get("[data-cy='search']").type("white");
63
+ cy.get("mark.highlight").should("not.exist");
64
+ });
65
+ });
66
+
67
+ it("should not have a search bar", () => {
68
+ cy.get("eox-itemfilter").should(($el) => {
69
+ const EOxItemFilter = <EOxItemFilter>$el[0];
70
+ // have to replace the entire config, otherwise enableSearch = false doesn't work
71
+ EOxItemFilter.config = {
72
+ titleProperty: "title",
73
+ filterProperties: ["themes"],
74
+ aggregateResults: "themes",
75
+ enableSearch: false,
76
+ enableHighlighting: true,
77
+ fuseConfig: {
78
+ keys: ["title", "description", "themes"],
79
+ },
80
+ // onSelect: (item: any) => {
81
+ // console.log(item);
82
+ // },
83
+ // matchAllWhenEmpty: true,
84
+ // exclusiveFilters: true,
85
+ };
86
+ EOxItemFilter.apply(testItems);
87
+ });
88
+ cy.get("eox-itemfilter")
89
+ .shadow()
90
+ .find("input[type='text']")
91
+ .should("not.exist");
92
+ });
93
+
94
+ it("should allow multiple filters", () => {
95
+ cy.get("eox-itemfilter")
96
+ .shadow()
97
+ .within(() => {
98
+ cy.get("[data-cy='expand-button']").click();
99
+ cy.get('[type="checkbox"]').first().check();
100
+ cy.get('[type="checkbox"]').eq(1).check();
101
+ cy.get('[type="checkbox"]').first().check().should("be.checked");
102
+ cy.get('[type="checkbox"]').eq(1).check().should("be.checked");
103
+ });
104
+ });
105
+
106
+ it("should allow only one filter", () => {
107
+ cy.get("eox-itemfilter").should(($el) => {
108
+ const EOxItemFilter = <EOxItemFilter>$el[0];
109
+ // have to replace the entire config, otherwise exclusiveFilters = true doesn't work
110
+ EOxItemFilter.config = {
111
+ titleProperty: "title",
112
+ filterProperties: ["themes"],
113
+ aggregateResults: "themes",
114
+ enableSearch: false,
115
+ enableHighlighting: true,
116
+ fuseConfig: {
117
+ keys: ["title", "description", "themes"],
118
+ },
119
+ // onSelect: (item: any) => {
120
+ // console.log(item);
121
+ // },
122
+ // matchAllWhenEmpty: true,
123
+ exclusiveFilters: true,
124
+ };
125
+ EOxItemFilter.apply(testItems);
126
+ });
127
+ cy.get("eox-itemfilter")
128
+ .shadow()
129
+ .within(() => {
130
+ cy.get("[data-cy='expand-button']").click();
131
+ cy.get('[type="radio"]').first().check();
132
+ cy.get('[type="radio"]').eq(1).check();
133
+ cy.get('[type="radio"]').first().should("not.be.checked");
134
+ });
135
+ });
136
+
137
+ it("should clear all filters", () => {
138
+ cy.get("eox-itemfilter")
139
+ .shadow()
140
+ .within(() => {
141
+ cy.get("[data-cy='search']").type("city");
142
+ cy.get("[data-cy='expand-button']").click();
143
+ cy.get("#details-filter")
144
+ .find('[type="checkbox"]')
145
+ .then(($value) => {
146
+ [...Array($value.length)].map((_, i) => {
147
+ cy.get('[type="checkbox"]').eq(i).check();
148
+ });
149
+ });
150
+ cy.get("[data-cy='filter-reset']").click();
151
+ cy.get("[data-cy='search']").should("have.value", "");
152
+ cy.get("#details-filter")
153
+ .find('[type="checkbox"]')
154
+ .then(($value) => {
155
+ [...Array($value.length)].map((_, i) => {
156
+ cy.get('[type="checkbox"]').eq(i).should("not.be.checked");
157
+ });
158
+ });
159
+ });
160
+ });
161
+ });
@@ -12,17 +12,36 @@ describe("Item Filter", () => {
12
12
  EOxItemFilter.config = {
13
13
  titleProperty: "title",
14
14
  filterProperties: ["themes"],
15
- aggregateResults: "themes",
15
+ // aggregateResults: "themes",
16
16
  enableSearch: true,
17
17
  enableHighlighting: true,
18
+ // showResults: false,
18
19
  fuseConfig: {
19
20
  keys: ["title", "description", "themes"],
20
21
  },
21
- onSelect: (item: any) => {
22
- console.log(item);
23
- },
22
+ // onSelect: (item: any) => {
23
+ // console.log(item);
24
+ // },
24
25
  // matchAllWhenEmpty: true,
25
26
  // exclusiveFilters: true,
27
+ // externalSearch: (input, filters) => {
28
+ // const base =
29
+ // "https://resource-catalogue.testing.opensciencedata.esa.int/collections/metadata:main/items?type=collection&f=json";
30
+ // if (filters) {
31
+ // let filterString = "";
32
+ // Object.keys(filters).forEach((filter) =>
33
+ // Object.entries(filters[filter]).forEach(([key, value]) => {
34
+ // if (value) {
35
+ // filterString += `${filter.replace("s", "")}:${key}`;
36
+ // }
37
+ // })
38
+ // );
39
+ // console.log(filterString);
40
+ // return `${base}&q=${input}&filter=keywords%20ILIKE%20%27%${filterString}%%27`;
41
+ // } else {
42
+ // return `${base}&q=${input}`;
43
+ // }
44
+ // },
26
45
  };
27
46
  EOxItemFilter.apply(testItems);
28
47
  });
@@ -0,0 +1,24 @@
1
+ import { EOxItemFilter } from "../src/main";
2
+ import testItems from "./testItems.json";
3
+
4
+ describe("Item Filter", () => {
5
+ beforeEach(() => {
6
+ cy.visit("/elements/itemfilter/test/general.html");
7
+ });
8
+
9
+ it("loads the itemfilter", () => {
10
+ cy.get("eox-itemfilter").should(($el) => {
11
+ const EOxItemFilter = <EOxItemFilter>$el[0];
12
+ EOxItemFilter.style.height = "100px";
13
+ EOxItemFilter.style.border = "1px solid grey";
14
+ EOxItemFilter.config = {
15
+ titleProperty: "title",
16
+ filterProperties: ["themes", "code"],
17
+ enableSearch: true,
18
+ showResults: false,
19
+ inlineMode: true,
20
+ };
21
+ EOxItemFilter.apply(testItems);
22
+ });
23
+ });
24
+ });
@@ -0,0 +1,21 @@
1
+ import { EOxItemFilter } from "../src/main";
2
+ import testItems from "./testItems.json";
3
+
4
+ describe("Item Filter", () => {
5
+ beforeEach(() => {
6
+ cy.visit("/elements/itemfilter/test/styledResults.html");
7
+ });
8
+
9
+ it("loads the itemfilter", () => {
10
+ cy.get("eox-itemfilter").should(($el) => {
11
+ const EOxItemFilter = <EOxItemFilter>$el[0];
12
+ EOxItemFilter.config = {
13
+ titleProperty: "title",
14
+ filterProperties: ["themes", "code"],
15
+ enableSearch: true,
16
+ inlineMode: true,
17
+ };
18
+ EOxItemFilter.apply(testItems);
19
+ });
20
+ });
21
+ });
@@ -0,0 +1,45 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <style>
5
+ html,
6
+ body,
7
+ eox-itemfilter {
8
+ padding: 0;
9
+ margin: 0;
10
+ width: 100%;
11
+ height: 100%;
12
+ }
13
+ eox-itemfilter::part(results) {
14
+ display: flex;
15
+ flex-wrap: wrap;
16
+ margin: -12px;
17
+ }
18
+ eox-itemfilter::part(result) {
19
+ border: thin solid #0003;
20
+ border-radius: 4px;
21
+ padding: 16px;
22
+ margin: 12px;
23
+ font-size: 0.875rem;
24
+ font-weight: 500;
25
+ letter-spacing: 0.007;
26
+ line-height: 1.375rem;
27
+ font-family: sans-serif;
28
+ }
29
+ eox-itemfilter::part(result)::before {
30
+ display: block;
31
+ content: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><title>earth</title><path d="M17.9,17.39C17.64,16.59 16.89,16 16,16H15V13A1,1 0 0,0 14,12H8V10H10A1,1 0 0,0 11,9V7H13A2,2 0 0,0 15,5V4.59C17.93,5.77 20,8.64 20,12C20,14.08 19.2,15.97 17.9,17.39M11,19.93C7.05,19.44 4,16.08 4,12C4,11.38 4.08,10.78 4.21,10.21L9,15V16A2,2 0 0,0 11,18M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z" /></svg>');
32
+ width: 20px;
33
+ height: 20px;
34
+ margin-bottom: 10px;
35
+ }
36
+ </style>
37
+ <script type="module" defer src="../dist/eox-itemfilter.js"></script>
38
+ </head>
39
+ <body>
40
+ <eox-itemfilter>
41
+ <h4 slot="filterstitle">Filter</h4>
42
+ <h4 slot="resultstitle">Results</h4>
43
+ </eox-itemfilter>
44
+ </body>
45
+ </html>