UNPKG

@applicaster/zapp-react-native-utils

Version:

Applicaster Zapp React Native utilities package

72 lines (55 loc) 1.97 kB
import { getAllFields, getConfigurationDiff } from "../utils"; describe("getAllFields", () => { it("should return all field keys from flat configs", () => { const config1 = { fields: [{ key: "foo" }, { key: "bar" }], }; const config2 = { fields: [{ key: "baz" }], }; expect(getAllFields(config1, config2)).toEqual(["foo", "bar", "baz"]); }); it("should handle grouped fields", () => { const config = { fields: [ { group: true, fields: [{ key: "grouped1" }, { key: "grouped2" }], }, { key: "single" }, ], }; expect(getAllFields(config)).toEqual(["grouped1", "grouped2", "single"]); }); it("should filter out fields without a key", () => { const config = { fields: [{ key: "foo" }, { notAKey: "bar" }], }; expect(getAllFields(config)).toEqual(["foo"]); }); it("should return an empty array if no fields are present", () => { expect(getAllFields({})).toEqual([]); }); }); describe("getConfigurationDiff", () => { it("should return keys in defaultConfig not present in config", () => { const defaultConfig = ["foo", "bar", "baz"]; const config = { foo: 1, baz: 2 }; expect(getConfigurationDiff(defaultConfig, config)).toEqual(["bar"]); }); it("should return all keys if config is empty", () => { const defaultConfig = ["foo", "bar"]; const config = {}; expect(getConfigurationDiff(defaultConfig, config)).toEqual(["foo", "bar"]); }); it("should return an empty array if all keys are present", () => { const defaultConfig = ["foo"]; const config = { foo: 1 }; expect(getConfigurationDiff(defaultConfig, config)).toEqual([]); }); it("should return defaultConfig if config has no matching keys", () => { const defaultConfig = ["foo", "bar"]; const config = { baz: 1 }; expect(getConfigurationDiff(defaultConfig, config)).toEqual(["foo", "bar"]); }); });