@brightlayer-ui/react-native-auth-workflow
Version:
Re-usable workflow components for Authentication and Registration within Eaton applications.
83 lines (82 loc) • 5.97 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { cleanup, render } from '@testing-library/react-native';
import { WorkflowCard, WorkflowCardBody, WorkflowCardHeader } from '../../../components/index.js';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { Text } from 'react-native-paper';
import { Dimensions } from 'react-native';
// Mock Dimensions to control tablet/mobile mode
const mockDimensions = (width, height) => {
jest.spyOn(Dimensions, 'get').mockReturnValue({ width, height, scale: 1, fontScale: 1 });
};
describe('WorkflowCard Test', () => {
afterEach(() => {
cleanup();
jest.restoreAllMocks();
});
it('WorkflowCard renders correctly with loading', () => {
mockDimensions(375, 812); // Mobile dimensions
const { toJSON } = render(_jsx(SafeAreaProvider, { children: _jsx(WorkflowCard, { loading: true, children: _jsx(WorkflowCardBody, { children: _jsx(Text, { children: "This is workflow card body content." }) }) }) }));
expect(toJSON()).toBeTruthy();
});
it('WorkflowCard renders correctly without loading', () => {
mockDimensions(375, 812); // Mobile dimensions
const { toJSON } = render(_jsx(SafeAreaProvider, { children: _jsx(WorkflowCard, { loading: false, children: _jsx(WorkflowCardBody, { children: _jsx(Text, { children: "This is workflow card body content." }) }) }) }));
expect(toJSON()).toBeTruthy();
});
it('WorkflowCard renders correctly with WorkflowCardHeader', () => {
mockDimensions(375, 812); // Mobile dimensions
const { toJSON } = render(_jsx(SafeAreaProvider, { children: _jsxs(WorkflowCard, { children: [_jsx(WorkflowCardHeader, { title: "Test Title" }), _jsx(WorkflowCardBody, { children: _jsx(Text, { children: "This is workflow card body content." }) })] }) }));
expect(toJSON()).toBeTruthy();
});
it('WorkflowCard renders correctly without WorkflowCardHeader', () => {
mockDimensions(375, 812); // Mobile dimensions
const { toJSON } = render(_jsx(SafeAreaProvider, { children: _jsx(WorkflowCard, { children: _jsx(Text, { children: "This is workflow card body content." }) }) }));
expect(toJSON()).toBeTruthy();
});
it('WorkflowCard renders correctly on tablet', () => {
mockDimensions(1024, 768); // Tablet dimensions
const { toJSON } = render(_jsx(SafeAreaProvider, { children: _jsx(WorkflowCard, { children: _jsx(WorkflowCardBody, { children: _jsx(Text, { children: "This is workflow card body content." }) }) }) }));
expect(toJSON()).toBeTruthy();
});
it('WorkflowCard renders correctly on mobile', () => {
mockDimensions(375, 812); // Mobile dimensions
const { toJSON } = render(_jsx(SafeAreaProvider, { children: _jsx(WorkflowCard, { children: _jsx(WorkflowCardBody, { children: _jsx(Text, { children: "This is workflow card body content." }) }) }) }));
expect(toJSON()).toBeTruthy();
});
it('WorkflowCard renders with custom backgroundImage', () => {
mockDimensions(375, 812); // Mobile dimensions
const customImage = { uri: 'https://example.com/image.png' };
const { toJSON } = render(_jsx(SafeAreaProvider, { children: _jsx(WorkflowCard, { backgroundImage: customImage, children: _jsx(WorkflowCardBody, { children: _jsx(Text, { children: "This is workflow card body content." }) }) }) }));
expect(toJSON()).toBeTruthy();
});
it('WorkflowCard renders without custom backgroundImage (uses default)', () => {
mockDimensions(375, 812); // Mobile dimensions
const { toJSON } = render(_jsx(SafeAreaProvider, { children: _jsx(WorkflowCard, { children: _jsx(WorkflowCardBody, { children: _jsx(Text, { children: "This is workflow card body content." }) }) }) }));
expect(toJSON()).toBeTruthy();
});
it('WorkflowCard renders with style as array', () => {
mockDimensions(375, 812); // Mobile dimensions
const { toJSON } = render(_jsx(SafeAreaProvider, { children: _jsx(WorkflowCard, { style: [{ opacity: 0.9 }, { marginTop: 10 }], children: _jsx(WorkflowCardBody, { children: _jsx(Text, { children: "This is workflow card body content." }) }) }) }));
expect(toJSON()).toBeTruthy();
});
it('WorkflowCard renders with style as object', () => {
mockDimensions(375, 812); // Mobile dimensions
const { toJSON } = render(_jsx(SafeAreaProvider, { children: _jsx(WorkflowCard, { style: { opacity: 0.9 }, children: _jsx(WorkflowCardBody, { children: _jsx(Text, { children: "This is workflow card body content." }) }) }) }));
expect(toJSON()).toBeTruthy();
});
it('WorkflowCard renders on tablet without WorkflowCardHeader', () => {
mockDimensions(1024, 768); // Tablet dimensions
const { toJSON } = render(_jsx(SafeAreaProvider, { children: _jsx(WorkflowCard, { children: _jsx(WorkflowCardBody, { children: _jsx(Text, { children: "This is workflow card body content." }) }) }) }));
expect(toJSON()).toBeTruthy();
});
it('WorkflowCard renders on tablet with WorkflowCardHeader', () => {
mockDimensions(1024, 768); // Tablet dimensions
const { toJSON } = render(_jsx(SafeAreaProvider, { children: _jsxs(WorkflowCard, { children: [_jsx(WorkflowCardHeader, { title: "Test Title" }), _jsx(WorkflowCardBody, { children: _jsx(Text, { children: "This is workflow card body content." }) })] }) }));
expect(toJSON()).toBeTruthy();
});
it('WorkflowCard passes additional ImageBackgroundProps', () => {
mockDimensions(375, 812); // Mobile dimensions
const { toJSON } = render(_jsx(SafeAreaProvider, { children: _jsx(WorkflowCard, { imageStyle: { opacity: 0.5 }, testID: "workflow-card-bg", children: _jsx(WorkflowCardBody, { children: _jsx(Text, { children: "This is workflow card body content." }) }) }) }));
expect(toJSON()).toBeTruthy();
});
});