Skip to content
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

Split checkbox tests into their own files #3833

Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { View } from 'react-native';

import { Checkbox } from '@fluentui-react-native/experimental-checkbox';
import type { InteractionEvent } from '@fluentui-react-native/interactive-hooks';

function onChangeUncontrolled(_e: InteractionEvent, isChecked: boolean) {
console.log(isChecked);
}

export const BasicCheckbox: React.FunctionComponent = () => {
return (
<View>
<Checkbox label="Unchecked checkbox (undefined)" onChange={onChangeUncontrolled} />
<Checkbox label="Unchecked checkbox (uncontrolled)" onChange={onChangeUncontrolled} defaultChecked={false} />
<Checkbox label="Checked checkbox (uncontrolled)" onChange={onChangeUncontrolled} defaultChecked accessibilityLabel="Hello there" />
<Checkbox label="Disabled checkbox" disabled />
<Checkbox label="Disabled checked checkbox" defaultChecked disabled />
<Checkbox label="A required checkbox" required />
</View>
);
};
178 changes: 6 additions & 172 deletions apps/fluent-tester/src/TestComponents/CheckboxV1/CheckboxV1Test.tsx
Original file line number Diff line number Diff line change
@@ -1,181 +1,15 @@
import * as React from 'react';
import { View, TextInput, Platform } from 'react-native';

import { ButtonV1 as Button } from '@fluentui-react-native/button';
import { Checkbox } from '@fluentui-react-native/experimental-checkbox';
import type { InteractionEvent } from '@fluentui-react-native/interactive-hooks';
import type { Theme } from '@fluentui-react-native/theme-types';
import { useTheme } from '@fluentui-react-native/theme-types';
import { themedStyleSheet } from '@fluentui-react-native/themed-stylesheet';
import { Platform } from 'react-native';

import { E2ECheckboxV1Test } from './E2ECheckboxV1Test';
import { CHECKBOXV1_TESTPAGE } from '../../../../E2E/src/CheckboxV1/consts';
import { commonTestStyles as commonStyles, mobileStyles } from '../Common/styles';
import type { TestSection, PlatformStatus } from '../Test';
import { Test } from '../Test';

function onChangeUncontrolled(_e: InteractionEvent, isChecked: boolean) {
console.log(isChecked);
}

const BasicCheckbox: React.FunctionComponent = () => {
return (
<View>
<Checkbox label="Unchecked checkbox (undefined)" onChange={onChangeUncontrolled} />
<Checkbox label="Unchecked checkbox (uncontrolled)" onChange={onChangeUncontrolled} defaultChecked={false} />
<Checkbox label="Checked checkbox (uncontrolled)" onChange={onChangeUncontrolled} defaultChecked accessibilityLabel="Hello there" />
<Checkbox label="Disabled checkbox" disabled />
<Checkbox label="Disabled checked checkbox" defaultChecked disabled />
<Checkbox label="A required checkbox" required />
</View>
);
};

const DesktopSpecificCheckbox: React.FunctionComponent = () => {
return (
<>
<Checkbox label="Checkbox will display a tooltip" tooltip="This is a tooltip" />
<Checkbox label="A circular checkbox" shape="circular" />
<Checkbox label="A checkbox with label placed before" labelPosition="before" />
</>
);
};

const SizeCheckbox: React.FunctionComponent = () => {
return (
<View>
<Checkbox tooltip="Medium checkbox" size="medium" />
<Checkbox tooltip="Large checkbox" size="large" />
<Checkbox label="Medium checkbox" size="medium" />
<Checkbox label="Large checkbox" size="large" />
</View>
);
};

const OtherCheckbox: React.FunctionComponent = () => {
const [isChecked, setisChecked] = React.useState(false);

const setCheckedTrue = React.useCallback(() => {
setisChecked(true);
}, []);

const setCheckedFalse = React.useCallback(() => {
setisChecked(false);
}, []);

const memoizedStyles = React.useMemo(() => (Platform.OS === 'android' ? { ...mobileStyles.containerSpacedEvenly, height: 150 } : {}), []);

return (
<View style={memoizedStyles}>
<Button onClick={setCheckedTrue} size="small">
Check controlled checkboxes below
</Button>
<Button onClick={setCheckedFalse} size="small">
Uncheck controlled checkboxes below
</Button>

<Checkbox label="This is a controlled Checkbox" checked={isChecked} />
{Platform.OS !== 'android' && (
<>
<Checkbox label="Checkbox rendered with labelPosition 'before' (controlled)" labelPosition="before" checked={isChecked} />
<Checkbox label="A required checkbox with other required text" required="**" />
</>
)}
</View>
);
};

