some more progress toward ubiquitous eslint-plugin-testing-library

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2022-11-21 13:05:30 +01:00
parent b0b2a5ddb0
commit 3bd6cc7c55
41 changed files with 390 additions and 393 deletions
@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { screen } from '@testing-library/react';
import React from 'react';
import { renderInTestApp } from '@backstage/test-utils';
import { AttendeeChip } from './AttendeeChip';
import { EventAttendee, ResponseStatus } from '../../api';
@@ -27,8 +27,8 @@ describe('<AttendeeChip />', () => {
email,
responseStatus: ResponseStatus.needsAction,
};
const { queryByText } = await renderInTestApp(<AttendeeChip user={user} />);
expect(queryByText(email)).toBeInTheDocument();
await renderInTestApp(<AttendeeChip user={user} />);
expect(screen.getByText(email)).toBeInTheDocument();
});
it('renders accepted icon', async () => {
@@ -37,8 +37,8 @@ describe('<AttendeeChip />', () => {
email,
responseStatus: ResponseStatus.accepted,
};
const { getByTestId } = await renderInTestApp(<AttendeeChip user={user} />);
expect(getByTestId('accepted-icon')).toBeInTheDocument();
await renderInTestApp(<AttendeeChip user={user} />);
expect(screen.getByTestId('accepted-icon')).toBeInTheDocument();
});
it('renders declined icon', async () => {
@@ -47,7 +47,7 @@ describe('<AttendeeChip />', () => {
email,
responseStatus: ResponseStatus.declined,
};
const { getByTestId } = await renderInTestApp(<AttendeeChip user={user} />);
expect(getByTestId('declined-icon')).toBeInTheDocument();
await renderInTestApp(<AttendeeChip user={user} />);
expect(screen.getByTestId('declined-icon')).toBeInTheDocument();
});
});
@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { fireEvent } from '@testing-library/react';
import { screen } from '@testing-library/react';
import React from 'react';
import { renderInTestApp } from '@backstage/test-utils';
import { CalendarEvent } from './CalendarEvent';
describe('<CalendarEvent />', () => {
@@ -42,16 +42,14 @@ describe('<CalendarEvent />', () => {
};
it('should render calendar event', async () => {
const { queryByText, queryByTestId } = await renderInTestApp(
<CalendarEvent event={event} />,
);
expect(queryByText(event.summary)).toBeInTheDocument();
expect(queryByTestId('calendar-event-zoom-link')).toBeInTheDocument();
expect(queryByTestId('calendar-event-zoom-link')).toHaveAttribute(
await renderInTestApp(<CalendarEvent event={event} />);
expect(screen.getByText(event.summary)).toBeInTheDocument();
expect(screen.getByTestId('calendar-event-zoom-link')).toBeInTheDocument();
expect(screen.queryByTestId('calendar-event-zoom-link')).toHaveAttribute(
'href',
event.conferenceData.entryPoints[0].uri,
);
expect(queryByTestId('calendar-event-time')).toBeInTheDocument();
expect(screen.getByTestId('calendar-event-time')).toBeInTheDocument();
});
it('should not render time for events longer than 1 day', async () => {
@@ -64,20 +62,18 @@ describe('<CalendarEvent />', () => {
date: '2022-02-19',
},
};
const { queryByText, queryByTestId } = await renderInTestApp(
<CalendarEvent event={allDayEvent} />,
);
expect(queryByText(allDayEvent.summary)).toBeInTheDocument();
expect(queryByTestId('calendar-event-time')).not.toBeInTheDocument();
await renderInTestApp(<CalendarEvent event={allDayEvent} />);
expect(screen.getByText(allDayEvent.summary)).toBeInTheDocument();
expect(screen.queryByTestId('calendar-event-time')).not.toBeInTheDocument();
});
it('should show popover on click', async () => {
const { queryByTestId, getByTestId } = await renderInTestApp(
<CalendarEvent event={event} />,
);
expect(queryByTestId('calendar-event-popover')).not.toBeInTheDocument();
await renderInTestApp(<CalendarEvent event={event} />);
expect(
screen.queryByTestId('calendar-event-popover'),
).not.toBeInTheDocument();
fireEvent.click(getByTestId('calendar-event'));
expect(queryByTestId('calendar-event-popover')).toBeInTheDocument();
fireEvent.click(screen.getByTestId('calendar-event'));
expect(screen.getByTestId('calendar-event-popover')).toBeInTheDocument();
});
});
@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { screen } from '@testing-library/react';
import { renderInTestApp } from '@backstage/test-utils';
import { CalendarEventPopoverContent } from './CalendarEventPopoverContent';
describe('<CalendarEventPopoverContent />', () => {
@@ -35,21 +35,18 @@ describe('<CalendarEventPopoverContent />', () => {
};
it('should render event info', async () => {
const { queryByText, queryByTestId } = await renderInTestApp(
<CalendarEventPopoverContent event={event} />,
);
expect(queryByText(event.summary)).toBeInTheDocument();
expect(queryByText(event.description)).toBeInTheDocument();
expect(queryByText(event.attendees[0].email)).toBeInTheDocument();
expect(queryByText('Join Zoom Meeting')).toBeInTheDocument();
expect(queryByText('Join Zoom Meeting')?.closest('a')).toHaveAttribute(
'href',
event.conferenceData.entryPoints[0].uri,
);
expect(queryByTestId('open-calendar-link')).toHaveAttribute(
await renderInTestApp(<CalendarEventPopoverContent event={event} />);
expect(screen.getByText(event.summary)).toBeInTheDocument();
expect(screen.getByText(event.description)).toBeInTheDocument();
expect(screen.getByText(event.attendees[0].email)).toBeInTheDocument();
expect(screen.getByText('Join Zoom Meeting')).toBeInTheDocument();
expect(
screen.queryByText('Join Zoom Meeting')?.closest('a'),
).toHaveAttribute('href', event.conferenceData.entryPoints[0].uri);
expect(screen.queryByTestId('open-calendar-link')).toHaveAttribute(
'href',
event.htmlLink,
);
expect(queryByText(event.attendees[0].email)).toBeInTheDocument();
expect(screen.getByText(event.attendees[0].email)).toBeInTheDocument();
});
});