Skip to content

Commit

Permalink
add test for open activities button
Browse files Browse the repository at this point in the history
  • Loading branch information
Bricks666 committed Jul 6, 2024
1 parent bef7e88 commit d0f0b9c
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`features/activities/open-all-room-activities/open-all-room-activities > should render link looks like button 1`] = `
<a
class="MuiButtonBase-root MuiButton-root MuiButton-text MuiButton-textPrimary MuiButton-sizeMedium MuiButton-textSizeMedium MuiButton-root MuiButton-text MuiButton-textPrimary MuiButton-sizeMedium MuiButton-textSizeMedium css-1e6y48t-MuiButtonBase-root-MuiButton-root"
href="/rooms/123/activities"
tabindex="0"
>
blocks.last_activities.actions.open
<span
class="MuiTouchRipple-root css-8je8zh-MuiTouchRipple-root"
/>
</a>
`;
16 changes: 0 additions & 16 deletions src/features/activities/open-all-room-activities/model.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { RenderResult, fireEvent, render } from '@testing-library/react';
import { RouterProvider } from 'atomic-router-react';
import { Scope, allSettled, fork } from 'effector';
import { Provider } from 'effector-react';
import { createMemoryHistory } from 'history';
import { beforeEach, describe, expect, test } from 'vitest';

import { router, routes } from '@/shared/configs';

import { OpenAllRoomActivities } from './open-all-room-activities';

describe('features/activities/open-all-room-activities/open-all-room-activities', () => {
let wrapper: RenderResult;
let scope: Scope;
const roomId = 123;

const createComponent = () => {
wrapper = render(
<Provider value={scope}>
<RouterProvider router={router}>
<OpenAllRoomActivities />
</RouterProvider>
</Provider>
);
};
const findLink = () =>
wrapper.getByRole('link', { name: 'blocks.last_activities.actions.open', });

beforeEach(async () => {
scope = fork();
await allSettled(router.setHistory, {
scope,
params: createMemoryHistory(),
});
await allSettled(routes.room.tasks.open, {
scope,
params: { id: roomId, },
});
});

test('should render link looks like button', () => {
createComponent();

expect(findLink()).toMatchSnapshot();
});

test('should navigate to activities room on click', () => {
createComponent();

const link = findLink();

fireEvent.click(link);

expect(scope.getState(router.$path)).toBe(`/rooms/${roomId}/activities`);
});
});

0 comments on commit d0f0b9c

Please sign in to comment.