This repository has been archived by the owner on Jun 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 429
/
ShareJsonModal.test.tsx
102 lines (96 loc) · 3.12 KB
/
ShareJsonModal.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/** @jest-environment jsdom */
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/
//
// This file incorporates work covered by the following copyright and
// permission notice:
//
// Copyright 2018-2021 Cruise LLC
//
// This source code is licensed under the Apache License, Version 2.0,
// found at http://www.apache.org/licenses/LICENSE-2.0
// You may not use this file except in compliance with the License.
import { mount } from "enzyme";
import ThemeProvider from "@foxglove-studio/app/theme/ThemeProvider";
import ShareJsonModal from "./ShareJsonModal";
describe("<ShareJsonModal />", () => {
it("fires change callback with new valid json contents", (done) => {
const pass = (value: any) => {
expect(value).toEqual({ id: "foo" });
done();
};
const wrapper = mount(
<ThemeProvider>
<div data-modalcontainer="true">
<ShareJsonModal
onRequestClose={() => {
// no-op
}}
value={{}}
onChange={pass}
noun="layout"
/>
</div>
</ThemeProvider>,
);
const newValue = btoa(JSON.stringify({ id: "foo" }));
wrapper.find(".textarea").simulate("change", { target: { value: newValue } });
wrapper.find("Button[children='Apply']").first().simulate("click");
expect(wrapper.find(".is-danger").exists()).toBe(false);
});
it("fires no change callback and shows error if bad input is used", (done) => {
const fail = () => {
done("Change callback was fired unexpectedly");
};
const wrapper = mount(
<ThemeProvider>
<div data-modalcontainer="true">
<ShareJsonModal
onRequestClose={() => {
// no-op
}}
value={{}}
onChange={fail}
noun="layout"
/>
</div>
</ThemeProvider>,
);
const newValue = "asdlkfjasdf";
wrapper.find(".textarea").simulate("change", { target: { value: newValue } });
wrapper.find("Button[children='Apply']").first().simulate("click");
expect(wrapper.find(".is-danger").exists()).toBe(true);
done();
});
it("fires no error when resetting an actual layout to default", (done) => {
const pass = (value: any) => {
expect(value.layout).toEqual("RosOut!cuuf9u");
done();
};
const wrapper = mount(
<ThemeProvider>
<div data-modalcontainer="true">
<ShareJsonModal
onRequestClose={() => {
// no-op
}}
value={{}}
onChange={pass}
noun="layout"
/>
</div>
</ThemeProvider>,
);
const newValue = btoa(
JSON.stringify({
layout: "RosOut!cuuf9u",
savedProps: {},
globalVariables: {},
}),
);
wrapper.find(".textarea").simulate("change", { target: { value: newValue } });
wrapper.find("Button[children='Apply']").first().simulate("click");
expect(wrapper.find(".is-danger").exists()).toBe(false);
});
});