-
Notifications
You must be signed in to change notification settings - Fork 734
Infra/picker testing coverage #3107
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
Changes from 7 commits
4103a7f
6019fb1
4b9a9a6
eccde07
8d4913c
68f70dd
87f624e
61e0d65
e29caa4
1faecdf
4e30855
051a1a0
d4ebaa9
1d34013
6915189
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,5 +1,6 @@ | ||
import React, {useState} from 'react'; | ||
import {act, render, waitFor} from '@testing-library/react-native'; | ||
import {act, render, waitFor, screen} from '@testing-library/react-native'; | ||
import {Typography} from '../../../style'; | ||
import Picker from '../index'; | ||
import {PickerDriver} from '../Picker.driver.new'; | ||
const countries = [ | ||
|
@@ -27,38 +28,26 @@ const getDriver = (props?: any) => { | |
return PickerDriver({renderTree: render(<TestCase {...props}/>), testID}); | ||
}; | ||
|
||
const onPress = jest.fn(); | ||
const onDismiss = jest.fn(); | ||
// const onShow = jest.fn(); | ||
|
||
describe('Picker', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('Modal', () => { | ||
describe('Test value', () => { | ||
it('Get correct value of a single item', () => { | ||
const driver = getDriver({value: countries[2].value}); | ||
expect(driver.getValue()).toEqual(countries[2].label); | ||
}); | ||
|
||
it('Get correct value of multiple selected items', () => { | ||
const driver = getDriver({value: [countries[2].value, countries[4].value]}); | ||
expect(driver.getValue()).toEqual(`${countries[2].label}, ${countries[4].label}`); | ||
}); | ||
}); | ||
|
||
describe('Test open', () => { | ||
it('Should open when enabled', () => { | ||
const driver = getDriver(); | ||
|
||
expect(driver.isOpen()).toBeFalsy(); | ||
driver.open(); | ||
expect(driver.isOpen()).toBeTruthy(); | ||
}); | ||
|
||
it('Should not open when disabled', () => { | ||
const driver = getDriver({editable: false}); | ||
|
||
expect(driver.isOpen()).toBeFalsy(); | ||
driver.open(); | ||
expect(driver.isOpen()).toBeFalsy(); | ||
|
@@ -67,19 +56,28 @@ describe('Picker', () => { | |
|
||
it('Test close', () => { | ||
const driver = getDriver(); | ||
|
||
expect(driver.isOpen()).toBeFalsy(); | ||
driver.open(); | ||
expect(driver.isOpen()).toBeTruthy(); | ||
driver.cancel(); | ||
expect(driver.isOpen()).toBeFalsy(); | ||
}); | ||
|
||
describe('Test value', () => { | ||
it('Get correct value of a single item', () => { | ||
const driver = getDriver({value: countries[2].value}); | ||
expect(driver.getValue()).toEqual(countries[2].label); | ||
}); | ||
|
||
it('Get correct value of multiple selected items', () => { | ||
const driver = getDriver({value: [countries[2].value, countries[4].value]}); | ||
expect(driver.getValue()).toEqual(`${countries[2].label}, ${countries[4].label}`); | ||
}); | ||
}); | ||
|
||
describe('Test selection', () => { | ||
it('Should select a single item', () => { | ||
const driver = getDriver(); | ||
expect(driver.getValue()).toEqual(''); | ||
expect(driver.isOpen()).toBeFalsy(); | ||
driver.open(); | ||
expect(driver.isOpen()).toBeTruthy(); | ||
driver.selectItem(countries[2].label); | ||
|
@@ -90,7 +88,6 @@ describe('Picker', () => { | |
it('Should select multiple items', () => { | ||
const driver = getDriver({mode: 'MULTI'}); | ||
expect(driver.getValue()).toEqual(''); | ||
expect(driver.isOpen()).toBeFalsy(); | ||
driver.open(); | ||
expect(driver.isOpen()).toBeTruthy(); | ||
driver.selectItem(countries[2].label); | ||
|
@@ -100,122 +97,185 @@ describe('Picker', () => { | |
}); | ||
}); | ||
|
||
it('Test onDismiss', () => { | ||
const driver = getDriver({ | ||
pickerModalProps: { | ||
onDismiss | ||
} | ||
}); | ||
|
||
expect(driver.isOpen()).toBeFalsy(); | ||
it('Test onPress', () => { | ||
const driver = getDriver({onPress}); | ||
driver.open(); | ||
expect(driver.isOpen()).toBeTruthy(); | ||
driver.cancel(); | ||
expect(driver.isOpen()).toBeFalsy(); | ||
expect(onDismiss).toHaveBeenCalledTimes(2); // TODO: this should be 1 | ||
expect(onPress).toHaveBeenCalled(); | ||
}); | ||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
describe('Test pickerModalProps', () => { | ||
it('Test onDismiss', () => { | ||
const driver = getDriver({ | ||
pickerModalProps: { | ||
onDismiss | ||
} | ||
}); | ||
driver.open(); | ||
expect(driver.isOpen()).toBeTruthy(); | ||
driver.cancel(); | ||
expect(driver.isOpen()).toBeFalsy(); | ||
expect(onDismiss).toHaveBeenCalledTimes(2); // TODO: this should be 1 | ||
}); | ||
|
||
// TODO: this test is not passing yet | ||
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. When should this start working? 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. The issue here is that the I'll change the 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. Doesn't matter IMO |
||
// it('Test onShow passed via pickerModalProps', async () => { | ||
// const driver = getDriver({ | ||
// pickerModalProps: { | ||
// onShow | ||
// } | ||
// }); | ||
// expect(driver.isOpen()).toBeFalsy(); | ||
// jest.useFakeTimers(); | ||
// expect(driver.isOpen()).toBeTruthy(); | ||
// expect(onShow).toHaveBeenCalled(); | ||
// }); | ||
|
||
describe('Test Modal TopBar', () => { | ||
it('should close and select items when pressing on cancel button', () => { | ||
const driver = getDriver({mode: 'MULTI', topBarProps: {cancelLabel: 'Cancel'}}); | ||
driver.open(); | ||
expect(driver.isOpen()).toBeTruthy(); | ||
driver.selectItem(countries[2].label); | ||
driver.selectItem(countries[4].label); | ||
driver.done(); | ||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(driver.isOpen()).toBeFalsy(); | ||
expect(driver.getValue()).toEqual(`${countries[2].label}, ${countries[4].label}`); | ||
}); | ||
|
||
it('should close without selecting items when pressing on cancel button', () => { | ||
const driver = getDriver({mode: 'MULTI', topBarProps: {cancelLabel: 'Cancel'}}); | ||
driver.open(); | ||
expect(driver.isOpen()).toBeTruthy(); | ||
driver.selectItem(countries[2].label); | ||
driver.selectItem(countries[4].label); | ||
driver.cancel(); | ||
expect(driver.getValue()).toEqual(``); | ||
expect(driver.isOpen()).toBeFalsy(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
// TODO: this is a work in progress, the tests are not passing yet | ||
describe.skip('Dialog', () => { | ||
describe('Dialog', () => { | ||
const dialogProps = {useDialog: true, customPickerProps: {migrateDialog: true}}; | ||
describe('Test value', () => { | ||
it('Get correct value of a single item', () => { | ||
const driver = getDriver({ | ||
useDialog: true, | ||
customPickerProps: {migrateDialog: true}, | ||
...dialogProps, | ||
value: countries[2].value | ||
}); | ||
expect(driver.getValue()).toEqual(countries[2].label); | ||
}); | ||
|
||
it('Get correct value of multiple selected items', () => { | ||
const driver = getDriver({ | ||
useDialog: true, | ||
customPickerProps: {migrateDialog: true}, | ||
...dialogProps, | ||
value: [countries[2].value, countries[4].value] | ||
}); | ||
expect(driver.getValue()).toEqual(`${countries[2].label}, ${countries[4].label}`); | ||
}); | ||
}); | ||
|
||
describe('Test open', () => { | ||
describe('Test open/close', () => { | ||
it('Should open when enabled', async () => { | ||
const driver = getDriver({useDialog: true, customPickerProps: {migrateDialog: true}}); | ||
|
||
const driver = getDriver(dialogProps); | ||
expect(driver.isOpen()).toBeFalsy(); | ||
// driver.open(); | ||
// expect(driver.isOpen()).toBeTruthy(); | ||
jest.useFakeTimers(); | ||
act(() => driver.open()); | ||
jest.runAllTimers(); | ||
// advanceAnimationByTime(10000); | ||
// await new Promise(r => setTimeout(r, 1000)); | ||
await waitFor(() => expect(driver.isOpen()).toBeTruthy()); | ||
await waitFor(() => expect(driver.isOpen(dialogProps.useDialog)).toBeTruthy()); | ||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
it('Should not open when disabled', () => { | ||
const driver = getDriver({useDialog: true, customPickerProps: {migrateDialog: true}, editable: false}); | ||
|
||
expect(driver.isOpen()).toBeFalsy(); | ||
driver.open(); | ||
it('Should not open when disabled', async () => { | ||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const driver = getDriver({...dialogProps, editable: false}); | ||
expect(driver.isOpen()).toBeFalsy(); | ||
act(() => driver.open()); | ||
await waitFor(() => expect(driver.isOpen(dialogProps.useDialog)).toBeFalsy()); | ||
}); | ||
}); | ||
|
||
it('Test close', () => { | ||
const driver = getDriver({useDialog: true, customPickerProps: {migrateDialog: true}}); | ||
|
||
expect(driver.isOpen()).toBeFalsy(); | ||
driver.open(); | ||
expect(driver.isOpen()).toBeTruthy(); | ||
driver.cancel(); | ||
expect(driver.isOpen()).toBeFalsy(); | ||
it('Test close', async () => { | ||
const driver = getDriver(dialogProps); | ||
expect(driver.isOpen()).toBeFalsy(); | ||
act(() => driver.open()); | ||
await waitFor(() => expect(driver.isOpen(dialogProps.useDialog)).toBeTruthy()); | ||
act(() => driver.dismissDialog()); | ||
await waitFor(() => expect(driver.dismissDialog(dialogProps.useDialog)).toBeFalsy()); | ||
}); | ||
}); | ||
|
||
describe('Test selection', () => { | ||
it('Should select a single item', () => { | ||
const driver = getDriver({useDialog: true, customPickerProps: {migrateDialog: true}}); | ||
expect(driver.getValue()).toEqual(undefined); | ||
expect(driver.isOpen()).toBeFalsy(); | ||
driver.open(); | ||
expect(driver.isOpen()).toBeTruthy(); | ||
it('Should select a single item', async () => { | ||
const driver = getDriver(dialogProps); | ||
expect(driver.getValue()).toEqual(''); | ||
act(() => driver.open()); | ||
await waitFor(() => expect(driver.isOpen(dialogProps.useDialog)).toBeTruthy()); | ||
driver.selectItem(countries[2].label); | ||
expect(driver.isOpen()).toBeFalsy(); | ||
act(() => driver.dismissDialog()); | ||
await waitFor(() => expect(driver.isOpen(dialogProps.useDialog)).toBeFalsy()); | ||
expect(driver.getValue()).toEqual(countries[2].label); | ||
}); | ||
|
||
it('Should select multiple items', () => { | ||
const driver = getDriver({useDialog: true, customPickerProps: {migrateDialog: true}, mode: 'MULTI'}); | ||
expect(driver.getValue()).toEqual(undefined); | ||
it('Should select multiple items', async () => { | ||
const driver = getDriver({...dialogProps, mode: 'MULTI'}); | ||
expect(driver.getValue()).toEqual(''); | ||
expect(driver.isOpen()).toBeFalsy(); | ||
driver.open(); | ||
expect(driver.isOpen()).toBeTruthy(); | ||
act(() => driver.open()); | ||
await waitFor(() => expect(driver.isOpen(dialogProps.useDialog)).toBeTruthy()); | ||
driver.selectItem(countries[2].label); | ||
driver.selectItem(countries[4].label); | ||
driver.done(); | ||
await waitFor(() => expect(driver.isOpen(dialogProps.useDialog)).toBeFalsy()); | ||
expect(driver.getValue()).toEqual(`${countries[2].label}, ${countries[4].label}`); | ||
}); | ||
}); | ||
|
||
it('Test onDismiss', () => { | ||
it('Test onDismiss', async () => { | ||
const driver = getDriver({ | ||
useDialog: true, | ||
customPickerProps: {migrateDialog: true}, | ||
pickerModalProps: { | ||
onDismiss | ||
...dialogProps, | ||
customPickerProps: { | ||
dialogProps: { | ||
onDismiss | ||
} | ||
} | ||
}); | ||
|
||
expect(driver.isOpen()).toBeFalsy(); | ||
driver.open(); | ||
expect(driver.isOpen()).toBeTruthy(); | ||
driver.cancel(); | ||
expect(driver.isOpen()).toBeFalsy(); | ||
expect(onDismiss).toHaveBeenCalledTimes(2); // TODO: this should be 1 | ||
act(() => driver.open()); | ||
await waitFor(() => expect(driver.isOpen(dialogProps.useDialog)).toBeTruthy()); | ||
act(() => driver.dismissDialog()); | ||
await waitFor(() => expect(driver.dismissDialog(dialogProps.useDialog)).toBeFalsy()); | ||
expect(onDismiss).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
// TODO: add tests for WheelPicker as well | ||
// TODO: add tests for WheelPicker | ||
// Note: the picker dialog should be opened and then the wheel picker should be rendered, this is the main issue with testing it for now | ||
// describe.skip('WheelPicker', () => { | ||
// }); | ||
|
||
//TODO: add more tests for different props | ||
describe('Picker field types', () => { | ||
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. These are failing 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. fixed, bad merging from master after merging the new |
||
it('should render a form picker', () => { | ||
const driver = getDriver({fieldType: 'form'}); | ||
const textFieldDriver = driver.getInput(); | ||
act(() => expect(textFieldDriver.exists()).toBeTruthy()); | ||
expect(textFieldDriver.getStyle()).toEqual(expect.objectContaining({textAlign: 'left'})); | ||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
it('should render a filter picker', () => { | ||
const driver = getDriver({fieldType: 'filter'}); | ||
screen.debug(); | ||
const textFieldDriver = driver.getInput(); | ||
act(() => expect(textFieldDriver.exists()).toBeTruthy()); | ||
expect(textFieldDriver.getStyle()).toEqual(expect.objectContaining(Typography.text70)); | ||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
it('should render a settings picker', async () => { | ||
const driver = getDriver({fieldType: 'settings'}); | ||
const textFieldDriver = driver.getInput(); | ||
act(() => expect(textFieldDriver.exists()).toBeTruthy()); | ||
console.log(`textFieldDriver.getStyle():`, textFieldDriver.getStyle()); | ||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(textFieldDriver.getStyle()).toEqual(expect.objectContaining(Typography.text70)); | ||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.