|
| 1 | +import React from "react"; |
| 2 | +import { render, screen } from "@tests/test-renderer"; |
| 3 | +import { Lottie } from "./index"; |
| 4 | + |
| 5 | +describe("Lottie", () => { |
| 6 | + beforeEach(() => { |
| 7 | + const Config = require("react-native-config").default; |
| 8 | + Config.DETOX = undefined; |
| 9 | + }); |
| 10 | + |
| 11 | + it("renders LottieView when source has uri", () => { |
| 12 | + render(<Lottie source={{ uri: "file:///test.lottie" }} />); |
| 13 | + expect(screen.getByTestId("lottie-source")).toBeOnTheScreen(); |
| 14 | + expect(screen.getByTestId("lottie-mock")).toBeOnTheScreen(); |
| 15 | + expect(screen.getByTestId("lottie-source").props.children).toContain("file:///test.lottie"); |
| 16 | + }); |
| 17 | + |
| 18 | + it("renders empty view when source is null", () => { |
| 19 | + render(<Lottie source={null} />); |
| 20 | + expect(screen.queryByTestId("lottie-mock")).toBeNull(); |
| 21 | + }); |
| 22 | + |
| 23 | + it("renders empty view when source has no uri", () => { |
| 24 | + render(<Lottie source={{ width: 1, height: 1 } as unknown as { uri: string }} />); |
| 25 | + expect(screen.queryByTestId("lottie-mock")).toBeNull(); |
| 26 | + }); |
| 27 | + |
| 28 | + it("uses default testID for detox view", () => { |
| 29 | + const Config = require("react-native-config").default; |
| 30 | + Config.DETOX = "1"; |
| 31 | + render(<Lottie source={{ uri: "file:///test.lottie" }} />); |
| 32 | + expect(screen.getByTestId("lottie-detox")).toBeOnTheScreen(); |
| 33 | + expect(screen.queryByTestId("lottie-mock")).toBeNull(); |
| 34 | + Config.DETOX = undefined; |
| 35 | + }); |
| 36 | + |
| 37 | + it("uses custom testID for detox view when provided", () => { |
| 38 | + const Config = require("react-native-config").default; |
| 39 | + Config.DETOX = "1"; |
| 40 | + render(<Lottie source={{ uri: "file:///test.lottie" }} testID="splash-lottie" />); |
| 41 | + expect(screen.getByTestId("splash-lottie-detox")).toBeOnTheScreen(); |
| 42 | + expect(screen.queryByTestId("lottie-mock")).toBeNull(); |
| 43 | + Config.DETOX = undefined; |
| 44 | + }); |
| 45 | +}); |
0 commit comments