Skip to content

Commit

Permalink
FI-2003: Fix Codecov flag settings (#394)
Browse files Browse the repository at this point in the history
* move codecov.yml

* move codecov

* turn coverage on

* wrap test render in act

* remove extra ;

* remove extra change

---------

Co-authored-by: Alyssa Wang <[email protected]>
  • Loading branch information
AlyssaWang and AlyssaWang authored Sep 25, 2023
1 parent c7ca4bf commit 2f74dc9
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 72 deletions.
19 changes: 11 additions & 8 deletions client/src/components/App/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react';
import { act } from 'react-dom/test-utils';
import { render } from '@testing-library/react';

import { vi } from 'vitest';
import { SnackbarProvider } from 'notistack';

Expand All @@ -21,16 +23,17 @@ describe('The App Root Component', () => {
vi.clearAllMocks();
});

it('sets Test Suite state on mount', () => {
it('sets Test Suite state on mount', async () => {
const getTestSuites = vi.spyOn(testSuitesApi, 'getTestSuites');
getTestSuites.mockResolvedValue(testSuites);

render(
<ThemeProvider>
<SnackbarProvider>
<App />
</SnackbarProvider>
</ThemeProvider>
await act(() =>
render(
<ThemeProvider>
<SnackbarProvider>
<App />
</SnackbarProvider>
</ThemeProvider>
)
);

expect(getTestSuites).toBeCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { act } from 'react-dom/test-utils';
import { vi } from 'vitest';
import userEvent from '@testing-library/user-event';
import { render, screen, waitFor } from '@testing-library/react';
Expand All @@ -12,15 +13,17 @@ import {
} from '~/components/RequestDetailModal/__mocked_data__/mockData';

describe('The RequestsList component', () => {
test('it orders requests based on their index', () => {
test('it orders requests based on their index', async () => {
const requests = [codeResponseWithHTML, mockedRequest];

render(
<ThemeProvider>
<SnackbarProvider>
<RequestList requests={requests} resultId="abc" updateRequest={() => {}} view="run" />
</SnackbarProvider>
</ThemeProvider>
await act(() =>
render(
<ThemeProvider>
<SnackbarProvider>
<RequestList requests={requests} resultId="abc" updateRequest={() => {}} view="run" />
</SnackbarProvider>
</ThemeProvider>
)
);

const renderedRequests = document.querySelectorAll('tbody > tr');
Expand All @@ -43,12 +46,14 @@ describe('The RequestsList component', () => {
},
});

render(
<ThemeProvider>
<SnackbarProvider>
<RequestList requests={requests} resultId="abc" updateRequest={() => {}} view="run" />
</SnackbarProvider>
</ThemeProvider>
await act(() =>
render(
<ThemeProvider>
<SnackbarProvider>
<RequestList requests={requests} resultId="abc" updateRequest={() => {}} view="run" />
</SnackbarProvider>
</ThemeProvider>
)
);

const buttons = screen.getAllByRole('button');
Expand All @@ -64,15 +69,17 @@ describe('The RequestsList component', () => {
vi.resetAllMocks();
});

test('shows details when button is clicked', () => {
test('shows details when button is clicked', async () => {
const requests = [codeResponseWithHTML, mockedRequest];

render(
<ThemeProvider>
<SnackbarProvider>
<RequestList requests={requests} resultId="abc" updateRequest={() => {}} view="run" />
</SnackbarProvider>
</ThemeProvider>
await act(() =>
render(
<ThemeProvider>
<SnackbarProvider>
<RequestList requests={requests} resultId="abc" updateRequest={() => {}} view="run" />
</SnackbarProvider>
</ThemeProvider>
)
);

const buttons = screen.getAllByRole('button');
Expand Down
57 changes: 31 additions & 26 deletions client/src/components/TestSuite/__tests__/TestSession.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { BrowserRouter } from 'react-router-dom';
import { act } from 'react-dom/test-utils';
import { SnackbarProvider } from 'notistack';
import { render, screen } from '@testing-library/react';
import { vi } from 'vitest';
Expand All @@ -10,42 +11,46 @@ import TestSessionWrapper from '../TestSessionWrapper';
import { mockedTestSession, mockedResultsList } from '../__mocked_data__/mockData';

describe('The TestSession Component', () => {
it('renders TestSessionWrapper', () => {
it('renders TestSessionWrapper', async () => {
const getCoreVersion = vi.spyOn(versionsApi, 'getCoreVersion');
getCoreVersion.mockResolvedValue('1.2.34');

render(
<BrowserRouter>
<ThemeProvider>
<SnackbarProvider>
<TestSessionWrapper />
</SnackbarProvider>
</ThemeProvider>
</BrowserRouter>
await act(() =>
render(
<BrowserRouter>
<ThemeProvider>
<SnackbarProvider>
<TestSessionWrapper />
</SnackbarProvider>
</ThemeProvider>
</BrowserRouter>
)
);

expect(getCoreVersion).toBeCalledTimes(1);
});

it('renders TestSession', () => {
it('renders TestSession', async () => {
let drawerOpen = true;

render(
<BrowserRouter>
<ThemeProvider>
<SnackbarProvider>
<TestSessionComponent
testSession={mockedTestSession}
previousResults={mockedResultsList}
initialTestRun={null}
sessionData={new Map()}
setSessionData={() => {}}
drawerOpen={drawerOpen}
toggleDrawer={() => (drawerOpen = !drawerOpen)}
/>
</SnackbarProvider>
</ThemeProvider>
</BrowserRouter>
await act(() =>
render(
<BrowserRouter>
<ThemeProvider>
<SnackbarProvider>
<TestSessionComponent
testSession={mockedTestSession}
previousResults={mockedResultsList}
initialTestRun={null}
sessionData={new Map()}
setSessionData={() => {}}
drawerOpen={drawerOpen}
toggleDrawer={() => (drawerOpen = !drawerOpen)}
/>
</SnackbarProvider>
</ThemeProvider>
</BrowserRouter>
)
);

const testSessionTitleComponentList = screen.getAllByTestId('navigable-group-item');
Expand Down
37 changes: 20 additions & 17 deletions client/src/components/TestSuite/__tests__/TestSessionSmall.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import { act } from 'react-dom/test-utils';
import { render, renderHook, screen } from '@testing-library/react';
import { SnackbarProvider } from 'notistack';
import ThemeProvider from 'components/ThemeProvider';
Expand All @@ -13,25 +14,27 @@ beforeEach(() => {
result.current.windowIsSmall = true;
});

test('renders narrow screen TestSession', () => {
test('renders narrow screen TestSession', async () => {
let drawerOpen = false;

render(
<MemoryRouter>
<ThemeProvider>
<SnackbarProvider>
<TestSessionComponent
testSession={mockedTestSession}
previousResults={mockedResultsList}
initialTestRun={null}
sessionData={new Map()}
setSessionData={() => {}}
drawerOpen={drawerOpen}
toggleDrawer={() => (drawerOpen = !drawerOpen)}
/>
</SnackbarProvider>
</ThemeProvider>
</MemoryRouter>
await act(() =>
render(
<MemoryRouter>
<ThemeProvider>
<SnackbarProvider>
<TestSessionComponent
testSession={mockedTestSession}
previousResults={mockedResultsList}
initialTestRun={null}
sessionData={new Map()}
setSessionData={() => {}}
drawerOpen={drawerOpen}
toggleDrawer={() => (drawerOpen = !drawerOpen)}
/>
</SnackbarProvider>
</ThemeProvider>
</MemoryRouter>
)
);

const testSessionTitleComponentList = screen.getAllByTestId('navigable-group-item');
Expand Down
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ coverage:

flag_management:
default_rules:
carryforward: true;
carryforward: true
individual_flags:
- name: backend
paths:
Expand Down

0 comments on commit 2f74dc9

Please sign in to comment.