Files
iNaturalistReactNative/tests/unit/components/SharedComponents/Buttons/Button.dark.test.js
Johannes Klein 66a0eda08d Dark mode styling button changes (#938)
* Add dark mode button snapshot tests

* Refactor dark mode styles to be a single function call

* Remove neutral button dark mode styling
2023-11-30 23:03:40 +01:00

57 lines
1.6 KiB
JavaScript

import { render, screen } from "@testing-library/react-native";
import { Button } from "components/SharedComponents";
import React from "react";
// Mock Appearance.getColorScheme()
jest.mock( "react-native/Libraries/Utilities/Appearance", () => {
const actualAppearance = jest.requireActual( "react-native/Libraries/Utilities/Appearance" );
return {
...actualAppearance,
getColorScheme: jest.fn( () => "dark" )
};
} );
// Mock nativewind useColorScheme()
jest.mock( "nativewind", () => {
const actualNativewind = jest.requireActual( "nativewind" );
return {
...actualNativewind,
useColorScheme: jest.fn( () => ( { colorScheme: "dark" } ) )
};
} );
describe.each( [["primary"], ["warning"], ["focus"], ["neutral"]] )(
"Button %s in dark mode",
level => {
it( "should render correctly", () => {
render( <Button level={level} text={`${level.toUpperCase()} BUTTON`} /> );
// Snapshot test
expect( screen ).toMatchSnapshot();
} );
it( "has no accessibility errors", () => {
const button = <Button level={level} text={`${level.toUpperCase()} BUTTON`} />;
expect( button ).toBeAccessible();
} );
describe( "when disabled", () => {
it( "should render correctly", () => {
render( <Button level={level} text={`${level.toUpperCase()} DISABLED`} disabled /> );
// Snapshot test
expect( screen ).toMatchSnapshot();
} );
it( "has no accessibility errors", () => {
const button = (
<Button level={level} text={`${level.toUpperCase()} DISABLED`} disabled />
);
expect( button ).toBeAccessible();
} );
} );
}
);