Skip to content

Commit

Permalink
chore: fix next integration (#8093)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackySoul authored Dec 17, 2024
1 parent 2c787f6 commit 8301011
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 140 deletions.
46 changes: 22 additions & 24 deletions packages/vkui/src/components/Calendar/Calendar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fireEvent, render, screen } from '@testing-library/react';
import { format } from 'date-fns';
import { baselineComponent, userEvent } from '../../testing/utils';
import { baselineComponent, setNodeEnv, userEvent } from '../../testing/utils';
import { Calendar } from './Calendar';

const targetDate = new Date('2023-09-20T07:40:00.000Z');
Expand All @@ -14,9 +14,6 @@ const dayTestId = (day: Date) => format(day, 'dd.MM.yyyy');
describe('Calendar', () => {
baselineComponent(Calendar);

beforeEach(() => (process.env.NODE_ENV = 'development'));
afterEach(() => (process.env.NODE_ENV = 'test'));

it('fires onChange', () => {
const onChange = jest.fn();

Expand Down Expand Up @@ -103,30 +100,31 @@ describe('Calendar', () => {
expect(screen.getByTestId(monthDropdownTestId(8))).toBeInTheDocument();
});

it('check calls Calendar DEV errors', () => {
const consoleErrorMock = jest.spyOn(console, 'error').mockImplementation();

process.env.NODE_ENV = 'development';
describe('DEV errors', () => {
beforeEach(() => setNodeEnv('development'));
afterEach(() => setNodeEnv('test'));

const { rerender } = render(<Calendar value={lastDayDate} disablePickers={false} size="s" />);
it('check calls Calendar', () => {
const consoleErrorMock = jest.spyOn(console, 'error').mockImplementation();

expect(consoleErrorMock).toHaveBeenCalledTimes(1);
expect(consoleErrorMock).toHaveBeenCalledWith(
"%c[VKUI/Calendar] Нельзя включить селекты выбора месяца/года, если размер календаря 's'",
undefined,
);
const { rerender } = render(<Calendar value={lastDayDate} disablePickers={false} size="s" />);

rerender(<Calendar value={lastDayDate} enableTime size="s" />);

expect(consoleErrorMock).toHaveBeenCalledTimes(2);
expect(consoleErrorMock.mock.calls).toEqual([
[
expect(consoleErrorMock).toHaveBeenCalledTimes(1);
expect(consoleErrorMock).toHaveBeenCalledWith(
"%c[VKUI/Calendar] Нельзя включить селекты выбора месяца/года, если размер календаря 's'",
undefined,
],
["%c[VKUI/Calendar] Нельзя включить выбор времени, если размер календаря 's'", undefined],
]);

process.env.NODE_ENV = 'test';
);

rerender(<Calendar value={lastDayDate} enableTime size="s" />);

expect(consoleErrorMock).toHaveBeenCalledTimes(2);
expect(consoleErrorMock.mock.calls).toEqual([
[
"%c[VKUI/Calendar] Нельзя включить селекты выбора месяца/года, если размер календаря 's'",
undefined,
],
["%c[VKUI/Calendar] Нельзя включить выбор времени, если размер календаря 's'", undefined],
]);
});
});
});
50 changes: 27 additions & 23 deletions packages/vkui/src/components/Checkbox/Checkbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
import { getDocumentBody } from '../../lib/dom';
import { Platform } from '../../lib/platform';
import { baselineComponent, fakeTimers, userEvent } from '../../testing/utils';
import { baselineComponent, fakeTimers, setNodeEnv, userEvent } from '../../testing/utils';
import { ConfigProvider } from '../ConfigProvider/ConfigProvider';
import { Checkbox } from './Checkbox';

Expand Down Expand Up @@ -63,27 +63,31 @@ describe('Checkbox', () => {
expect(screen.getByRole<HTMLInputElement>('checkbox').indeterminate).toBeTruthy();
});

it('check dev errors', () => {
process.env.NODE_ENV = 'development';
const errorStub = jest.spyOn(console, 'error');
render(
<>
<Checkbox defaultIndeterminate={true} defaultChecked={true} />
<Checkbox indeterminate={true} checked={true} />
<Checkbox defaultChecked={true} checked={true} />
</>,
);
expect(errorStub.mock.calls[0]).toEqual([
'%c[VKUI/Checkbox] defaultIndeterminate и defaultChecked не могут быть true одновременно',
undefined,
]);
expect(errorStub.mock.calls[1]).toEqual([
'%c[VKUI/Checkbox] indeterminate и checked не могут быть true одновременно',
undefined,
]);
expect(errorStub.mock.calls[2]).toEqual([
'%c[VKUI/Checkbox] defaultChecked и checked не могут быть true одновременно',
undefined,
]);
describe('DEV errors', () => {
beforeEach(() => setNodeEnv('development'));
afterEach(() => setNodeEnv('test'));

it('check calls Checkbox', () => {
const errorStub = jest.spyOn(console, 'error');
render(
<>
<Checkbox defaultIndeterminate={true} defaultChecked={true} />
<Checkbox indeterminate={true} checked={true} />
<Checkbox defaultChecked={true} checked={true} />
</>,
);
expect(errorStub.mock.calls[0]).toEqual([
'%c[VKUI/Checkbox] defaultIndeterminate и defaultChecked не могут быть true одновременно',
undefined,
]);
expect(errorStub.mock.calls[1]).toEqual([
'%c[VKUI/Checkbox] indeterminate и checked не могут быть true одновременно',
undefined,
]);
expect(errorStub.mock.calls[2]).toEqual([
'%c[VKUI/Checkbox] defaultChecked и checked не могут быть true одновременно',
undefined,
]);
});
});
});
41 changes: 24 additions & 17 deletions packages/vkui/src/components/CustomSelect/CustomSelect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { useState } from 'react';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { noop } from '@vkontakte/vkjs';
import type { Placement, useFloating } from '../../lib/floating';
import { baselineComponent, userEvent, waitForFloatingPosition } from '../../testing/utils';
import {
baselineComponent,
setNodeEnv,
userEvent,
waitForFloatingPosition,
} from '../../testing/utils';
import { Avatar } from '../Avatar/Avatar';
import { CustomSelectOption } from '../CustomSelectOption/CustomSelectOption';
import { CustomSelect, type CustomSelectRenderOption, type SelectProps } from './CustomSelect';
Expand Down Expand Up @@ -1416,25 +1421,27 @@ describe('CustomSelect', () => {
expect(onChange).toHaveBeenCalledTimes(0);
});

it('check dev error when use different type of values', () => {
process.env.NODE_ENV = 'development';
const errorStub = jest.spyOn(global.console, 'error').mockImplementationOnce(noop);
describe('DEV errors', () => {
beforeEach(() => setNodeEnv('development'));
afterEach(() => setNodeEnv('test'));

render(
<CustomSelect
options={[
{ value: 0, label: 'Mike' },
{ value: '1', label: 'Josh' },
]}
/>,
);
it('check error when use different type of values', () => {
const errorStub = jest.spyOn(global.console, 'error').mockImplementationOnce(noop);

expect(errorStub).toHaveBeenCalledWith(
'%c[VKUI/CustomSelect] Некоторые значения ваших опций имеют разные типы. onChange всегда возвращает строковый тип.',
undefined,
);
render(
<CustomSelect
options={[
{ value: 0, label: 'Mike' },
{ value: '1', label: 'Josh' },
]}
/>,
);

process.env.NODE_ENV = 'test';
expect(errorStub).toHaveBeenCalledWith(
'%c[VKUI/CustomSelect] Некоторые значения ваших опций имеют разные типы. onChange всегда возвращает строковый тип.',
undefined,
);
});
});

it('checks CustomSelect placement class for borders when dropdown is opened and closed during placement change', async () => {
Expand Down
41 changes: 22 additions & 19 deletions packages/vkui/src/components/Gallery/Gallery.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
import { noop } from '@vkontakte/vkjs';
import { baselineComponent } from '../../testing/utils';
import { baselineComponent, setNodeEnv } from '../../testing/utils';
import type { AlignType } from '../../types';
import { ANIMATION_DURATION } from '../CarouselBase/constants';
import { type BaseGalleryProps } from '../CarouselBase/types';
Expand Down Expand Up @@ -594,26 +594,29 @@ describe('Gallery', () => {
checkActiveSlide(0);
});

it('check dev error when slides width incorrect', () => {
process.env.NODE_ENV = 'development';
const onChange = jest.fn();
const warn = jest.spyOn(console, 'warn').mockImplementation(noop);
describe('DEV errors', () => {
beforeEach(() => setNodeEnv('development'));
afterEach(() => setNodeEnv('test'));

it('check dev error when slides width incorrect', () => {
const onChange = jest.fn();
const warn = jest.spyOn(console, 'warn').mockImplementation(noop);

setup({
looped: true,
defaultSlideIndex: 0,
slideWidth: 40,
containerWidth: 200,
viewPortWidth: 200,
onChange,
});

setup({
looped: true,
defaultSlideIndex: 0,
slideWidth: 40,
containerWidth: 200,
viewPortWidth: 200,
onChange,
expect(warn).toHaveBeenCalledWith(
'%c[VKUI/Gallery] Ширины слайдов недостаточно для корректной работы свойства "looped". Пожалуйста, сделайте её больше.',
undefined,
);
warn.mockRestore();
});

expect(warn).toHaveBeenCalledWith(
'%c[VKUI/Gallery] Ширины слайдов недостаточно для корректной работы свойства "looped". Пожалуйста, сделайте её больше.',
undefined,
);
warn.mockRestore();
process.env.NODE_ENV = 'test';
});
});

Expand Down
25 changes: 14 additions & 11 deletions packages/vkui/src/components/GridAvatar/GridAvatar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen } from '@testing-library/react';
import { noop } from '@vkontakte/vkjs';
import { IconExampleForBadgeBasedOnImageBaseSize } from '../../testing/icons';
import { baselineComponent } from '../../testing/utils';
import { baselineComponent, setNodeEnv } from '../../testing/utils';
import { GridAvatar, type GridAvatarProps, MAX_GRID_LENGTH } from './GridAvatar';
import styles from './GridAvatar.module.css';
import gridAvatarBadgeStyles from './GridAvatarBadge/GridAvatarBadge.module.css';
Expand All @@ -24,16 +24,19 @@ const getGridAvatarItemEls = () => getGridAvatarRootEl().querySelectorAll(`.${st
describe(GridAvatar, () => {
baselineComponent(GridAvatar);

it(`should not show more than ${MAX_GRID_LENGTH} items in grid`, () => {
process.env.NODE_ENV = 'development';
const error = jest.spyOn(console, 'error').mockImplementation(noop);
render(<GridAvatarTest src={['#01', '#02', '#03', '#04', '#05']} />);
expect(error).toHaveBeenCalledWith(
`%c[VKUI/GridAvatar] Длина массива src (5) больше максимальной (4)`,
undefined,
);
expect(getGridAvatarItemEls().length).toBe(MAX_GRID_LENGTH);
process.env.NODE_ENV = 'test';
describe('DEV errors', () => {
beforeEach(() => setNodeEnv('development'));
afterEach(() => setNodeEnv('test'));

it(`should not show more than ${MAX_GRID_LENGTH} items in grid`, () => {
const error = jest.spyOn(console, 'error').mockImplementation(noop);
render(<GridAvatarTest src={['#01', '#02', '#03', '#04', '#05']} />);
expect(error).toHaveBeenCalledWith(
`%c[VKUI/GridAvatar] Длина массива src (5) больше максимальной (4)`,
undefined,
);
expect(getGridAvatarItemEls().length).toBe(MAX_GRID_LENGTH);
});
});
});

Expand Down
30 changes: 16 additions & 14 deletions packages/vkui/src/components/Group/Group.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render, screen } from '@testing-library/react';
import { classNames, noop } from '@vkontakte/vkjs';
import { ModalContext } from '../../context/ModalContext';
import type { SizeTypeValues } from '../../lib/adaptivity';
import { baselineComponent } from '../../testing/utils';
import { baselineComponent, setNodeEnv } from '../../testing/utils';
import { AdaptivityContext } from '../AdaptivityProvider/AdaptivityContext';
import {
AppRootContext,
Expand Down Expand Up @@ -130,20 +130,22 @@ describe('Group', () => {
}
});

it('check DEV errors', () => {
process.env.NODE_ENV = 'development';
const error = jest.spyOn(console, 'warn').mockImplementation(noop);
render(
<Group role="tabpanel">
<div />
</Group>,
);
describe('DEV errors', () => {
beforeEach(() => setNodeEnv('development'));
afterEach(() => setNodeEnv('test'));

expect(error).toHaveBeenCalledWith(
'%c[VKUI/Group] При использовании роли "tabpanel" необходимо задать значение свойств "aria-controls" и "id"',
undefined,
);
it('check DEV errors', () => {
const error = jest.spyOn(console, 'warn').mockImplementation(noop);
render(
<Group role="tabpanel">
<div />
</Group>,
);

process.env.NODE_ENV = 'test';
expect(error).toHaveBeenCalledWith(
'%c[VKUI/Group] При использовании роли "tabpanel" необходимо задать значение свойств "aria-controls" и "id"',
undefined,
);
});
});
});
19 changes: 11 additions & 8 deletions packages/vkui/src/components/ImageBase/ImageBase.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
IconExampleForBadgeBasedOnImageBaseSize,
IconExampleForFallbackBasedOnImageBaseSize,
} from '../../testing/icons';
import { baselineComponent, imgOnlyAttributes } from '../../testing/utils';
import { baselineComponent, imgOnlyAttributes, setNodeEnv } from '../../testing/utils';
import {
getBadgeIconSizeByImageBaseSize,
getFallbackIconSizeByImageBaseSize,
Expand Down Expand Up @@ -38,12 +38,10 @@ const getImageBaseImgEl = (elParent = getImageBaseRootEl()) => within(elParent).

let logStub: jest.SpyInstance | null = null;
beforeEach(() => {
process.env.NODE_ENV = 'development';
logStub = jest.spyOn(console, 'log').mockImplementation(noop);
});

afterEach(() => {
process.env.NODE_ENV = 'test';
logStub?.mockRestore();
});

Expand Down Expand Up @@ -216,11 +214,6 @@ describe(ImageBase, () => {
expect(getImageBaseRootEl()).toHaveClass(styles.transparentBackground);
});

it('check dev error when use incorrect size of icon', () => {
render(<ImageBaseTest fallbackIcon={<Icon20Add />} size={28} />);
expect(logStub).toHaveBeenCalledTimes(1);
});

it('should apply custom objectPosition style', () => {
render(<ImageBaseTest src="#" objectPosition="center bottom" />);

Expand All @@ -229,6 +222,16 @@ describe(ImageBase, () => {
'--vkui_internal--ImageBase_object_position': 'center bottom',
});
});

describe('DEV errros', () => {
beforeEach(() => setNodeEnv('development'));
afterEach(() => setNodeEnv('test'));

it('check error when use incorrect size of icon', () => {
render(<ImageBaseTest fallbackIcon={<Icon20Add />} size={28} />);
expect(logStub).toHaveBeenCalledTimes(1);
});
});
});

describe(getOverlayIconSizeByImageBaseSize, () => {
Expand Down
Loading

0 comments on commit 8301011

Please sign in to comment.