Skip to content

Commit 68383cd

Browse files
authored
fix: #405 , and both new and corrected tests for JsonGenerator (#406)
* build: add @testing-library/dom to dependancies needed to run current tests * refactor: remove unnecessary named export in JsonGenerator side effect: improves code coverage * test: correct test case in CardForm tests * test: add test to cover final branch in CardForm * test: add tests to validate output of JsonPreview introduces a test which fails as it correctly identifies an issue with the current code * fix: compare schema value types in isDataCached to invalidate cache correctly Modified isDataCached to compare both keys and value types in the schema to ensure cache invalidation when field types change. This resolves the issue where changing a field type (e.g., from int to firstName) did not update the preview as expected. * test: add test case to validate preview update after adding a field and setting its type in CardForm
1 parent 2750941 commit 68383cd

File tree

7 files changed

+284
-45
lines changed

7 files changed

+284
-45
lines changed

package-lock.json

+15-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"uuid": "^10.0.0"
7373
},
7474
"devDependencies": {
75+
"@testing-library/dom": "^10.4.0",
7576
"@testing-library/jest-dom": "^6.5.0",
7677
"@testing-library/react": "^16.0.1",
7778
"eslint": "^8",

src/app/customizer/JsonGenerator/components/CardForm.jsx

+14-14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ import { ActionButtons } from "./ActionButtons";
88
import { PreviewSection } from "./PreviewSection";
99
import { initialFields } from "./Init";
1010

11+
export const exportJsonData = (data) => {
12+
const blob = new Blob(
13+
[
14+
JSON.stringify(
15+
data,
16+
(_, value) => (typeof value === "bigint" ? value.toString() : value),
17+
2,
18+
),
19+
],
20+
{ type: "application/json" },
21+
);
22+
saveAs(blob, "WebDevTools.json");
23+
};
24+
1125
export default function CardForm({ isDarkMode }) {
1226
const [fields, setFields] = useState(initialFields());
1327
const [numRows, setNumRows] = useState(5);
@@ -46,20 +60,6 @@ export default function CardForm({ isDarkMode }) {
4660
}).filter((item) => Object.keys(item).length > 0);
4761
};
4862

49-
const exportJsonData = (data) => {
50-
const blob = new Blob(
51-
[
52-
JSON.stringify(
53-
data,
54-
(_, value) => (typeof value === "bigint" ? value.toString() : value),
55-
2,
56-
),
57-
],
58-
{ type: "application/json" },
59-
);
60-
saveAs(blob, "WebDevTools.json");
61-
};
62-
6363
const resetClicks = () => {
6464
setIsLoading(false);
6565
setPreviewClicked(false);

src/app/customizer/JsonGenerator/components/JsonPreview.jsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
export const JsonPreview = ({ data }) => (
2-
<pre className="p-3 overflow-auto break-words whitespace-pre-wrap">
2+
<pre
3+
className="p-3 overflow-auto break-words whitespace-pre-wrap"
4+
data-testid="preview-json"
5+
>
36
{JSON.stringify(
47
data,
58
(_, value) => (typeof value === "bigint" ? value.toString() : value),

src/app/customizer/JsonGenerator/page.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import CardForm from "./components/CardForm";
55
import Heroish from "./components/Heroish";
66
import { Nav } from "@/components/nav";
77

8-
export function JsonGeneratorMain() {
8+
function JsonGeneratorMain() {
99
const [isDarkMode, setIsDarkMode] = useState(false);
1010

1111
const toggleTheme = () => {

0 commit comments

Comments
 (0)