-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(uaa-parity): Fix consecutive version events issue #3828
Changes from all commits
b9e161e
c8e5062
6f9e69a
19ad5ec
56671f4
c872031
e7ba614
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,87 @@ | ||
import * as React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import { render, screen } from '@testing-library/react'; | ||
import { IntlProvider } from 'react-intl'; | ||
import { ACTION_TYPE_CREATED, ACTION_TYPE_RESTORED, ACTION_TYPE_TRASHED } from '../../../../../constants'; | ||
import CollapsedVersion from '../CollapsedVersion'; | ||
import selectors from '../../../../common/selectors/version'; | ||
import { CollapsedVersionBase as CollapsedVersion } from '../CollapsedVersion'; | ||
|
||
const translationProps = { | ||
intl: { formatMessage: () => {} }, | ||
}; | ||
jest.mock('react-intl', () => ({ | ||
...jest.requireActual('react-intl'), | ||
})); | ||
Comment on lines
+8
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you import There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests not passing when I do that for some reason . Given this change is a little time-sensitive, I will leave as is. |
||
|
||
describe('elements/content-sidebar/ActivityFeed/version/CollapsedVersion', () => { | ||
const render = item => shallow(<CollapsedVersion {...translationProps} {...item} />); | ||
|
||
beforeEach(() => { | ||
selectors.getVersionAction = jest.fn().mockReturnValue('upload'); | ||
}); | ||
|
||
test('should correctly render for single collaborator', () => { | ||
const version_start = 1; | ||
const version_end = 10; | ||
const item = { | ||
collaborators: { 1: { name: 'Person one', id: 1 } }, | ||
version_start, | ||
version_end, | ||
}; | ||
const intl = { | ||
formatMessage: jest.fn().mockImplementation(message => message.defaultMessage), | ||
}; | ||
|
||
const renderComponent = props => | ||
render( | ||
<IntlProvider locale="en"> | ||
<CollapsedVersion | ||
intl={intl} | ||
collaborators={{ 1: { name: 'Person one', id: 1 } }} | ||
version_start={1} | ||
version_end={10} | ||
versions={[]} | ||
id={0} | ||
{...props} | ||
/> | ||
</IntlProvider>, | ||
); | ||
|
||
const wrapper = render(item); | ||
const formattedMessage = wrapper.find('FormattedMessage'); | ||
expect(wrapper).toMatchSnapshot(); | ||
test('should correctly render for single collaborator', () => { | ||
renderComponent(); | ||
|
||
const renderedVersionsMessage = shallow(formattedMessage.prop('values').versions); | ||
expect(renderedVersionsMessage).toMatchSnapshot(); | ||
expect(screen.getByText('Person one')).toBeInTheDocument(); | ||
expect(screen.getByText('uploaded v')).toBeInTheDocument(); | ||
expect(screen.getByText('1 - 10')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should correctly render for multiple collaborators', () => { | ||
const version_start = 1; | ||
const version_end = 10; | ||
const item = { | ||
collaborators: { | ||
1: { name: 'Person one', id: 1 }, | ||
2: { name: 'Person two', id: 2 }, | ||
}, | ||
version_start, | ||
version_end, | ||
}; | ||
renderComponent({ | ||
collaborators: { 1: { name: 'Person one', id: 1 }, 2: { name: 'Person two', id: 2 } }, | ||
}); | ||
|
||
const wrapper = render(item); | ||
const formattedMessage = wrapper.find('FormattedMessage'); | ||
|
||
expect(wrapper).toMatchSnapshot(); | ||
|
||
const renderedVersionsMessage = shallow(formattedMessage.prop('values').versions); | ||
expect(renderedVersionsMessage).toMatchSnapshot(); | ||
expect(screen.getByText('2 collaborators uploaded v')).toBeInTheDocument(); | ||
expect(screen.getByText('1 - 10')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should correctly render info icon if onInfo is passed', () => { | ||
const item = { | ||
renderComponent({ | ||
onInfo: () => {}, | ||
collaborators: { | ||
1: { name: 'Person one', id: 1 }, | ||
2: { name: 'Person two', id: 2 }, | ||
}, | ||
version_start: 1, | ||
version_end: 10, | ||
}; | ||
}); | ||
|
||
const wrapper = render(item); | ||
|
||
expect(wrapper.exists('IconInfo')).toBe(true); | ||
expect(screen.getByLabelText('Get version information')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should not render a message if action is not upload', () => { | ||
selectors.getVersionAction.mockReturnValueOnce('delete'); | ||
|
||
const item = { | ||
collaborators: { 1: { name: 'Person one', id: 1 } }, | ||
version_start: 1, | ||
version_end: 10, | ||
}; | ||
renderComponent(); | ||
|
||
const wrapper = render(item); | ||
const formattedMessage = wrapper.find('FormattedMessage'); | ||
expect(screen.queryByText('Person one')).not.toBeInTheDocument(); | ||
}); | ||
|
||
expect(formattedMessage.length).toBe(0); | ||
test.each` | ||
actionType | actionText | ||
${ACTION_TYPE_RESTORED} | ${'restored v'} | ||
${ACTION_TYPE_TRASHED} | ${'deleted v'} | ||
${ACTION_TYPE_CREATED} | ${'uploaded v'} | ||
`('should correctly render when shouldUseUAA is true with actionType $actionType', ({ actionType, actionText }) => { | ||
renderComponent({ | ||
shouldUseUAA: true, | ||
action_type: actionType, | ||
action_by: [{ name: 'John Doe', id: 3 }], | ||
version_start: 2, | ||
version_end: 4, | ||
}); | ||
|
||
expect(screen.getByText('John Doe')).toBeInTheDocument(); | ||
expect(screen.getByText(actionText)).toBeInTheDocument(); | ||
expect(screen.getByText('2 - 4')).toBeInTheDocument(); | ||
}); | ||
Comment on lines
+69
to
86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, thanks for converting this! |
||
}); |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like a switch here with a default to null would read better as well or invert this gate and default to returning null.