From b04ef1e4255fb96b62519c9cdc8ff06ff364969a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Mon, 7 Feb 2022 10:38:57 +0100 Subject: [PATCH] add some tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .../components/AncestryPage.tsx | 21 +++++---- .../components/JsonPage.test.tsx | 45 +++++++++++++++++++ .../components/JsonPage.tsx | 2 +- .../components/YamlPage.test.tsx | 45 +++++++++++++++++++ .../components/YamlPage.tsx | 2 +- 5 files changed, 102 insertions(+), 13 deletions(-) create mode 100644 plugins/catalog-react/src/components/InspectEntityDialog/components/JsonPage.test.tsx create mode 100644 plugins/catalog-react/src/components/InspectEntityDialog/components/YamlPage.test.tsx diff --git a/plugins/catalog-react/src/components/InspectEntityDialog/components/AncestryPage.tsx b/plugins/catalog-react/src/components/InspectEntityDialog/components/AncestryPage.tsx index cab6faff0e..b27bbe3948 100644 --- a/plugins/catalog-react/src/components/InspectEntityDialog/components/AncestryPage.tsx +++ b/plugins/catalog-react/src/components/InspectEntityDialog/components/AncestryPage.tsx @@ -27,7 +27,7 @@ import { ResponseErrorPanel, } from '@backstage/core-components'; import { useApi, useRouteRef } from '@backstage/core-plugin-api'; -import { DialogContentText, makeStyles } from '@material-ui/core'; +import { Box, DialogContentText, makeStyles } from '@material-ui/core'; import classNames from 'classnames'; import React, { useLayoutEffect, useRef, useState } from 'react'; import { useNavigate } from 'react-router'; @@ -148,7 +148,6 @@ function CustomNode({ node }: DependencyGraphTypes.RenderNodeProps) { }), ); }; - const focused = false; return ( @@ -169,7 +168,6 @@ function CustomNode({ node }: DependencyGraphTypes.RenderNodeProps) { height={iconSize} className={classNames( classes.text, - focused && 'focused', node.root ? 'secondary' : 'primary', )} /> @@ -177,7 +175,6 @@ function CustomNode({ node }: DependencyGraphTypes.RenderNodeProps) { ref={idRef} className={classNames( classes.text, - focused && 'focused', node.root ? 'secondary' : 'primary', )} y={paddedHeight / 2} @@ -211,13 +208,15 @@ export function AncestryPage(props: { entity: Entity }) { child entities that ultimately led to the current one existing. Note that this is a completely different mechanism from relations. - + + + ); } diff --git a/plugins/catalog-react/src/components/InspectEntityDialog/components/JsonPage.test.tsx b/plugins/catalog-react/src/components/InspectEntityDialog/components/JsonPage.test.tsx new file mode 100644 index 0000000000..83888a867f --- /dev/null +++ b/plugins/catalog-react/src/components/InspectEntityDialog/components/JsonPage.test.tsx @@ -0,0 +1,45 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ComponentEntity } from '@backstage/catalog-model'; +import { renderInTestApp } from '@backstage/test-utils'; +import { screen } from '@testing-library/react'; +import React from 'react'; +import { JsonPage } from './JsonPage'; + +describe('JsonPage', () => { + it('renders', async () => { + const entity: ComponentEntity = { + apiVersion: 'backstage.io/v1alpha1', + kind: 'Component', + metadata: { + namespace: 'default', + name: 'c1', + }, + spec: { + type: 'service', + lifecycle: 'production', + owner: 'ops', + }, + }; + + await renderInTestApp(); + + expect(screen.getByTestId('code-snippet')).toHaveTextContent( + '"lifecycle": "production"', + ); + }); +}); diff --git a/plugins/catalog-react/src/components/InspectEntityDialog/components/JsonPage.tsx b/plugins/catalog-react/src/components/InspectEntityDialog/components/JsonPage.tsx index cee350f62a..44dd626963 100644 --- a/plugins/catalog-react/src/components/InspectEntityDialog/components/JsonPage.tsx +++ b/plugins/catalog-react/src/components/InspectEntityDialog/components/JsonPage.tsx @@ -28,7 +28,7 @@ export function JsonPage(props: { entity: Entity }) { This is the raw entity data as received from the catalog, on JSON form. -
+
{ + it('renders', async () => { + const entity: ComponentEntity = { + apiVersion: 'backstage.io/v1alpha1', + kind: 'Component', + metadata: { + namespace: 'default', + name: 'c1', + }, + spec: { + type: 'service', + lifecycle: 'production', + owner: 'ops', + }, + }; + + await renderInTestApp(); + + expect(screen.getByTestId('code-snippet')).toHaveTextContent( + 'lifecycle: production', + ); + }); +}); diff --git a/plugins/catalog-react/src/components/InspectEntityDialog/components/YamlPage.tsx b/plugins/catalog-react/src/components/InspectEntityDialog/components/YamlPage.tsx index c876fe9edd..ad74611ec5 100644 --- a/plugins/catalog-react/src/components/InspectEntityDialog/components/YamlPage.tsx +++ b/plugins/catalog-react/src/components/InspectEntityDialog/components/YamlPage.tsx @@ -29,7 +29,7 @@ export function YamlPage(props: { entity: Entity }) { This is the raw entity data as received from the catalog, on YAML form. -
+