Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createElement } from "react";
import { render } from "@testing-library/react-native";
import { render, act } from "@testing-library/react-native";
import { IntroScreen } from "../IntroScreen";
import { IntroScreenProps } from "../../typings/IntroScreenProps";
import { IntroScreenStyle } from "../ui/Styles";
import { View } from "react-native";
import { InteractionManager, View } from "react-native";
import { EditableValueBuilder } from "@mendix/piw-utils-internal";
import { Big } from "big.js";

Expand All @@ -13,10 +13,13 @@ jest.mock("react-native-device-info", () => ({
}));

jest.mock("@react-native-async-storage/async-storage", () => ({
getItem: jest.fn().mockResolvedValue("gone"),
setValue: jest.fn().mockResolvedValue(null)
getItem: jest.fn().mockResolvedValue(null),
setItem: jest.fn().mockResolvedValue(null)
}));

const flushInteractions = (): Promise<void> =>
act(() => new Promise<void>(resolve => InteractionManager.runAfterInteractions(resolve)));

describe("Intro Screen", () => {
let defaultProps: IntroScreenProps<IntroScreenStyle>;

Expand All @@ -36,39 +39,42 @@ describe("Intro Screen", () => {
hideIndicatorLastSlide: false,
identifier: ""
};

jest.useFakeTimers();
});

it("renders", () => {
it("renders", async () => {
const component = render(<IntroScreen {...defaultProps} />);
await flushInteractions();
expect(component.toJSON()).toMatchSnapshot();
});

it("renders with 1 bottom button", () => {
it("renders with 1 bottom button", async () => {
const component = render(
<IntroScreen {...defaultProps} slideIndicators={"above"} buttonPattern={"nextDone"} />
);
await flushInteractions();
expect(component.toJSON()).toMatchSnapshot();
});

it("renders with 2 bottom button", () => {
it("renders with 2 bottom button", async () => {
const component = render(<IntroScreen {...defaultProps} slideIndicators={"above"} buttonPattern={"all"} />);
await flushInteractions();
expect(component.toJSON()).toMatchSnapshot();
});

it("renders with active slide attribute", () => {
it("renders with active slide attribute", async () => {
const component = render(
<IntroScreen
{...defaultProps}
activeSlideAttribute={new EditableValueBuilder<Big>().withValue(new Big(1)).build()}
/>
);
await flushInteractions();
expect(component.toJSON()).toMatchSnapshot();
});

it("renders with async storage identifier", () => {
it("renders with async storage identifier", async () => {
const component = render(<IntroScreen {...defaultProps} identifier="test1" />);
await flushInteractions();
expect(component.toJSON()).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createElement } from "react";
import { render } from "@testing-library/react-native";
import { render, act } from "@testing-library/react-native";
import { InteractionManager, View } from "react-native";
import { IntroScreen } from "../IntroScreen";
import { IntroScreenProps } from "../../typings/IntroScreenProps";
import { IntroScreenStyle } from "../ui/Styles";
import { View } from "react-native";
import { EditableValueBuilder } from "@mendix/piw-utils-internal";
import { Big } from "big.js";

Expand All @@ -13,10 +13,13 @@ jest.mock("react-native-device-info", () => ({
}));

jest.mock("@react-native-async-storage/async-storage", () => ({
getItem: jest.fn().mockResolvedValue("gone"),
setValue: jest.fn().mockResolvedValue(null)
getItem: jest.fn().mockResolvedValue(null),
setItem: jest.fn().mockResolvedValue(null)
}));

const flushInteractions = (): Promise<void> =>
act(() => new Promise<void>(resolve => InteractionManager.runAfterInteractions(resolve)));

describe("Intro Screen", () => {
let defaultProps: IntroScreenProps<IntroScreenStyle>;

Expand All @@ -41,39 +44,42 @@ describe("Intro Screen", () => {
hasNotch: jest.fn(),
getDeviceId: jest.fn().mockReturnValue("iPhone")
}));

jest.useFakeTimers();
});

it("renders", () => {
it("renders", async () => {
const component = render(<IntroScreen {...defaultProps} />);
await flushInteractions();
expect(component.toJSON()).toMatchSnapshot();
});

it("renders with 1 bottom button", () => {
it("renders with 1 bottom button", async () => {
const component = render(
<IntroScreen {...defaultProps} slideIndicators={"above"} buttonPattern={"nextDone"} />
);
await flushInteractions();
expect(component.toJSON()).toMatchSnapshot();
});

it("renders with 2 bottom button", () => {
it("renders with 2 bottom button", async () => {
const component = render(<IntroScreen {...defaultProps} slideIndicators={"above"} buttonPattern={"all"} />);
await flushInteractions();
expect(component.toJSON()).toMatchSnapshot();
});

it("renders with active slide attribute", () => {
it("renders with active slide attribute", async () => {
const component = render(
<IntroScreen
{...defaultProps}
activeSlideAttribute={new EditableValueBuilder<Big>().withValue(new Big(1)).build()}
/>
);
await flushInteractions();
expect(component.toJSON()).toMatchSnapshot();
});

it("renders with async storage identifier", () => {
it("renders with async storage identifier", async () => {
const component = render(<IntroScreen {...defaultProps} identifier="test1" />);
await flushInteractions();
expect(component.toJSON()).toMatchSnapshot();
});
});
Loading
Loading