Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
},
"dependencies": {
"@babel/runtime": "^7.10.1",
"@rc-component/trigger": "^1.5.0",
"classnames": "^2.2.6",
"rc-input": "^0.2.2",
"rc-menu": "~9.8.0",
"rc-textarea": "^1.0.0",
"rc-trigger": "^5.0.4",
"rc-util": "^5.22.5"
},
"devDependencies": {
Expand Down
5 changes: 3 additions & 2 deletions src/KeywordTrigger.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Trigger from 'rc-trigger';
import Trigger from '@rc-component/trigger';
import type { FC } from 'react';
import * as React from 'react';
import { FC, useMemo } from 'react';
import { useMemo } from 'react';
import DropdownMenu from './DropdownMenu';
import type { DataDrivenOptionProps, Direction, Placement } from './Mentions';

Expand Down
8 changes: 4 additions & 4 deletions tests/FullProcess.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { fireEvent, render } from '@testing-library/react';
import KeyCode from 'rc-util/lib/KeyCode';
import React from 'react';
import { fireEvent, render } from '@testing-library/react';
import Mentions from '../src';
import type { MentionsProps } from '../src';
import Mentions from '../src';
import { expectMatchOptions, expectMeasuring, simulateInput } from './util';

describe('Full Process', () => {
Expand Down Expand Up @@ -145,7 +145,7 @@ describe('Full Process', () => {
});

it('should support same value', () => {
const { container } = render(
const { container, baseElement } = render(
<Mentions
options={[
{
Expand All @@ -170,7 +170,7 @@ describe('Full Process', () => {

simulateInput(container, '@');
expect(
container.querySelectorAll('li.rc-mentions-dropdown-menu-item-active'),
baseElement.querySelectorAll('li.rc-mentions-dropdown-menu-item-active'),
).toHaveLength(2);
});

Expand Down
32 changes: 19 additions & 13 deletions tests/Mentions.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('Mentions', () => {

it('not lose focus if click on dropdown', () => {
const onBlur = jest.fn();
const { container } = renderMentions({
const { container, baseElement } = renderMentions({
autoFocus: true,
defaultValue: '@',
onBlur,
Expand All @@ -69,11 +69,11 @@ describe('Mentions', () => {
});

fireEvent.focus(
container.querySelector('li.rc-mentions-dropdown-menu-item'),
baseElement.querySelector('li.rc-mentions-dropdown-menu-item'),
);
fireEvent.blur(container.querySelector('textarea'));
fireEvent.click(
container.querySelector('li.rc-mentions-dropdown-menu-item'),
baseElement.querySelector('li.rc-mentions-dropdown-menu-item'),
);
fireEvent.focus(container.querySelector('textarea'));

Expand Down Expand Up @@ -177,13 +177,15 @@ describe('Mentions', () => {
});

it('do not lose label', () => {
const { container } = renderOptionsMentions();
const { container, baseElement } = renderOptionsMentions();
simulateInput(container, '@');
fireEvent.mouseEnter(
container.querySelector('li.rc-mentions-dropdown-menu-item:last-child'),
baseElement.querySelector(
'li.rc-mentions-dropdown-menu-item:last-child',
),
);
expect(
container.querySelector('.rc-mentions-dropdown-menu-item-active')
baseElement.querySelector('.rc-mentions-dropdown-menu-item-active')
.textContent,
).toBe('Cat');
});
Expand Down Expand Up @@ -224,33 +226,37 @@ describe('Mentions', () => {

describe('accessibility', () => {
it('hover', () => {
const { container } = renderMentions();
const { container, baseElement } = renderMentions();
simulateInput(container, '@');
fireEvent.mouseEnter(
container.querySelector('li.rc-mentions-dropdown-menu-item:last-child'),
baseElement.querySelector(
'li.rc-mentions-dropdown-menu-item:last-child',
),
);
expect(
container.querySelector('.rc-mentions-dropdown-menu-item-active')
baseElement.querySelector('.rc-mentions-dropdown-menu-item-active')
.textContent,
).toBe('Cat');
});
});

it('dropdownClassName should work', () => {
const { container } = renderMentions({ dropdownClassName: 'my-dropdown' });
const { container, baseElement } = renderMentions({
dropdownClassName: 'my-dropdown',
});
simulateInput(container, '@');
expect(
container.querySelector('.my-dropdown.rc-mentions-dropdown'),
baseElement.querySelector('.my-dropdown.rc-mentions-dropdown'),
).toBeTruthy();
});

it('should support direction', () => {
const { container } = renderMentions({ direction: 'rtl' });
const { container, baseElement } = renderMentions({ direction: 'rtl' });
simulateInput(container, '@');
act(() => {
jest.runAllTimers();
});
expect(container.querySelector('.rc-mentions-dropdown')).toBeTruthy();
expect(baseElement.querySelector('.rc-mentions-dropdown')).toBeTruthy();
});

it('should support textarea in ref', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/__mocks__/rc-trigger.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import Trigger from 'rc-trigger/lib/mock';
import Trigger from '@rc-component/trigger/lib/mock';

export default Trigger;