|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import withAndroidInputBackground from "./withAndroidInputBackground.cjs"; |
| 3 | + |
| 4 | +async function transform(resources) { |
| 5 | + const config = withAndroidInputBackground({ name: "Test", slug: "test" }); |
| 6 | + const result = await config.mods.android.styles({ |
| 7 | + ...config, |
| 8 | + modRequest: { platform: "android", modName: "styles", introspect: false }, |
| 9 | + modResults: { resources: structuredClone(resources) }, |
| 10 | + }); |
| 11 | + return result.modResults.resources; |
| 12 | +} |
| 13 | + |
| 14 | +describe("Android input background generation", () => { |
| 15 | + it("removes framework and AppCompat underlines while preserving other theme settings", async () => { |
| 16 | + const color = { $: { name: "colorPrimary" }, _: "@color/colorPrimary" }; |
| 17 | + const dialog = { $: { name: "AppAlertDialog" }, item: [color] }; |
| 18 | + const result = await transform({ |
| 19 | + style: [ |
| 20 | + { |
| 21 | + $: { name: "AppTheme", parent: "Theme.AppCompat.DayNight.NoActionBar" }, |
| 22 | + item: [ |
| 23 | + color, |
| 24 | + { $: { name: "android:editTextBackground" }, _: "@drawable/rn_edit_text_material" }, |
| 25 | + ], |
| 26 | + }, |
| 27 | + dialog, |
| 28 | + ], |
| 29 | + }); |
| 30 | + |
| 31 | + expect(result.style[0]).toEqual({ |
| 32 | + $: { name: "AppTheme", parent: "Theme.AppCompat.DayNight.NoActionBar" }, |
| 33 | + item: [ |
| 34 | + color, |
| 35 | + { $: { name: "android:editTextBackground" }, _: "@null" }, |
| 36 | + { $: { name: "editTextBackground" }, _: "@null" }, |
| 37 | + ], |
| 38 | + }); |
| 39 | + expect(result.style[1]).toEqual(dialog); |
| 40 | + expect(await transform(result)).toEqual(result); |
| 41 | + }); |
| 42 | + |
| 43 | + it("handles a theme with no existing items", async () => { |
| 44 | + const result = await transform({ style: [{ $: { name: "AppTheme" } }] }); |
| 45 | + expect(result.style[0].item).toEqual([ |
| 46 | + { $: { name: "editTextBackground" }, _: "@null" }, |
| 47 | + { $: { name: "android:editTextBackground" }, _: "@null" }, |
| 48 | + ]); |
| 49 | + }); |
| 50 | + |
| 51 | + it("fails visibly if the Android theme template changes", async () => { |
| 52 | + await expect(transform({})).rejects.toThrow("AppTheme is missing"); |
| 53 | + }); |
| 54 | +}); |
0 commit comments