Skip to content

Commit

Permalink
Less warnings (#1319)
Browse files Browse the repository at this point in the history
Less warnings
  • Loading branch information
ptbrowne authored Dec 20, 2019
2 parents 1c45860 + d16f0b9 commit c9f7d20
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 13 deletions.
2 changes: 1 addition & 1 deletion react/AppLinker/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import expiringMemoize from './expiringMemoize'

const expirationDelay = 10 * 1000
const memoizedCheckApp = expiringMemoize(
checkApp,
appInfo => checkApp(appInfo).catch(() => false),
expirationDelay,
appInfo => appInfo.appId
)
Expand Down
27 changes: 20 additions & 7 deletions react/ContactsList/ContactRow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,31 @@ import { mount } from 'enzyme'

import ContactRow from './ContactRow'
import renderer from 'react-test-renderer'
import logger from 'cozy-logger'

logger.setLevel('error')

const makeContact = attrs => ({
_id: 'contactid',
_type: 'io.cozy.contacts',
...attrs
})

describe('ContactRow', () => {
test('should accept the strict minimum', () => {
const contact = { email: [{ address: 'johndoe@localhost' }] }
const contact = makeContact({ email: [{ address: 'johndoe@localhost' }] })
const contactRowInstance = <ContactRow contact={contact} />
const contactrow = mount(contactRowInstance)
const contactrowemail = contactrow.find('ContactEmail')
expect(contactrowemail.text()).toBe(contact.email[0].address)
})
test('should display data', () => {
const contact = {
const contact = makeContact({
name: { familyName: 'Doe', givenName: 'John' },
phone: [{ number: '0123456789' }],
email: [{ address: 'johndoe@localhost' }],
cozy: [{ url: 'http://johndoe.mycozy.cloud' }]
}
})
const contactRowInstance = <ContactRow contact={contact} />
const contactrow = mount(contactRowInstance)
const contactrowname = contactrow.find('ContactName')
Expand All @@ -37,7 +47,9 @@ describe('ContactRow', () => {
expect(contactrowcozyurl.text()).toBe(contact.cozy[0].url)
})
test('should display empty string for missing information', () => {
const contact = { email: [{ address: 'johndoe@localhost' }] }
const contact = makeContact({
email: [{ address: 'johndoe@localhost' }]
})
const contactRowInstance = <ContactRow contact={contact} />
const contactrow = mount(contactRowInstance)
const contactrowname = contactrow.find('ContactName')
Expand All @@ -50,8 +62,9 @@ describe('ContactRow', () => {
expect(contactrowcozyurl).toBeDefined()
expect(contactrowcozyurl.text().trim()).toBe('—')
})

test('should accept empty array', () => {
const contact = { email: [] }
const contact = makeContact({ email: [] })
const contactRowInstance = <ContactRow contact={contact} />
const contactrow = mount(contactRowInstance)
const contactrowemail = contactrow.find('ContactEmail')
Expand All @@ -60,12 +73,12 @@ describe('ContactRow', () => {
})

test('should match the contact snapshot', () => {
const contact = {
const contact = makeContact({
name: { familyName: 'Doe', givenName: 'John' },
phone: [{ number: '0123456789' }],
email: [{ address: 'johndoe@localhost' }],
cozy: [{ url: 'http://johndoe.mycozy.cloud' }]
}
})
const tree = renderer.create(<ContactRow contact={contact} />).toJSON()
expect(tree).toMatchSnapshot()
})
Expand Down
3 changes: 2 additions & 1 deletion react/Field/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ const allowedTypes = [
'textarea',
'text',
'url',
'number'
'number',
'contact'
]

Field.propTypes = {
Expand Down
6 changes: 6 additions & 0 deletions react/I18n/format.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { initFormat } from './format'

describe('initFormat', () => {
beforeEach(() => {
jest.spyOn(console, 'warn').mockImplementation(() => {})
})
afterEach(() => {
console.warn.mockRestore()
})
it('should not throw if a date-fns locale can not be found', () => {
expect(() => initFormat('unknown-lang', 'unknown-default')).not.toThrow()
})
Expand Down
1 change: 1 addition & 0 deletions react/InputGroup/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ import Input from 'cozy-ui/transpiled/react/Input';
### InputGroup with a prepended text and a custom classname (border-radius)

```
import InputGroup from 'cozy-ui/transpiled/react/InputGroup';
import { Bold } from 'cozy-ui/transpiled/react/Text';
import Input from 'cozy-ui/transpiled/react/Input';
<form>
Expand Down
10 changes: 8 additions & 2 deletions react/Spinner/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@ import Spinner from 'cozy-ui/transpiled/react/Spinner';
import I18n from 'cozy-ui/transpiled/react/I18n';
<div>
<I18n lang='en' dictRequire={() => {}}>
<Spinner size='xxlarge' loadingType='hi' />
<I18n lang='en' dictRequire={() => {
en: {
loading: {
helloWorld: 'Hello World !'
}
}
}}>
<Spinner size='xxlarge' loadingType='helloWorld' />
</I18n>
</div>
```
6 changes: 6 additions & 0 deletions react/Viewer/PdfJsViewer.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ describe('PDFViewer', () => {
})

describe('with a pdf that does not load', () => {
beforeEach(() => {
jest.spyOn(console, 'warn').mockImplementation(() => {})
})
afterEach(() => {
console.warn.mockRestore()
})
it('should show a fallback', () => {
component.instance().onLoadError('pdfviewer test error')
expect(component.state('errored')).toBe(true)
Expand Down
17 changes: 15 additions & 2 deletions react/__snapshots__/examples.spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5156,7 +5156,20 @@ exports[`InputGroup should render examples: InputGroup 6`] = `
</div>"
`;

exports[`InputGroup should render examples: InputGroup 7`] = `"<div></div><pre class=\\"rsg--root-0\\">ReferenceError: InputGroup is not defined</pre>"`;
exports[`InputGroup should render examples: InputGroup 7`] = `
"<div>
<form>
<div>
<div class=\\"styles__c-inputgroup___12OVJ u-bdrs-3\\">
<div class=\\"styles__c-inputgroup-side___60v0v\\">
<div class=\\"u-title-h4 u-pl-1\\">text</div>
</div>
<div class=\\"styles__c-inputgroup-main___1LP4B\\"><input type=\\"text\\" class=\\"styles__c-input-text___3TAv1 styles__c-input-text--large___28EaR\\" placeholder=\\"Placeholder\\" value=\\"\\"></div>
</div>
</div>
</form>
</div>"
`;

exports[`Label should render examples: Label 1`] = `
"<div>
Expand Down Expand Up @@ -5832,7 +5845,7 @@ exports[`Spinner should render examples: Spinner 5`] = `
<div class=\\"styles__c-spinner___1snK7\\"><svg class=\\"styles__icon___23x3R styles__icon--spin___ybfC1\\" style=\\"fill: var(--primaryColor);\\" width=\\"80\\" height=\\"80\\">
<use xlink:href=\\"#spinner\\"></use>
</svg>
<p>loading.hi</p>
<p>loading.helloWorld</p>
</div>
</div>
</div>"
Expand Down
9 changes: 9 additions & 0 deletions stylus/utilities/debug.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.u-debug
background rgba(0, 0, 0, .075)
border 1px solid red

.u-debug .u-debug
border-color blue

.u-debug .u-debug .u-debug
border-color green
50 changes: 50 additions & 0 deletions test/jestsetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,53 @@ configure({ adapter: new Adapter() })

global.mount = mount
global.shallow = shallow

const isDeprecatedLifecycleWarning = (msg, componentName) => {
return (
msg.includes('has been renamed, and is not recommended for use') &&
msg.includes(componentName)
)
}

const ignoreOnConditions = (originalWarn, ignoreConditions) => {
return function(...args) {
const msg = args[0]
if (ignoreConditions.some(condition => condition(msg))) {
return
}
originalWarn.apply(this, args)
}
}

const makeDeprecatedLifecycleMatcher = componentName => msg =>
isDeprecatedLifecycleWarning(msg, componentName)

const ignoredWarnings = {
I18nLifecycle: {
reason: 'Preact compatibility',
matcher: makeDeprecatedLifecycleMatcher('I18n')
},
ReactSwipableViewLifecycle: {
reason: 'External lib',
matcher: makeDeprecatedLifecycleMatcher('ReactSwipableView')
},
AutosizeInputLifecycle: {
reason: 'External lib',
matcher: makeDeprecatedLifecycleMatcher('AutosizeInput')
},
ModalContentLifecycle: {
reason: 'Preact compatibility',
matcher: makeDeprecatedLifecycleMatcher('ModalContent')
},
ModalAriaLabel: {
reason: 'Dont know',
matcher: msg => msg.includes('aria-label') && msg.includes('If your modal')
}
}

// Ignore warnings that we think are not problematic, see
// https://github.com/cozy/cozy-ui/issues/1318
console.warn = ignoreOnConditions(
console.warn,
Object.values(ignoredWarnings).map(x => x.matcher)
)

0 comments on commit c9f7d20

Please sign in to comment.