From 2276e17310df342762147ba7f1166f7d4a3f22dc Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Thu, 1 Oct 2020 17:05:26 -0700 Subject: [PATCH] Add to CheckBox tests --- .../__snapshots__/index-test.js.snap | 99 +++++++++++++++++++ .../exports/CheckBox/__tests__/index-test.js | 91 ++++++++++++++++- 2 files changed, 186 insertions(+), 4 deletions(-) create mode 100644 packages/react-native-web/src/exports/CheckBox/__tests__/__snapshots__/index-test.js.snap diff --git a/packages/react-native-web/src/exports/CheckBox/__tests__/__snapshots__/index-test.js.snap b/packages/react-native-web/src/exports/CheckBox/__tests__/__snapshots__/index-test.js.snap new file mode 100644 index 00000000..a4a71914 --- /dev/null +++ b/packages/react-native-web/src/exports/CheckBox/__tests__/__snapshots__/index-test.js.snap @@ -0,0 +1,99 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`CheckBox prop "accessibilityLabel" value is set 1`] = ` +
+
+ +
+`; + +exports[`CheckBox prop "color" value is set 1`] = ` +
+
+ +
+`; + +exports[`CheckBox prop "dataSet" value is set 1`] = ` +
+
+ +
+`; + +exports[`CheckBox prop "nativeID" value is set 1`] = ` +
+
+ +
+`; + +exports[`CheckBox prop "style" value is set 1`] = ` +
+
+ +
+`; + +exports[`CheckBox prop "testID" value is set 1`] = ` +
+
+ +
+`; diff --git a/packages/react-native-web/src/exports/CheckBox/__tests__/index-test.js b/packages/react-native-web/src/exports/CheckBox/__tests__/index-test.js index 5eac2d13..f6745f54 100644 --- a/packages/react-native-web/src/exports/CheckBox/__tests__/index-test.js +++ b/packages/react-native-web/src/exports/CheckBox/__tests__/index-test.js @@ -2,6 +2,8 @@ import CheckBox from '../'; import React from 'react'; +import { act } from 'react-dom/test-utils'; +import { createEventTarget } from 'dom-event-testing-library'; import { render } from '@testing-library/react'; function findCheckbox(container) { @@ -9,7 +11,28 @@ function findCheckbox(container) { } describe('CheckBox', () => { - describe('disabled', () => { + describe('prop "accessibilityLabel"', () => { + test('value is set', () => { + const { container } = render(); + expect(container.firstChild).toMatchSnapshot(); + }); + }); + + describe('prop "color"', () => { + test('value is set', () => { + const { container } = render(); + expect(container.firstChild).toMatchSnapshot(); + }); + }); + + describe('prop "dataSet"', () => { + test('value is set', () => { + const { container } = render(); + expect(container.firstChild).toMatchSnapshot(); + }); + }); + + describe('prop "disabled"', () => { test('when "false" a default checkbox is rendered', () => { const { container } = render(); expect(findCheckbox(container).disabled).toBe(false); @@ -21,7 +44,30 @@ describe('CheckBox', () => { }); }); - describe('onChange', () => { + describe('prop "nativeID"', () => { + test('value is set', () => { + const { container } = render(); + expect(container.firstChild).toMatchSnapshot(); + }); + }); + + describe('prop "onBlur"', () => { + test('is called', () => { + const onBlur = jest.fn(); + const ref = React.createRef(); + act(() => { + render(); + }); + const target = createEventTarget(ref.current); + act(() => { + target.focus(); + target.blur(); + }); + expect(onBlur).toBeCalled(); + }); + }); + + describe('prop "onChange"', () => { test('is called with the event object', () => { const onChange = jest.fn(); const { container } = render(); @@ -31,7 +77,22 @@ describe('CheckBox', () => { }); }); - describe('onValueChange', () => { + describe('prop "onFocus"', () => { + test('is called', () => { + const onFocus = jest.fn(); + const ref = React.createRef(); + act(() => { + render(); + }); + const target = createEventTarget(ref.current); + act(() => { + target.focus(); + }); + expect(onFocus).toBeCalled(); + }); + }); + + describe('prop "onValueChange"', () => { test('when value is "false" it receives "true"', () => { const onValueChange = jest.fn(); const { container } = render(); @@ -49,7 +110,29 @@ describe('CheckBox', () => { }); }); - describe('value', () => { + describe('prop "ref"', () => { + test('value is set', () => { + const ref = jest.fn(); + render(); + expect(ref).toBeCalled(); + }); + }); + + describe('prop "style"', () => { + test('value is set', () => { + const { container } = render(); + expect(container.firstChild).toMatchSnapshot(); + }); + }); + + describe('prop "testID"', () => { + test('value is set', () => { + const { container } = render(); + expect(container.firstChild).toMatchSnapshot(); + }); + }); + + describe('prop "value"', () => { test('when "false" an unchecked checkbox is rendered', () => { const { container } = render(); expect(findCheckbox(container).checked).toBe(false);