const CircleColorCheckbox = Checkbox.customize({
checked: {
checkboxBackgroundColor: 'green',
checkboxBorderColor: 'green',
checkmarkColor: 'white',
},
});

const HoverCheckbox = Checkbox.customize({
hovered: {
checkmarkOpacity: 1,
},
});

const BigLabelCheckbox = Checkbox.customize({
label: {
fontSize: 24,
fontWeight: 'bold',
},
});

const ComposedCheckbox = Checkbox.compose({
slotProps: {
label: { style: { color: 'hotpink' } },
},
});

const getThemedStyles = themedStyleSheet((t: Theme) => {
return { textbox: { ...commonStyles.textBox, borderColor: t.colors.inputBorder } };
});

const TokenCheckbox: React.FunctionComponent = () => {
const [checkboxColor, setCheckboxColor] = React.useState('blue');
const [checkmarkColor, setCheckmarkColor] = React.useState('white');

const BlueCheckbox = Checkbox.customize({
checked: {
checkboxBackgroundColor: checkboxColor,
checkboxBorderColor: checkboxColor,
checkmarkColor: checkmarkColor,
},
});

const theme = useTheme();
const textBoxBorderStyle = getThemedStyles(theme);

return (
<View>
{Platform.OS !== 'android' && (
<>
<HoverCheckbox label="A checkbox with checkmark visible on hover" onChange={onChangeUncontrolled} />
<CircleColorCheckbox
label="A circular token-customized checkbox"
shape="circular"
onChange={onChangeUncontrolled}
defaultChecked
/>
</>
)}

<BigLabelCheckbox label="A checkbox with a bold large font label" />
<ComposedCheckbox label="A checkbox with a hot pink label and no padding" />

<BlueCheckbox
label="Token-customized checkbox. Customizable below."
onChange={onChangeUncontrolled}
labelPosition="before"
defaultChecked={false}
/>
<TextInput
accessibilityLabel="Background color"
style={textBoxBorderStyle.textbox}
placeholder="Background color"
blurOnSubmit={true}
onSubmitEditing={(e) => {
setCheckboxColor(e.nativeEvent.text);
}}
/>

<TextInput
accessibilityLabel="Checkmark color"
style={textBoxBorderStyle.textbox}
placeholder="Checkmark color"
blurOnSubmit={true}
onSubmitEditing={(e) => {
setCheckmarkColor(e.nativeEvent.text);
}}
/>
</View>
);
};
import { BasicCheckbox } from './BasicCheckboxTest';
import { DesktopSpecificCheckbox } from './DesktopSpecificCheckboxTest';
import { OtherCheckbox } from './OtherCheckboxPropsTest';
import { SizeCheckbox } from './SizeCheckboxTest';
import { TokenCheckbox } from './TokenCheckboxTest';

const checkboxSections: TestSection[] = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';

import { Checkbox } from '@fluentui-react-native/experimental-checkbox';

