Skip to content

Commit b03e310

Browse files
committed
test(core): Add config tests
1 parent 2f3e9b5 commit b03e310

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

packages/core/src/config.test.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { FirebaseApp } from "firebase/app";
2+
import { Auth } from "firebase/auth";
3+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
4+
import { initializeUI } from "./config";
5+
import { enUs, registerLocale } from "@firebase-ui/translations";
6+
import { autoAnonymousLogin, autoUpgradeAnonymousUsers } from "./behaviors";
7+
8+
describe('initializeUI', () => {
9+
it('should return a valid deep store with default values', () => {
10+
const config = {
11+
app: {} as FirebaseApp,
12+
auth: {} as Auth,
13+
};
14+
15+
const ui = initializeUI(config);
16+
expect(ui).toBeDefined();
17+
expect(ui.get()).toBeDefined();
18+
expect(ui.get().app).toBe(config.app);
19+
expect(ui.get().auth).toBe(config.auth);
20+
expect(ui.get().behaviors).toEqual({});
21+
expect(ui.get().state).toEqual("idle");
22+
expect(ui.get().locale).toEqual(enUs);
23+
});
24+
25+
it('should merge behaviors', () => {
26+
const config = {
27+
app: {} as FirebaseApp,
28+
auth: {} as Auth,
29+
behaviors: [autoUpgradeAnonymousUsers()],
30+
};
31+
32+
const ui = initializeUI(config);
33+
expect(ui).toBeDefined();
34+
expect(ui.get()).toBeDefined();
35+
expect(ui.get().behaviors).toHaveProperty("autoUpgradeAnonymousCredential");
36+
expect(ui.get().behaviors).toHaveProperty("autoUpgradeAnonymousProvider");
37+
});
38+
39+
it('should set state and update state when called', () => {
40+
const config = {
41+
app: {} as FirebaseApp,
42+
auth: {} as Auth,
43+
};
44+
45+
const ui = initializeUI(config);
46+
expect(ui.get().state).toEqual("idle");
47+
ui.get().setState("loading");
48+
expect(ui.get().state).toEqual("loading");
49+
ui.get().setState("idle");
50+
expect(ui.get().state).toEqual("idle");
51+
});
52+
53+
it('should set state and update locale when called', () => {
54+
const testLocale1 = registerLocale('test1', {});
55+
const testLocale2 = registerLocale('test2', {});
56+
57+
const config = {
58+
app: {} as FirebaseApp,
59+
auth: {} as Auth,
60+
};
61+
62+
const ui = initializeUI(config);
63+
expect(ui.get().locale.locale).toEqual('en-US');
64+
ui.get().setLocale(testLocale1);
65+
expect(ui.get().locale.locale).toEqual('test1');
66+
ui.get().setLocale(testLocale2);
67+
expect(ui.get().locale.locale).toEqual('test2');
68+
});
69+
});
70+

0 commit comments

Comments
 (0)