Skip to content

Commit

Permalink
chore(resin): Add resin tags to mentions list
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingze Xiao committed Jul 6, 2020
1 parent c86ae59 commit 828c36b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/components/ItemList/ItemRow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import * as React from 'react';
import * as ReactRedux from 'react-redux';
import classNames from 'classnames';
import { Collaborator } from '../../@types';
import { getFileId, getIsCurrentFileVersion } from '../../store';
import './ItemRow.scss';

export type Props = {
Expand All @@ -16,6 +18,8 @@ export type ItemRowRef = HTMLLIElement;

const ItemRow = (props: Props, ref: React.Ref<ItemRowRef>): JSX.Element | null => {
const { className, isActive, item: collaborator, onClick, onMouseDown, onMouseEnter } = props;
const fileId = ReactRedux.useSelector(getFileId);
const isCurrentFileVersion = ReactRedux.useSelector(getIsCurrentFileVersion);

if (!collaborator || !collaborator.item || !collaborator.item.name) {
return null;
Expand All @@ -29,6 +33,9 @@ const ItemRow = (props: Props, ref: React.Ref<ItemRowRef>): JSX.Element | null =
ref={ref}
aria-selected={isActive}
className={classNames(className, 'ba-ItemRow', { 'is-active': isActive })}
data-resin-fileid={fileId}
data-resin-iscurrent={isCurrentFileVersion}
data-resin-target="atMention"
data-testid="ba-ItemRow"
onClick={onClick}
onMouseDown={onMouseDown}
Expand Down
1 change: 1 addition & 0 deletions src/components/ItemList/__tests__/ItemList-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ItemList, { Props } from '../ItemList';
import { Collaborator } from '../../../@types';

jest.mock('scroll-into-view-if-needed', () => jest.fn());
jest.mock('../ItemRow', () => 'div');

describe('components/ItemList/ItemList', () => {
const defaults: Props<Collaborator> = {
Expand Down
22 changes: 21 additions & 1 deletion src/components/ItemList/__tests__/ItemRow-test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import * as React from 'react';
import * as ReactRedux from 'react-redux';
import { shallow, ShallowWrapper } from 'enzyme';
import { UserMini } from '../../../@types';
import ItemRow, { Props } from '../ItemRow';
Expand All @@ -15,6 +16,12 @@ describe('components/ItemList/ItemRow', () => {

const getWrapper = (props = {}): ShallowWrapper => shallow(<ItemRow {...defaults} {...props} />);

let reduxSpy: jest.SpyInstance;

beforeEach(() => {
reduxSpy = jest.spyOn(ReactRedux, 'useSelector').mockImplementation(() => true);
});

describe('render()', () => {
test('should not render anything if no item name', () => {
const wrapper = getWrapper({ item: {} });
Expand All @@ -34,5 +41,18 @@ describe('components/ItemList/ItemRow', () => {

expect(wrapper.exists('[data-testid="ba-ItemRow-email"]')).toBeFalsy();
});

test('should add resin tags', () => {
reduxSpy.mockReturnValueOnce('0');
reduxSpy.mockReturnValueOnce(true);

const wrapper = getWrapper();

expect(wrapper.props()).toMatchObject({
'data-resin-fileid': '0',
'data-resin-iscurrent': true,
'data-resin-target': 'atMention',
});
});
});
});

0 comments on commit 828c36b

Please sign in to comment.