Newer
Older
import { FIRST_ARRAY_ELEMENT } from '@/constants/common';
import {
openReactionDrawerById,
openSearchDrawerWithSelectedTab,
openSubmapsDrawer,
} from '@/redux/drawer/drawer.slice';
import { getReactionsByIds } from '@/redux/reactions/reactions.thunks';
import { StoreType } from '@/redux/store';
import {
InitialStoreState,
getReduxWrapperWithStore,
} from '@/utils/testing/getReduxWrapperWithStore';
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
import type {} from 'redux-thunk/extend-redux';
import { bioEntitiesContentFixture } from '@/models/fixtures/bioEntityContentsFixture';
import { newReactionFixture } from '@/models/fixtures/newReactionFixture';
const renderComponent = (initialStore?: InitialStoreState): { store: StoreType } => {
const { Wrapper, store } = getReduxWrapperWithStore(initialStore);

Tadeusz Miesiąc
committed
return (
render(
<Wrapper>
<Drawer />
</Wrapper>,
),
{
store,
}
);
};
describe('Drawer - component', () => {
it('should render Drawer', () => {
renderComponent();
expect(screen.getByRole('drawer')).toBeInTheDocument();
});

Tadeusz Miesiąc
committed
it('should not display drawer when its not open', () => {

Tadeusz Miesiąc
committed
expect(screen.getByRole('drawer')).not.toHaveClass('translate-x-0');
});
describe('search drawer ', () => {
it('should open drawer and display search drawer content', async () => {
const { store } = renderComponent();

Tadeusz Miesiąc
committed
expect(screen.queryByTestId('search-drawer-content')).not.toBeInTheDocument();

Tadeusz Miesiąc
committed
await act(() => {
store.dispatch(openSearchDrawerWithSelectedTab(''));

Tadeusz Miesiąc
committed
});
expect(screen.getByTestId('search-drawer-content')).toBeInTheDocument();
});
it('should close drawer after pressing close button', async () => {
const { store } = renderComponent();
await act(() => {
store.dispatch(openSearchDrawerWithSelectedTab(''));

Tadeusz Miesiąc
committed
});
expect(screen.getByTestId('search-drawer-content')).toBeInTheDocument();
const button = screen.getByRole('close-drawer-button');
await act(() => {
fireEvent.click(button);
});
expect(screen.getByRole('drawer')).not.toHaveClass('translate-x-0');
expect(screen.queryByTestId('search-drawer-content')).not.toBeInTheDocument();
});
describe('submap drawer', () => {
it('should open drawer and display submaps', async () => {
const { store } = renderComponent();
expect(screen.queryByTestId('submap-drawer')).not.toBeInTheDocument();
await act(() => {
store.dispatch(openSubmapsDrawer());
});
expect(screen.getByTestId('submap-drawer')).toBeInTheDocument();
});
});
describe('reaction drawer', () => {
it('should open drawer and display reaction', async () => {
const { id, model } = newReactionFixture;
const { store } = renderComponent({
reactions: {
loading: 'succeeded',
error: { message: '', name: '' },
},
newReactions: {
0: {
data: [newReactionFixture],
loading: 'succeeded',
error: { message: '', name: '' },
},
},
});
expect(screen.queryByTestId('reaction-drawer')).not.toBeInTheDocument();
store.dispatch(getReactionsByIds({ ids: [{ id, modelId: model }] }));
store.dispatch(openReactionDrawerById(id));
});
await waitFor(() => expect(screen.getByTestId('reaction-drawer')).toBeInTheDocument());
});
});
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
describe('bioEntity drawer', () => {
it.skip('should open drawer and display bioEntity', async () => {
const { id } = bioEntitiesContentFixture[FIRST_ARRAY_ELEMENT].bioEntity;
const { store } = renderComponent({
bioEntity: {
data: [
{
searchQueryElement: '',
loading: 'succeeded',
error: { name: '', message: '' },
data: bioEntitiesContentFixture,
},
],
loading: 'succeeded',
error: { message: '', name: '' },
},
});
expect(screen.queryByTestId('bioentity-drawer')).not.toBeInTheDocument();
await act(() => {
store.dispatch(openBioEntityDrawerById(id));
});
await waitFor(() => expect(screen.getByTestId('bioentity-drawer')).toBeInTheDocument());
});
});