Skip to content

Commit

Permalink
refactor: add missed scenarios for inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
yjose committed Mar 13, 2024
1 parent 2e3ec67 commit c2e3931
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 0 additions & 1 deletion setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import '@testing-library/react-native/extend-expect';
// react-hook form setup for testing
// @ts-ignore
global.window = {};
Expand Down
11 changes: 10 additions & 1 deletion src/ui/button.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable max-lines-per-function */
import React from 'react';
import { Text } from 'react-native';

import { cleanup, fireEvent, render, screen } from '@/core/test-utils';

Expand All @@ -9,9 +10,17 @@ afterEach(cleanup);

describe('Button component ', () => {
it('should render correctly ', () => {
render(<Button testID="button" disabled={false} />);
render(<Button testID="button" />);
expect(screen.getByTestId('button')).toBeOnTheScreen();
});
it('should render correctly if we add explicit child ', () => {
render(
<Button testID="button">
<Text> Custom child </Text>
</Button>
);
expect(screen.getByText('Custom child')).toBeOnTheScreen();
});
it('should render the label correctly', () => {
render(<Button testID="button" label="Submit" />);
expect(screen.getByTestId('button')).toBeOnTheScreen();
Expand Down
16 changes: 16 additions & 0 deletions src/ui/input.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable max-lines-per-function */
import React from 'react';
import { I18nManager } from 'react-native';

import { cleanup, fireEvent, render, screen } from '@/core/test-utils';

Expand All @@ -12,6 +13,21 @@ describe('Input component ', () => {
render(<Input testID="input" />);
expect(screen.getByTestId('input')).toBeOnTheScreen();
});
it('should use the right direction for rtl layout', () => {
I18nManager.isRTL = true;
render(<Input testID="input" />);
expect(screen.getByTestId('input')).toHaveStyle({
writingDirection: 'rtl',
});
});

it('should use the right direction for ltr layout', () => {
I18nManager.isRTL = false;
render(<Input testID="input" />);
expect(screen.getByTestId('input')).toHaveStyle({
writingDirection: 'ltr',
});
});

it('should render the placeholder correctly ', () => {
render(<Input testID="input" placeholder="Enter your username" />);
Expand Down

0 comments on commit c2e3931

Please sign in to comment.