fix tests broken by OverflowToolTip changes

Signed-off-by: Claire Casey <ccasey@spotify.com>
This commit is contained in:
Claire Casey
2023-02-21 13:03:25 -05:00
parent c915712447
commit c79857ae25
2 changed files with 35 additions and 9 deletions
@@ -28,6 +28,19 @@ import {
import React from 'react';
import { MembersListCard } from './MembersListCard';
// Mock needed because jsdom doesn't correctly implement box-sizing
// https://github.com/ShinyChang/React-Text-Truncate/issues/70
// https://stackoverflow.com/questions/71916701/how-to-mock-a-react-function-component-that-takes-a-ref-prop
jest.mock('react-text-truncate', () => {
const { forwardRef } = jest.requireActual('react');
return {
__esModule: true,
default: forwardRef((props: any, ref: any) => (
<div ref={ref}>{props.text}</div>
)),
};
});
describe('MemberTab Test', () => {
const groupEntity: GroupEntity = {
apiVersion: 'backstage.io/v1alpha1',
@@ -95,7 +108,7 @@ describe('MemberTab Test', () => {
expect(
rendered.getByText('tara-macgovern@example.com'),
).toBeInTheDocument();
expect(rendered.getByText('Tara MacGovern')).toHaveAttribute(
expect(rendered.getByText('Tara MacGovern').closest('a')).toHaveAttribute(
'href',
'/catalog/foo-bar/user/tara.macgovern',
);
@@ -120,6 +120,19 @@ const getEntitiesMock = (
} as GetEntitiesResponse);
};
// Mock needed because jsdom doesn't correctly implement box-sizing
// https://github.com/ShinyChang/React-Text-Truncate/issues/70
// https://stackoverflow.com/questions/71916701/how-to-mock-a-react-function-component-that-takes-a-ref-prop
jest.mock('react-text-truncate', () => {
const { forwardRef } = jest.requireActual('react');
return {
__esModule: true,
default: forwardRef((props: any, ref: any) => (
<div ref={ref}>{props.text}</div>
)),
};
});
describe('OwnershipCard', () => {
const groupEntity: GroupEntity = {
apiVersion: 'backstage.io/v1alpha1',
@@ -177,19 +190,19 @@ describe('OwnershipCard', () => {
expect(getByText('OPENAPI')).toBeInTheDocument();
expect(
queryByText(getByText('OPENAPI').parentElement!, '1'),
queryByText(getByText('OPENAPI').closest('a')!, '1'),
).toBeInTheDocument();
expect(getByText('SERVICE')).toBeInTheDocument();
expect(
queryByText(getByText('SERVICE').parentElement!, '1'),
queryByText(getByText('SERVICE').closest('a')!, '1'),
).toBeInTheDocument();
expect(getByText('LIBRARY')).toBeInTheDocument();
expect(
queryByText(getByText('LIBRARY').parentElement!, '1'),
queryByText(getByText('LIBRARY').closest('a')!, '1'),
).toBeInTheDocument();
expect(getByText('SYSTEM')).toBeInTheDocument();
expect(
queryByText(getByText('SYSTEM').parentElement!, '1'),
queryByText(getByText('SYSTEM').closest('a')!, '1'),
).toBeInTheDocument();
});
@@ -215,17 +228,17 @@ describe('OwnershipCard', () => {
expect(getByText('SYSTEM')).toBeInTheDocument();
expect(
queryByText(getByText('SYSTEM').parentElement!, '1'),
queryByText(getByText('SYSTEM').closest('a')!, '1'),
).toBeInTheDocument();
expect(
queryByText(getByText('SYSTEM').parentElement!, 'System'),
queryByText(getByText('SYSTEM').closest('a')!, 'System'),
).not.toBeInTheDocument();
expect(getByText('OPENAPI')).toBeInTheDocument();
expect(
queryByText(getByText('OPENAPI').parentElement!, '1'),
queryByText(getByText('OPENAPI').closest('a')!, '1'),
).toBeInTheDocument();
expect(
queryByText(getByText('OPENAPI').parentElement!, 'API'),
queryByText(getByText('OPENAPI').closest('a')!, 'API'),
).toBeInTheDocument();
expect(() => getByText('LIBRARY')).toThrow();
});