Skip to content

Commit

Permalink
test(React): Home page tests (#2184)
Browse files Browse the repository at this point in the history
Co-authored-by: John Joyce <john@acryl.io>
  • Loading branch information
jjoyce0510 and jjoyce0510 authored Mar 7, 2021
1 parent 2e8a0ce commit 3537b2e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
4 changes: 2 additions & 2 deletions datahub-web-react/src/Mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Dataset, EntityType, PlatformType } from './types.generated';

const user1 = {
username: 'sdas',
urn: 'urn:li:corpuser:2',
urn: 'urn:li:corpuser:1',
type: EntityType.CorpUser,
info: {
email: 'sdas@domain.com',
Expand Down Expand Up @@ -251,7 +251,7 @@ export const mocks = [
},
result: {
data: {
dataset: {
corpUser: {
...user1,
},
},
Expand Down
1 change: 1 addition & 0 deletions datahub-web-react/src/app/home/HomePageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const HomePageHeader = () => {
<Input.Search
placeholder={SearchCfg.SEARCH_BAR_PLACEHOLDER_TEXT}
onSearch={(value: string) => onSearch(value)}
data-testid="search-input"
/>
</AutoComplete>

Expand Down
55 changes: 55 additions & 0 deletions datahub-web-react/src/app/home/__tests__/HomePage.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react';
import { render, waitFor, fireEvent } from '@testing-library/react';
import { MockedProvider } from '@apollo/client/testing';
import { HomePage } from '../HomePage';
import { mocks } from '../../../Mocks';
import TestPageContainer from '../../../utils/test-utils/TestPageContainer';

describe('HomePage', () => {
it('renders', () => {
render(
<MockedProvider mocks={mocks} addTypename={false}>
<TestPageContainer>
<HomePage />
</TestPageContainer>
</MockedProvider>,
);
});

it('renders greeting message', async () => {
const { getByText } = render(
<MockedProvider mocks={mocks} addTypename={false}>
<TestPageContainer>
<HomePage />
</TestPageContainer>
</MockedProvider>,
);
await waitFor(() => expect(getByText('Welcome back, .')).toBeInTheDocument());
});

it('renders browsable entities', async () => {
const { getByText } = render(
<MockedProvider mocks={mocks} addTypename={false}>
<TestPageContainer>
<HomePage />
</TestPageContainer>
</MockedProvider>,
);
await waitFor(() => expect(getByText('Datasets')).toBeInTheDocument());
});

it('renders autocomplete results', async () => {
const { getByTestId, queryByTitle } = render(
<MockedProvider mocks={mocks} addTypename={false}>
<TestPageContainer>
<HomePage />
</TestPageContainer>
</MockedProvider>,
);
const searchInput = getByTestId('search-input');
fireEvent.change(searchInput, { target: { value: 't' } });

await waitFor(() => expect(queryByTitle('The Great Test Dataset')).toBeInTheDocument());
await waitFor(() => expect(queryByTitle('Some other test')).toBeInTheDocument());
});
});
2 changes: 0 additions & 2 deletions datahub-web-react/src/utils/test-utils/TestPageContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useMemo } from 'react';
import { MemoryRouter } from 'react-router';

import { DatasetEntity } from '../../app/entity/dataset/DatasetEntity';
import { UserEntity } from '../../app/entity/user/User';
import EntityRegistry from '../../app/entity/EntityRegistry';
Expand All @@ -20,7 +19,6 @@ export function getTestEntityRegistry() {

export default ({ children, initialEntries }: Props) => {
const entityRegistry = useMemo(() => getTestEntityRegistry(), []);

return (
<MemoryRouter initialEntries={initialEntries}>
<EntityRegistryContext.Provider value={entityRegistry}>{children}</EntityRegistryContext.Provider>
Expand Down

0 comments on commit 3537b2e

Please sign in to comment.