Add to View tests

This commit is contained in:
Nicolas Gallagher
2020-10-05 14:28:27 -07:00
parent 92ac1f94c5
commit 72bfe499c5
2 changed files with 164 additions and 0 deletions
@@ -1,5 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/View allows "dir" to be overridden 1`] = `
<div
class="css-view-1dbjc4n"
/>
`;
exports[`components/View default 1`] = `
<div
class="css-view-1dbjc4n"
@@ -17,8 +23,67 @@ exports[`components/View non-text is rendered 1`] = `
</div>
`;
exports[`components/View prop "accessibilityLabel" value is set 1`] = `
<div
aria-label="accessibility label"
class="css-view-1dbjc4n"
/>
`;
exports[`components/View prop "accessibilityLiveRegion" value is set 1`] = `
<div
aria-live="polite"
class="css-view-1dbjc4n"
/>
`;
exports[`components/View prop "accessibilityRole" value alters HTML element 1`] = `
<a
class="css-reset-4rbku5 css-cursor-18t94o4 css-view-1dbjc4n"
data-focusable="true"
role="link"
/>
`;
exports[`components/View prop "accessibilityRole" value is "button" 1`] = `
<div
class="css-cursor-18t94o4 css-view-1dbjc4n"
data-focusable="true"
role="button"
tabindex="0"
/>
`;
exports[`components/View prop "accessibilityRole" value is set 1`] = `
<div
class="css-view-1dbjc4n"
role="presentation"
/>
`;
exports[`components/View prop "nativeID" value is set 1`] = `
<div
class="css-view-1dbjc4n"
id="nativeID"
/>
`;
exports[`components/View prop "pointerEvents" 1`] = `
<div
class="css-view-1dbjc4n r-pointerEvents-ah5dr5"
/>
`;
exports[`components/View prop "style" value is set 1`] = `
<div
class="css-view-1dbjc4n"
style="border-top-width: 5px; border-right-width: 5px; border-bottom-width: 5px; border-left-width: 5px;"
/>
`;
exports[`components/View prop "testID" value is set 1`] = `
<div
class="css-view-1dbjc4n"
data-testid="123"
/>
`;
@@ -2,6 +2,8 @@
import React from 'react';
import View from '../';
import { act } from 'react-dom/test-utils';
import { createEventTarget } from 'dom-event-testing-library';
import { render } from '@testing-library/react';
describe('components/View', () => {
@@ -43,8 +45,105 @@ describe('components/View', () => {
});
});
describe('prop "accessibilityLabel"', () => {
test('value is set', () => {
const { container } = render(<View accessibilityLabel="accessibility label" />);
expect(container.firstChild).toMatchSnapshot();
});
});
describe('prop "accessibilityLiveRegion"', () => {
test('value is set', () => {
const { container } = render(<View accessibilityLiveRegion="polite" />);
expect(container.firstChild).toMatchSnapshot();
});
});
describe('prop "accessibilityRole"', () => {
test('value is set', () => {
const { container } = render(<View accessibilityRole="none" />);
expect(container.firstChild).toMatchSnapshot();
});
test('value is "button"', () => {
const { container } = render(<View accessibilityRole="button" />);
expect(container.firstChild).toMatchSnapshot();
});
test('value alters HTML element', () => {
const { container } = render(<View accessibilityRole="link" />);
expect(container.firstChild).toMatchSnapshot();
});
});
test('allows "dir" to be overridden', () => {
const { container } = render(<View dir="rtl" />);
expect(container.firstChild).toMatchSnapshot();
});
describe('prop "nativeID"', () => {
test('value is set', () => {
const { container } = render(<View nativeID="nativeID" />);
expect(container.firstChild).toMatchSnapshot();
});
});
describe('prop "onBlur"', () => {
test('is called', () => {
const onBlur = jest.fn();
const ref = React.createRef();
act(() => {
render(<View onBlur={onBlur} ref={ref} />);
});
const target = createEventTarget(ref.current);
act(() => {
target.focus();
target.blur();
});
expect(onBlur).toBeCalled();
});
});
describe('prop "onFocus"', () => {
test('is called', () => {
const onFocus = jest.fn();
const ref = React.createRef();
act(() => {
render(<View onFocus={onFocus} ref={ref} />);
});
const target = createEventTarget(ref.current);
act(() => {
target.focus();
target.blur();
});
expect(onFocus).toBeCalled();
});
});
describe('prop "ref"', () => {
test('value is set', () => {
const ref = jest.fn();
render(<View ref={ref} />);
expect(ref).toBeCalled();
});
});
test('prop "pointerEvents"', () => {
const { container } = render(<View pointerEvents="box-only" />);
expect(container.firstChild).toMatchSnapshot();
});
describe('prop "style"', () => {
test('value is set', () => {
const { container } = render(<View style={{ borderWidth: 5 }} />);
expect(container.firstChild).toMatchSnapshot();
});
});
describe('prop "testID"', () => {
test('value is set', () => {
const { container } = render(<View testID="123" />);
expect(container.firstChild).toMatchSnapshot();
});
});
});