Skip to content
Snippets Groups Projects

fix(plugins): multiple plugins (MIN-284)

Merged mateusz-winiarczyk requested to merge MIN-284-multiple-plugins into development
2 unresolved threads
7 files
+ 130
114
Compare changes
  • Side-by-side
  • Inline
Files
7
import { StoreType } from '@/redux/store';
import { AppDispatch, RootState, StoreType } from '@/redux/store';
import {
InitialStoreState,
getReduxWrapperWithStore,
} from '@/utils/testing/getReduxWrapperWithStore';
import { render, screen } from '@testing-library/react';
import { initialStateFixture } from '@/redux/drawer/drawerFixture';
import { MockStoreEnhanced } from 'redux-mock-store';
import { getReduxStoreWithActionsListener } from '@/utils/testing/getReduxStoreActionsListener';
import { PROJECT_STATE_INITIAL_MOCK } from '@/redux/project/project.mock';
import { projectFixture } from '@/models/fixtures/projectFixture';
import { initialMapStateFixture } from '@/redux/map/map.fixtures';
import {
BACKGROUNDS_MOCK,
BACKGROUND_INITIAL_STATE_MOCK,
} from '@/redux/backgrounds/background.mock';
import { FIRST_ARRAY_ELEMENT } from '@/constants/common';
import { USER_INITIAL_STATE_MOCK } from '@/redux/user/user.mock';
import { SEARCH_STATE_INITIAL_MOCK } from '@/redux/search/search.mock';
import { TopBar } from './TopBar.component';
const renderComponent = (initialStoreState: InitialStoreState = {}): { store: StoreType } => {
@@ -22,6 +34,23 @@ const renderComponent = (initialStoreState: InitialStoreState = {}): { store: St
);
};
const renderComponentWithActionListener = (
initialStoreState: InitialStoreState = {},
): { store: MockStoreEnhanced<Partial<RootState>, AppDispatch> } => {
const { Wrapper, store } = getReduxStoreWithActionsListener(initialStoreState);
return (
render(
<Wrapper>
<TopBar />
</Wrapper>,
),
{
store,
}
);
};
describe('TopBar - component', () => {
it('Should contain search bar', () => {
renderComponent();
@@ -52,4 +81,54 @@ describe('TopBar - component', () => {
expect(isOpen).toBe(true);
expect(drawerName).toBe('overlays');
});
it('should render browse overview images button', () => {
renderComponent();
expect(screen.getByText('Browse overview images')).toBeInTheDocument();
});
it('should open overview image modal on button click', () => {
const { store } = renderComponentWithActionListener({
project: {
...PROJECT_STATE_INITIAL_MOCK,
data: projectFixture,
},
drawer: initialStateFixture,
user: USER_INITIAL_STATE_MOCK,
map: initialMapStateFixture,
search: SEARCH_STATE_INITIAL_MOCK,
backgrounds: { ...BACKGROUND_INITIAL_STATE_MOCK, data: BACKGROUNDS_MOCK },
});
const overviewImageButton = screen.getByText('Browse overview images');
overviewImageButton.click();
const actions = store.getActions();
expect(actions[FIRST_ARRAY_ELEMENT]).toStrictEqual({
payload: projectFixture.topOverviewImage?.idObject,
type: 'modal/openOverviewImagesModalById',
});
});
it('should disable button browse overview images if there are no overview images', () => {
const { store } = renderComponentWithActionListener({
user: USER_INITIAL_STATE_MOCK,
search: SEARCH_STATE_INITIAL_MOCK,
drawer: initialStateFixture,
project: {
...PROJECT_STATE_INITIAL_MOCK,
data: {
...projectFixture,
overviewImageViews: [],
},
},
map: initialMapStateFixture,
backgrounds: { ...BACKGROUND_INITIAL_STATE_MOCK, data: BACKGROUNDS_MOCK },
});
const overviewImageButton = screen.getByText('Browse overview images');
expect(overviewImageButton).toBeDisabled();
overviewImageButton.click();
const actions = store.getActions();
expect(actions).toStrictEqual([]);
});
});
Loading