Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Checkbox as RNPCheckbox } from 'react-native-paper';
import { CheckboxProps } from '@bluebase/components';
// tslint:disable-next-line: sort-imports
import { Checkbox as RNPCheckbox } from 'react-native-paper';
import { SelectionControl } from '../SelectionControl';
import { Theme } from '@bluebase/core';
import { componentMapper } from '@bluebase/component-mapper';
Expand All @@ -21,6 +22,14 @@ export const Checkbox = componentMapper<CheckboxProps>(SelectionControl, {

return color;
},
onPress: ({ onPress, onValueChange, value, checked }: any) => () => {
if (onPress) {
onPress();
}
if (onValueChange) {
onValueChange(value, !checked);
}
},

status: ({ checked, indeterminate }: CheckboxProps) => {
if (indeterminate === true) {
Expand Down
6 changes: 5 additions & 1 deletion src/components/Checkbox/__stories__/Checkbox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ stories
color="blue"
/>
<Checkbox
onValueChange={action('Checked')}
value="test1"
onValueChange={(a, b)=>{
// console.log(a);
// console.log(b);
}}
label="Unchecked"
color="blue"
checked={false}
Expand Down
24 changes: 24 additions & 0 deletions src/components/Checkbox/__tests__/Checkbox.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BlueBaseApp, getComponent } from '@bluebase/core';

import { Checkbox } from '../Checkbox';
import React from 'react';
import { mount } from 'enzyme';
Expand Down Expand Up @@ -110,6 +111,29 @@ describe.only('Checkbox', () => {
expect(component.find('Checkbox Text').last().text()).toEqual('Foo');
});

it('should check that the onPress and onValueChange is binded correctly', async () => {
const onPressFunc = jest.fn();
const onValueChangeFunc = jest.fn();

const BBCheckbox = getComponent('Checkbox');

const component = mount(
<BlueBaseApp components={{ Checkbox }}>
<BBCheckbox color="default" onPress={onPressFunc} value={1} onValueChange={onValueChangeFunc} />
</BlueBaseApp>
);

await waitForElement(component as any, BBCheckbox);

const onPress = component.find('TouchableHighlight').last().prop('onPress') as any;
onPress();
expect(onPressFunc).toBeCalled();

const onValueChange = component.find('TouchableHighlight').last().prop('onValueChange') as any;
onValueChange();
expect(onValueChangeFunc).toBeCalledWith(1, true);
});

});