Skip to content

Commit

Permalink
Merge pull request #1548 from cozy/improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbrowne authored Sep 9, 2020
2 parents 280c991 + e1af414 commit 0088f41
Show file tree
Hide file tree
Showing 8 changed files with 1,573 additions and 1,522 deletions.
47 changes: 38 additions & 9 deletions react/ActionMenu/index.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
import React from 'react'
import { mount } from 'enzyme'

import { act } from 'react-dom/test-utils'
import ActionMenu, { ActionMenuItem } from './'
import { fixPopperTesting } from '../Popper/testing'

describe('ActionMenu', () => {
fixPopperTesting()

// The update-not-wrapping-in-act warning is disabled for ActionMenuWrapper since
// we have not found how to remove the "update" happening when mounting the
// ActionMenu.
let originalConsoleError = console.error

beforeEach(() => {
// eslint-disable-next-line no-console
console.error = function(msg, arg) {
if (
msg.includes('An update to %s inside a test was not wrapped in act') &&
arg == 'ActionMenuWrapper'
) {
return
} else {
return originalConsoleError.apply(this, arguments)
}
}
})

afterEach(() => {
// eslint-disable-next-line no-console
console.error = originalConsoleError
})

it('should support null children', () => {
const comp = mount(
<ActionMenu onClose={jest.fn()}>
Expand Down Expand Up @@ -40,16 +64,21 @@ describe('ActionMenu', () => {
</ActionMenu>
)

comp
.find(ActionMenuItem)
.at(1)
.simulate('click')
act(() => {
comp
.find(ActionMenuItem)
.at(1)
.simulate('click')
})
expect(menuAction2).toHaveBeenCalled()
expect(closeMenu).not.toHaveBeenCalled()
comp
.find(ActionMenuItem)
.at(0)
.simulate('click')

act(() => {
comp
.find(ActionMenuItem)
.at(0)
.simulate('click')
})
expect(menuAction1).toHaveBeenCalled()
expect(closeMenu).toHaveBeenCalled()
})
Expand Down
8 changes: 4 additions & 4 deletions react/Badge/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ const Badge = withStyles(customStyles)(

Badge.propTypes = {
anchorOrigin: PropTypes.shape({
horizontal: PropTypes.oneOf('left', 'right'),
vertical: PropTypes.oneOf('bottom', 'top')
horizontal: PropTypes.oneOf(['left', 'right']),
vertical: PropTypes.oneOf(['bottom', 'top'])
}),
size: PropTypes.oneOf('small', 'medium', 'large'),
size: PropTypes.oneOf(['small', 'medium', 'large']),
showZero: PropTypes.bool,
variant: PropTypes.oneOf('standard', 'dot')
variant: PropTypes.oneOf(['standard', 'dot'])
}

Badge.defaultProps = {
Expand Down
2 changes: 1 addition & 1 deletion react/ContactsList/ContactsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const ContactsList = props => {
<ol className={cx(styles['list-contact'], className)} {...rest}>
{sortedHeaders.map(header => (
<li key={header}>
<ListSubheader>{header}</ListSubheader>
<ol className={styles['sublist-contact']}>
<ListSubheader>{header}</ListSubheader>
{categorizedContacts[header].map(contact => (
<li key={contact._id}>
<ContactRow
Expand Down
4 changes: 4 additions & 0 deletions react/ContactsListModal/AddContactButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const DumbAddContactButton = props => {

useEventListener(document, 'resume', apps.fetch)

if (apps.fetchStatus === 'loading') {
return null
}

return (
<AppLinker
slug={installedApp ? installedApp.attributes.slug : 'store'}
Expand Down
3 changes: 3 additions & 0 deletions react/ContactsListModal/DemoProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ mockClient.__proto__.requestQuery = ({ doctype }) => {
_type: 'io.cozy.apps',
attributes: {
slug: 'contacts'
},
links: {
related: 'http://contacts.cozy.tools:8080/'
}
}
]
Expand Down
11 changes: 10 additions & 1 deletion react/Viewer/TextViewer.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ import { shallow } from 'enzyme'
import { TextViewer, isMarkdown } from './TextViewer'
import { createMockClient } from 'cozy-client'
import renderer from 'react-test-renderer'

const client = createMockClient({})

const mockFetch = responseText => async () => ({
text: async () => responseText
})

client.stackClient.fetch = mockFetch('Text')

const props = {
client: createMockClient({}),
client,
url: 'https://foo.mycozy.cloud',
file: {
_id: '1',
Expand Down
3,012 changes: 1,506 additions & 1,506 deletions react/__snapshots__/examples.spec.jsx.snap

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion test/jestsetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ global.shallow = shallow

const isDeprecatedLifecycleWarning = (msg, componentName) => {
return (
msg &&
msg.includes &&
msg.includes('has been renamed, and is not recommended for use') &&
msg.includes(componentName)
)
Expand Down Expand Up @@ -45,7 +47,11 @@ const ignoredWarnings = {
},
ModalAriaLabel: {
reason: 'Dont know',
matcher: msg => msg.includes('aria-label') && msg.includes('If your modal')
matcher: msg =>
msg &&
msg.includes &&
msg.includes('aria-label') &&
msg.includes('If your modal')
}
}

Expand Down

0 comments on commit 0088f41

Please sign in to comment.