export const DesktopSpecificCheckbox: React.FunctionComponent = () => {
return (
<>
<Checkbox label="Checkbox will display a tooltip" tooltip="This is a tooltip" />
<Checkbox label="A circular checkbox" shape="circular" />
<Checkbox label="A checkbox with label placed before" labelPosition="before" />
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import { Platform, View } from 'react-native';

import { ButtonV1 as Button } from '@fluentui-react-native/button';
import { Checkbox } from '@fluentui-react-native/experimental-checkbox';

import { mobileStyles } from '../Common/styles';

export const OtherCheckbox: React.FunctionComponent = () => {
const [isChecked, setisChecked] = React.useState(false);

const setCheckedTrue = React.useCallback(() => {
setisChecked(true);
}, []);

const setCheckedFalse = React.useCallback(() => {
setisChecked(false);
}, []);

const memoizedStyles = React.useMemo(() => (Platform.OS === 'android' ? { ...mobileStyles.containerSpacedEvenly, height: 150 } : {}), []);

return (
<View style={memoizedStyles}>
<Button onClick={setCheckedTrue} size="small">
Check controlled checkboxes below
</Button>
<Button onClick={setCheckedFalse} size="small">
Uncheck controlled checkboxes below
</Button>

<Checkbox label="This is a controlled Checkbox" checked={isChecked} />
{Platform.OS !== 'android' && (
<>
<Checkbox label="Checkbox rendered with labelPosition 'before' (controlled)" labelPosition="before" checked={isChecked} />
<Checkbox label="A required checkbox with other required text" required="**" />
</>
)}
</View>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';

import { Checkbox } from '@fluentui-react-native/experimental-checkbox';

export const SizeCheckbox: React.FunctionComponent = () => {
return (
<>
<Checkbox tooltip="Medium checkbox" size="medium" />
<Checkbox tooltip="Large checkbox" size="large" />
<Checkbox label="Medium checkbox" size="medium" />
<Checkbox label="Large checkbox" size="large" />
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import React from 'react';
import { View, TextInput, Platform } from 'react-native';

import { Checkbox } from '@fluentui-react-native/experimental-checkbox';
import type { InteractionEvent } from '@fluentui-react-native/interactive-hooks';
import type { Theme } from '@fluentui-react-native/theme-types';
import { useTheme } from '@fluentui-react-native/theme-types';
import { themedStyleSheet } from '@fluentui-react-native/themed-stylesheet';

import { commonTestStyles as commonStyles } from '../Common/styles';

function onChangeUncontrolled(_e: InteractionEvent, isChecked: boolean) {
console.log(isChecked);
}

const CircleColorCheckbox = Checkbox.customize({
checked: {
checkboxBackgroundColor: 'green',
checkboxBorderColor: 'green',
checkmarkColor: 'white',
},
});

const HoverCheckbox = Checkbox.customize({
hovered: {
checkmarkOpacity: 1,
},
});

const BigLabelCheckbox = Checkbox.customize({
label: {
fontSize: 24,
fontWeight: 'bold',
},
});

const ComposedCheckbox = Checkbox.compose({
slotProps: {
label: { style: { color: 'hotpink' } },
},
});

const getThemedStyles = themedStyleSheet((t: Theme) => {
return { textbox: { ...commonStyles.textBox, borderColor: t.colors.inputBorder } };
});

export const TokenCheckbox: React.FunctionComponent = () => {
const [checkboxColor, setCheckboxColor] = React.useState('blue');
const [checkmarkColor, setCheckmarkColor] = React.useState('white');

const BlueCheckbox = Checkbox.customize({
checked: {
checkboxBackgroundColor: checkboxColor,
checkboxBorderColor: checkboxColor,
checkmarkColor: checkmarkColor,
},
});

const theme = useTheme();
const textBoxBorderStyle = getThemedStyles(theme);

return (
<View>
{Platform.OS !== 'android' && (
<>
<HoverCheckbox label="A checkbox with checkmark visible on hover" onChange={onChangeUncontrolled} />
<CircleColorCheckbox
label="A circular token-customized checkbox"
shape="circular"
onChange={onChangeUncontrolled}
defaultChecked
/>
</>
)}

<BigLabelCheckbox label="A checkbox with a bold large font label" />
<ComposedCheckbox label="A checkbox with a hot pink label and no padding" />

<BlueCheckbox
label="Token-customized checkbox. Customizable below."
onChange={onChangeUncontrolled}
labelPosition="before"
defaultChecked={false}
/>
<TextInput
accessibilityLabel="Background color"
style={textBoxBorderStyle.textbox}
placeholder="Background color"
blurOnSubmit={true}
onSubmitEditing={(e) => {
setCheckboxColor(e.nativeEvent.text);
}}
/>

<TextInput
accessibilityLabel="Checkmark color"
style={textBoxBorderStyle.textbox}
placeholder="Checkmark color"
blurOnSubmit={true}
onSubmitEditing={(e) => {
setCheckmarkColor(e.nativeEvent.text);
}}
/>
</View>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Split up checkbox tests into their own files",
"packageName": "@fluentui-react-native/tester",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Loading