From 0b48b52c17d12ed6fff6c9bb214e2721343c61db Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Tue, 7 Feb 2023 17:34:22 -0500 Subject: [PATCH] add basic snapshot test --- src/app/Dashboard/Charts/ChartCard.tsx | 1 - src/test/Dashboard/Charts/ChartCard.test.tsx | 88 ++++++++++++ .../__snapshots__/ChartCard.test.tsx.snap | 127 ++++++++++++++++++ 3 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 src/test/Dashboard/Charts/ChartCard.test.tsx create mode 100644 src/test/Dashboard/Charts/__snapshots__/ChartCard.test.tsx.snap diff --git a/src/app/Dashboard/Charts/ChartCard.tsx b/src/app/Dashboard/Charts/ChartCard.tsx index 8c7ed363ff..f53e505829 100644 --- a/src/app/Dashboard/Charts/ChartCard.tsx +++ b/src/app/Dashboard/Charts/ChartCard.tsx @@ -216,7 +216,6 @@ export const ChartCard: React.FC = (props) => { }, [props.actions, expandButton, popoutButton]); const header = React.useMemo(() => { - console.log({ span: props.span, kind: props.chartKind, hasRecording }); const isWide = props.span > 4; const style = { marginBottom: isWide ? '-2.8em' : '', diff --git a/src/test/Dashboard/Charts/ChartCard.test.tsx b/src/test/Dashboard/Charts/ChartCard.test.tsx new file mode 100644 index 0000000000..92287044b5 --- /dev/null +++ b/src/test/Dashboard/Charts/ChartCard.test.tsx @@ -0,0 +1,88 @@ +/* + * Copyright The Cryostat Authors + * + * The Universal Permissive License (UPL), Version 1.0 + * + * Subject to the condition set forth below, permission is hereby granted to any + * person obtaining a copy of this software, associated documentation and/or data + * (collectively the "Software"), free of charge and under any and all copyright + * rights in the Software, and any and all patent rights owned or freely + * licensable by each licensor hereunder covering either (i) the unmodified + * Software as contributed to or provided by such licensor, or (ii) the Larger + * Works (as defined below), to deal in both + * + * (a) the Software, and + * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if + * one is included with the Software (each a "Larger Work" to which the Software + * is contributed by such licensors), + * + * without restriction, including without limitation the rights to copy, create + * derivative works of, display, perform, and distribute the Software and make, + * use, sell, offer for sale, import, export, have made, and have sold the + * Software and the Larger Work(s), and to sublicense the foregoing rights on + * either these or other terms. + * + * This license is subject to the following condition: + * The above copyright notice and either this complete permission notice or at + * a minimum a reference to the UPL must be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +jest.mock('@app/Dashboard/Charts/ChartController'); +import { ChartCard } from '@app/Dashboard/Charts/ChartCard'; +import { ChartContext } from '@app/Dashboard/Charts/ChartContext'; +import { ChartController } from '@app/Dashboard/Charts/ChartController'; +import { NotificationsContext, NotificationsInstance } from '@app/Notifications/Notifications'; +import { store } from '@app/Shared/Redux/ReduxStore'; +import { defaultServices, ServiceContext } from '@app/Shared/Services/Services'; +import React from 'react'; +import { Provider } from 'react-redux'; +import renderer, { act } from 'react-test-renderer'; +import { of } from 'rxjs'; + +const mockGrafanaDashboardUrlResponse = 'http://localhost:3000'; +jest.spyOn(defaultServices.api, 'grafanaDashboardUrl').mockReturnValueOnce(of(mockGrafanaDashboardUrlResponse)); + +const mockTarget = { connectUrl: 'service:jmx:rmi://someUrl', alias: 'fooTarget' }; +jest.spyOn(defaultServices.target, 'target').mockReturnValue(of(mockTarget)); + +const mockController = new ChartController( + defaultServices.api, + defaultServices.target, + defaultServices.notificationChannel, + defaultServices.settings +); +const mockChartContext = { + controller: mockController, +}; + +describe('', () => { + it('renders correctly', async () => { + jest.spyOn(mockController, 'hasActiveRecording').mockReturnValue(of(true)); + jest.spyOn(mockController, 'attach').mockReturnValue(of(0)); + + let tree; + await act(async () => { + tree = renderer.create( + + + + + + + + + + ); + }); + expect(tree.toJSON()).toMatchSnapshot(); + }); +}); diff --git a/src/test/Dashboard/Charts/__snapshots__/ChartCard.test.tsx.snap b/src/test/Dashboard/Charts/__snapshots__/ChartCard.test.tsx.snap new file mode 100644 index 0000000000..f38722b309 --- /dev/null +++ b/src/test/Dashboard/Charts/__snapshots__/ChartCard.test.tsx.snap @@ -0,0 +1,127 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` renders correctly 1`] = ` +
+
+
+
+
+
+ + +
+
+
+
+