Skip to content

Commit

Permalink
fix: reimplement user.type as actually pasting in the meta framework (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ckbedwell committed Jul 23, 2024
1 parent 82a518d commit 84db7c4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
"sign": "npx --yes @grafana/sign-plugin@latest",
"spellcheck": "cspell -c cspell.config.json \"**/*.{ts,tsx,js,go,md,mdx,yml,yaml,json,scss,css}\"",
"test": "jest --all",
"test:accessibility": "pa11y --runner axe --reporter json http://localhost:3000/a/grafana-synthetic-monitoring-app/?page=checks > pa11y-report.json",
"test:ci": "jest --passWithNoTests --maxWorkers 4",
"test:changed": "jest --watch --onlyChanged",
"typecheck": "tsc --noEmit"
},
Expand Down
2 changes: 0 additions & 2 deletions src/components/CheckList/CheckList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ jest.mock('hooks/useNavigation', () => {
});
const useNavigationHook = require('hooks/useNavigation');

jest.setTimeout(20000);

const renderCheckList = async (checks = BASIC_CHECK_LIST, searchParams = '') => {
server.use(
apiRoute(`listChecks`, {
Expand Down
1 change: 0 additions & 1 deletion src/page/AlertingPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const useAlertsHook = require('hooks/useAlerts');
const { defaultRules } = jest.requireActual('hooks/useAlerts');
const setDefaultRules = jest.fn();
const setRules = jest.fn().mockImplementation(() => Promise.resolve({ ok: true }));
jest.setTimeout(30000);

const renderAlerting = () => {
return render(<AlertingPage />);
Expand Down
5 changes: 1 addition & 4 deletions src/page/ChecksPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ import { PLUGIN_URL_PATH } from 'components/Routing.consts';

import { CheckRouter } from './CheckRouter';

jest.setTimeout(20000);

const renderChecksPage = async () => {
const res = render(<CheckRouter />, {
path: `${PLUGIN_URL_PATH}${ROUTES.Checks}`,
route: `${PLUGIN_URL_PATH}${ROUTES.Checks}`,
});

await waitFor(() => expect(screen.getByText('Add new check')).toBeInTheDocument());
await waitFor(() => expect(screen.getByText('Add new check')).toBeInTheDocument(), { timeout: 10000 });
return res;
};

Expand Down Expand Up @@ -150,7 +148,6 @@ test(`renders retry button when unable to fetch alerts`, async () => {
);

const { user } = await renderChecksPage();
await waitFor(() => {}, { timeout: 10000 });
const refetchButton = await screen.findByLabelText('Unable to fetch alerting rules. Retry?');

server.use(
Expand Down
21 changes: 18 additions & 3 deletions src/page/__testHelpers__/checkForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { screen, within } from '@testing-library/react';
import { act, screen, waitFor, within } from '@testing-library/react';
import { UserEvent } from '@testing-library/user-event';
import { DataTestIds } from 'test/dataTestIds';
import { apiRoute, getServerRequests } from 'test/handlers';
Expand Down Expand Up @@ -33,11 +33,26 @@ export async function renderNewForm(checkType: CheckType) {
path: `${PLUGIN_URL_PATH}${ROUTES.NewCheck}/${checkTypeGroup}?checkType=${checkType}`,
});

await screen.findByTestId(DataTestIds.PAGE_READY);
await waitFor(async () => await screen.findByTestId(DataTestIds.PAGE_READY), { timeout: 10000 });

const typeButReallyPaste = async (target: Element, value: string, args?: any) => {
if (target instanceof HTMLElement) {
await act(() => {
target.focus();
});
await res.user.paste(value);
}
};

const user: UserEvent = {
...res.user,
type: typeButReallyPaste,
};

return {
...res,
read,
user,
};
}

Expand All @@ -52,7 +67,7 @@ export async function renderEditForm(check: Pick<Check, 'id' | 'settings'>) {
path: `${PLUGIN_URL_PATH}${ROUTES.EditCheck}/edit/${checkTypeGroup}/${check.id}`,
});

await screen.findByText(/^Editing/);
await waitFor(async () => await screen.findByText(/^Editing/), { timeout: 10000 });

return {
...res,
Expand Down

0 comments on commit 84db7c4

Please sign in to comment.