Merge pull request #30 from open-craft/maxim/bb-4842-add-tests-dicussions-home

test: add simple test for DiscussionsHome [BD-38] [TNL-8696] [BB-4842]
This commit is contained in:
Kshitij Sobti
2021-11-02 11:53:02 +00:00
committed by GitHub
3 changed files with 55 additions and 6 deletions

View File

@@ -1,8 +1,3 @@
/**
* @jest-environment jsdom
*/
import React from 'react';
import {
act, fireEvent, render, screen, waitFor,
} from '@testing-library/react';

View File

@@ -0,0 +1,51 @@
import {
fireEvent, render, screen,
} from '@testing-library/react';
import { IntlProvider } from 'react-intl';
import { MemoryRouter } from 'react-router';
import { initializeMockApp } from '@edx/frontend-platform';
import { AppProvider } from '@edx/frontend-platform/react';
import { Routes } from '../../data/constants';
import { initializeStore } from '../../store';
import navigationBarMessages from '../navigation/navigation-bar/messages';
import DiscussionsHome from './DiscussionsHome';
let store;
function renderComponent() {
render(
<IntlProvider locale="en">
<AppProvider store={store}>
<MemoryRouter initialEntries={[Routes.DISCUSSIONS.PATH]}>
<DiscussionsHome />
</MemoryRouter>
</AppProvider>
</IntlProvider>,
);
}
describe('DiscussionsHome', () => {
beforeEach(async () => {
initializeMockApp({
authenticatedUser: {
userId: 3,
username: 'abc123',
administrator: true,
roles: [],
},
});
store = initializeStore();
});
it('clicking "All Topics" button renders topics view', async () => {
renderComponent();
const allTopicsButton = await screen.findByText(navigationBarMessages.allTopics.defaultMessage);
fireEvent.click(allTopicsButton);
await screen.findByTestId('topics-view');
});
});

View File

@@ -43,7 +43,10 @@ function TopicsView() {
}
return (
<div className="discussion-topics d-flex flex-column card">
<div
className="discussion-topics d-flex flex-column card"
data-testid="topics-view"
>
<TopicSearchBar />
<div className="list-group list-group-flush">
{topicElements}