[gcalendar] fix tests

Signed-off-by: Tomasz Szuba <tszuba@box.com>
This commit is contained in:
Tomasz Szuba
2022-08-17 18:02:06 +02:00
parent a69ac5b63a
commit 75e9a7652b
3 changed files with 12 additions and 12 deletions
@@ -15,7 +15,7 @@
*/
import { sortBy } from 'lodash';
import { DateTime } from 'luxon';
import React, { useEffect, useState } from 'react';
import React, { useState } from 'react';
import { InfoCard, Progress } from '@backstage/core-components';
import { useAnalytics } from '@backstage/core-plugin-api';
@@ -35,6 +35,7 @@ import { CalendarEvent } from './CalendarEvent';
import { CalendarSelect } from './CalendarSelect';
import { SignInContent } from './SignInContent';
import { getStartDate } from './util';
import useAsync from 'react-use/lib/useAsync';
export const CalendarCard = () => {
const [date, setDate] = useState(DateTime.now());
@@ -47,9 +48,7 @@ export const CalendarCard = () => {
const { isSignedIn, isInitialized, signIn } = useSignIn();
useEffect(() => {
signIn(true);
}, [signIn]);
useAsync(async () => signIn(true), [signIn]);
const { isLoading: isCalendarLoading, data: calendars = [] } =
useCalendarsQuery({
@@ -58,7 +58,6 @@ export const CalendarSelect = ({
calendars,
}: CalendarSelectProps) => {
const classes = useStyles();
return (
<FormControl className={classes.formControl}>
<Select
@@ -75,7 +75,7 @@ describe('<HomePageCalendar />', () => {
</TestApiProvider>,
);
expect(rendered.queryByText('Sign in')).toBeInTheDocument();
expect(await rendered.findByText('Sign in')).toBeInTheDocument();
});
it('should render empty card', async () => {
@@ -90,8 +90,8 @@ describe('<HomePageCalendar />', () => {
</TestApiProvider>,
);
expect(rendered.queryByText('No events')).toBeInTheDocument();
expect(rendered.queryByText('Go to Calendar')).toBeInTheDocument();
expect(await rendered.findByText('No events')).toBeInTheDocument();
expect(await rendered.findByText('Go to Calendar')).toBeInTheDocument();
});
it('should select primary calendar by default', async () => {
@@ -106,7 +106,9 @@ describe('<HomePageCalendar />', () => {
</TestApiProvider>,
);
expect(rendered.queryByText(primaryCalendar.summary)).toBeInTheDocument();
expect(
await rendered.findByText(primaryCalendar.summary),
).toBeInTheDocument();
expect(
rendered.queryByText(nonPrimaryCalendar.summary),
).not.toBeInTheDocument();
@@ -124,12 +126,12 @@ describe('<HomePageCalendar />', () => {
</TestApiProvider>,
);
expect(await rendered.findAllByText('Test event')).toHaveLength(2);
expect(rendered.queryByText('No events')).not.toBeInTheDocument();
expect(rendered.queryAllByText('Test event')).toHaveLength(2);
});
it('should select stored calendar', async () => {
mockStorage
await mockStorage
.forBucket(gcalendarPlugin.getId())
.set('google_calendars_selected', [nonPrimaryCalendar.id]);
@@ -146,7 +148,7 @@ describe('<HomePageCalendar />', () => {
);
expect(
rendered.queryByText(nonPrimaryCalendar.summary),
await rendered.findByText(nonPrimaryCalendar.summary),
).toBeInTheDocument();
expect(
rendered.queryByText(primaryCalendar.summary),