@thepalaceproject/circulation-admin 1.7.0 → 1.8.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
@@ -139,5 +139,5 @@
139
139
  "*.{js,jsx,ts,tsx,css,md}": "prettier --write",
140
140
  "*.{js,css,md}": "prettier --write"
141
141
  },
142
- "version": "1.7.0"
142
+ "version": "1.8.0"
143
143
  }
@@ -1,6 +1,7 @@
1
1
  import * as React from "react";
2
- import { screen } from "@testing-library/react";
2
+ import { screen, waitFor } from "@testing-library/react";
3
3
  import userEvent from "@testing-library/user-event";
4
+
4
5
  import { rest } from "msw";
5
6
  import { setupServer } from "msw/node";
6
7
  import CustomLists from "../../../src/components/CustomLists";
@@ -105,4 +106,91 @@ describe("CustomLists", () => {
105
106
  items = screen.getAllByRole("treeitem");
106
107
  expect(items).toHaveLength(1);
107
108
  });
109
+
110
+ it("sends the language=all search parameter", async () => {
111
+ let searchParams = null;
112
+
113
+ server.use(
114
+ rest.get("*/search", (req, res, ctx) => {
115
+ searchParams = req.url.searchParams;
116
+
117
+ res(ctx.xml("<feed />"));
118
+ })
119
+ );
120
+
121
+ const user = userEvent.setup();
122
+
123
+ const contextProviderProps = {
124
+ csrfToken: "",
125
+ roles: [{ role: "system" }],
126
+ };
127
+
128
+ renderWithContext(
129
+ <CustomLists
130
+ csrfToken=""
131
+ editOrCreate="create"
132
+ library="testlib"
133
+ store={buildStore()}
134
+ />,
135
+ contextProviderProps
136
+ );
137
+
138
+ await user.click(screen.getByRole("textbox", { name: "filter value" }));
139
+ await user.keyboard("horror{enter}");
140
+
141
+ await waitFor(() => {
142
+ expect(searchParams.get("language")).toEqual("all");
143
+
144
+ expect(JSON.parse(searchParams.get("q"))).toEqual({
145
+ query: {
146
+ key: "genre",
147
+ value: "horror",
148
+ },
149
+ });
150
+ });
151
+ });
152
+
153
+ it("sends the language=all search parameter when a language filter is added, and places the language filter in the q parameter", async () => {
154
+ let searchParams = null;
155
+
156
+ server.use(
157
+ rest.get("*/search", (req, res, ctx) => {
158
+ searchParams = req.url.searchParams;
159
+
160
+ res(ctx.xml("<feed />"));
161
+ })
162
+ );
163
+
164
+ const user = userEvent.setup();
165
+
166
+ const contextProviderProps = {
167
+ csrfToken: "",
168
+ roles: [{ role: "system" }],
169
+ };
170
+
171
+ renderWithContext(
172
+ <CustomLists
173
+ csrfToken=""
174
+ editOrCreate="create"
175
+ library="testlib"
176
+ store={buildStore()}
177
+ />,
178
+ contextProviderProps
179
+ );
180
+
181
+ await user.click(screen.getByRole("radio", { name: "language" }));
182
+ await user.click(screen.getByRole("textbox", { name: "filter value" }));
183
+ await user.keyboard("french{enter}");
184
+
185
+ await waitFor(() => {
186
+ expect(searchParams.get("language")).toEqual("all");
187
+
188
+ expect(JSON.parse(searchParams.get("q"))).toEqual({
189
+ query: {
190
+ key: "language",
191
+ value: "french",
192
+ },
193
+ });
194
+ });
195
+ });
108
196
  });
@@ -98,6 +98,29 @@ module.exports = (env) => {
98
98
  res.setHeader("location", locationUrl.href);
99
99
  };
100
100
 
101
+ /**
102
+ * Rewrites an OpenSearch description response. This changes back-end URLs in the description to
103
+ * point to the local server instead. This is a simple find-and-replace.
104
+ *
105
+ * @param responseBuffer A buffer containing the response body.
106
+ * @param req The request.
107
+ * @returns
108
+ */
109
+ const rewriteOpenSearch = (responseBuffer, req) => {
110
+ const requestHost = req.headers.host;
111
+
112
+ if (!requestHost) {
113
+ return responseBuffer;
114
+ }
115
+
116
+ const osd = responseBuffer.toString("utf8");
117
+
118
+ return osd.replace(
119
+ new RegExp(backendUrl.origin, "g"),
120
+ `http://${requestHost}`
121
+ );
122
+ };
123
+
101
124
  /**
102
125
  * Rewrites an OPDS response. This changes back-end URLs in the feed to point to the local server
103
126
  * instead. This is a simple find-and-replace.
@@ -162,6 +185,10 @@ module.exports = (env) => {
162
185
  return rewriteHTML(responseBuffer, req);
163
186
  }
164
187
 
188
+ if (contentType.startsWith("application/opensearchdescription+xml")) {
189
+ return rewriteOpenSearch(responseBuffer, req);
190
+ }
191
+
165
192
  return responseBuffer;
166
193
  }
167
194
  ),