Add to Text tests

This commit is contained in:
Nicolas Gallagher
2020-10-05 13:14:38 -07:00
parent 5edba02319
commit 92ac1f94c5
2 changed files with 192 additions and 1 deletions
@@ -26,6 +26,64 @@ exports[`components/Text nested 1`] = `
</div>
`;
exports[`components/Text prop "accessibilityLabel" value is set 1`] = `
<div
aria-label="accessibility label"
class="css-text-901oao"
dir="auto"
/>
`;
exports[`components/Text prop "accessibilityLiveRegion" value is set 1`] = `
<div
aria-live="polite"
class="css-text-901oao"
dir="auto"
/>
`;
exports[`components/Text prop "accessibilityRole" value alters HTML element 1`] = `
<a
class="css-reset-4rbku5 css-cursor-18t94o4 css-text-901oao"
data-focusable="true"
dir="auto"
role="link"
/>
`;
exports[`components/Text prop "accessibilityRole" value is "button" 1`] = `
<div
class="css-cursor-18t94o4 css-text-901oao"
data-focusable="true"
dir="auto"
role="button"
tabindex="0"
/>
`;
exports[`components/Text prop "accessibilityRole" value is set 1`] = `
<div
class="css-text-901oao"
dir="auto"
role="presentation"
/>
`;
exports[`components/Text prop "nativeID" value is set 1`] = `
<div
class="css-text-901oao"
dir="auto"
id="nativeID"
/>
`;
exports[`components/Text prop "numberOfLines" value is set 1`] = `
<div
class="css-text-901oao css-textMultiLine-cens5h"
dir="auto"
/>
`;
exports[`components/Text prop "selectable" value of false 1`] = `
<div
class="css-text-901oao r-userSelect-lrvibr"
@@ -39,3 +97,19 @@ exports[`components/Text prop "selectable" value of true 1`] = `
dir="auto"
/>
`;
exports[`components/Text prop "style" value is set 1`] = `
<div
class="css-text-901oao"
dir="auto"
style="border-top-width: 5px; border-right-width: 5px; border-bottom-width: 5px; border-left-width: 5px;"
/>
`;
exports[`components/Text prop "testID" value is set 1`] = `
<div
class="css-text-901oao"
data-testid="123"
dir="auto"
/>
`;
@@ -2,8 +2,10 @@
/* eslint-disable react/jsx-no-bind */
import React from 'react';
import { render } from '@testing-library/react';
import Text from '../';
import { act } from 'react-dom/test-utils';
import { createEventTarget } from 'dom-event-testing-library';
import { render } from '@testing-library/react';
describe('components/Text', () => {
test('default', () => {
@@ -16,11 +18,112 @@ describe('components/Text', () => {
expect(container.firstChild).toMatchSnapshot();
});
describe('prop "accessibilityLabel"', () => {
test('value is set', () => {
const { container } = render(<Text accessibilityLabel="accessibility label" />);
expect(container.firstChild).toMatchSnapshot();
});
});
describe('prop "accessibilityLiveRegion"', () => {
test('value is set', () => {
const { container } = render(<Text accessibilityLiveRegion="polite" />);
expect(container.firstChild).toMatchSnapshot();
});
});
describe('prop "accessibilityRole"', () => {
test('value is set', () => {
const { container } = render(<Text accessibilityRole="none" />);
expect(container.firstChild).toMatchSnapshot();
});
test('value is "button"', () => {
const { container } = render(<Text accessibilityRole="button" />);
expect(container.firstChild).toMatchSnapshot();
});
test('value alters HTML element', () => {
const { container } = render(<Text accessibilityRole="link" />);
expect(container.firstChild).toMatchSnapshot();
});
});
test('allows "dir" to be overridden', () => {
const { container } = render(<Text dir="rtl" />);
expect(container.firstChild).toMatchSnapshot();
});
describe('prop "nativeID"', () => {
test('value is set', () => {
const { container } = render(<Text nativeID="nativeID" />);
expect(container.firstChild).toMatchSnapshot();
});
});
describe('prop "numberOfLines"', () => {
test('value is set', () => {
const { container } = render(<Text numberOfLines="3" />);
expect(container.firstChild).toMatchSnapshot();
});
});
describe('prop "onBlur"', () => {
test('is called', () => {
const onBlur = jest.fn();
const ref = React.createRef();
act(() => {
render(<Text 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(<Text onFocus={onFocus} ref={ref} />);
});
const target = createEventTarget(ref.current);
act(() => {
target.focus();
target.blur();
});
expect(onFocus).toBeCalled();
});
});
describe('prop "onPress"', () => {
test('is called', () => {
const onPress = jest.fn();
const ref = React.createRef();
act(() => {
render(<Text onPress={onPress} ref={ref} />);
});
const target = createEventTarget(ref.current);
act(() => {
target.pointerdown();
target.pointerup();
});
expect(onPress).toBeCalled();
});
});
describe('prop "ref"', () => {
test('value is set', () => {
const ref = jest.fn();
render(<Text ref={ref} />);
expect(ref).toBeCalled();
});
});
describe('prop "selectable"', () => {
test('value of false', () => {
const { container } = render(<Text selectable={false} />);
@@ -32,4 +135,18 @@ describe('components/Text', () => {
expect(container.firstChild).toMatchSnapshot();
});
});
describe('prop "style"', () => {
test('value is set', () => {
const { container } = render(<Text style={{ borderWidth: 5 }} />);
expect(container.firstChild).toMatchSnapshot();
});
});
describe('prop "testID"', () => {
test('value is set', () => {
const { container } = render(<Text testID="123" />);
expect(container.firstChild).toMatchSnapshot();
});
});
});