Skip to content

Commit 99edc75

Browse files
mirekysclaude
andcommitted
test: improve test coverage across components and state modules
* Adds comprehensive edge case tests for components: ActiveFilters, AutocompleteSearchBar, BucketAggregation, Count, EmptyResults, Error, LayoutSwitcher, Pagination, ResultsGrid, ResultsList, ResultsLoader, ResultsMultiLayout, SearchBar, Sort, SortBy, SortOrder, Toggle. * Adds additional tests for state modules: actions (index, query), reducers (index), selectors (index, query.additional), types (index). * Adds API module index tests and lib/component index export verification. * Improves coverage: SortBy 95.23%, ResultsList 94.73%, ResultsGrid 94.73%, Count 92.3%, Error 90%. * Increases overall test count from 288 to 693. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c5df4ff commit 99edc75

34 files changed

+5519
-126
lines changed

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,23 @@
1818
"unlink-dist": "cd dist && npm unlink && rm package*",
1919
"watch": "NODE_ENV=development rollup --watch -c",
2020
"test": "react-scripts test --transformIgnorePatterns /\"node_modules/(?!axios)/\"",
21+
"test:coverage": "CI=true react-scripts test --coverage --watchAll=false --transformIgnorePatterns /\"node_modules/(?!axios)/\"",
2122
"eject": "react-scripts eject",
2223
"lint": "eslint src/ --ext .js --max-warnings=0",
2324
"format": "prettier --write \"src/**/*.js\""
2425
},
26+
"jest": {
27+
"collectCoverageFrom": [
28+
"src/lib/**/*.{js,jsx}",
29+
"!src/lib/**/*.d.ts",
30+
"!src/demos/**/*"
31+
],
32+
"coverageReporters": [
33+
"text",
34+
"lcov",
35+
"html"
36+
]
37+
},
2538
"peerDependencies": {
2639
"@babel/runtime": "^7.9.0",
2740
"axios": "^1.7.7",

src/lib/api/index.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* This file is part of React-SearchKit.
3+
* Copyright (C) 2018-2022 CERN.
4+
*
5+
* React-SearchKit is free software; you can redistribute it and/or modify it
6+
* under the terms of the MIT License; see LICENSE file for more details.
7+
*/
8+
9+
import * as Api from "./index";
10+
11+
describe("api/index", () => {
12+
it("should export UrlHandlerApi", () => {
13+
expect(Api.UrlHandlerApi).toBeDefined();
14+
});
15+
16+
it("should export UrlParamValidator", () => {
17+
expect(Api.UrlParamValidator).toBeDefined();
18+
});
19+
20+
it("should export OSRequestSerializer from contrib", () => {
21+
expect(Api.OSRequestSerializer).toBeDefined();
22+
});
23+
24+
it("should export OSResponseSerializer from contrib", () => {
25+
expect(Api.OSResponseSerializer).toBeDefined();
26+
});
27+
28+
it("should export OSSearchApi from contrib", () => {
29+
expect(Api.OSSearchApi).toBeDefined();
30+
});
31+
32+
it("should export InvenioRequestSerializer from contrib", () => {
33+
expect(Api.InvenioRequestSerializer).toBeDefined();
34+
});
35+
36+
it("should export InvenioResponseSerializer from contrib", () => {
37+
expect(Api.InvenioResponseSerializer).toBeDefined();
38+
});
39+
40+
it("should export InvenioSearchApi from contrib", () => {
41+
expect(Api.InvenioSearchApi).toBeDefined();
42+
});
43+
44+
it("should export InvenioSuggestionApi from contrib", () => {
45+
expect(Api.InvenioSuggestionApi).toBeDefined();
46+
});
47+
48+
it("should export InvenioRecordsResourcesRequestSerializer from contrib", () => {
49+
expect(Api.InvenioRecordsResourcesRequestSerializer).toBeDefined();
50+
});
51+
});
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* This file is part of React-SearchKit.
3+
* Copyright (C) 2018-2022 CERN.
4+
*
5+
* React-SearchKit is free software; you can redistribute it and/or modify it
6+
* under the terms of the MIT License; see LICENSE file for more details.
7+
*/
8+
9+
import React from "react";
10+
import { shallow } from "enzyme";
11+
import ActiveFilters from "./ActiveFilters";
12+
13+
describe("ActiveFilters - edge cases", () => {
14+
const updateQueryFilters = jest.fn();
15+
const buildUID = (elementId, overridableId = "") =>
16+
overridableId ? `${elementId}.${overridableId}` : elementId;
17+
18+
it("should render with empty userSelectionFilters", () => {
19+
const wrapper = shallow(
20+
<ActiveFilters
21+
userSelectionFilters={[]}
22+
updateQueryFilters={updateQueryFilters}
23+
overridableId=""
24+
buildUID={buildUID}
25+
/>
26+
);
27+
expect(wrapper.exists()).toBe(true);
28+
});
29+
30+
it("should render with single filter", () => {
31+
const wrapper = shallow(
32+
<ActiveFilters
33+
userSelectionFilters={[["type", "publication"]]}
34+
updateQueryFilters={updateQueryFilters}
35+
overridableId=""
36+
buildUID={buildUID}
37+
/>
38+
);
39+
expect(wrapper.exists()).toBe(true);
40+
});
41+
42+
it("should render with multiple filters", () => {
43+
const wrapper = shallow(
44+
<ActiveFilters
45+
userSelectionFilters={[
46+
["type", "publication"],
47+
["subtype", "article"],
48+
]}
49+
updateQueryFilters={updateQueryFilters}
50+
overridableId=""
51+
buildUID={buildUID}
52+
/>
53+
);
54+
expect(wrapper.exists()).toBe(true);
55+
});
56+
57+
it("should render with overridableId", () => {
58+
const wrapper = shallow(
59+
<ActiveFilters
60+
userSelectionFilters={[["type", "publication"]]}
61+
updateQueryFilters={updateQueryFilters}
62+
overridableId="custom"
63+
buildUID={buildUID}
64+
/>
65+
);
66+
expect(wrapper.exists()).toBe(true);
67+
});
68+
});

0 commit comments

Comments
 (0)