6639d6e1f7
- WelcomeComponent now lazily selected and cached a tip per instance, preserving it across re-renders. - With the unicode preset, it showed a special nerdfont tip 10% of the time and otherwise used the regular tip rotation. - Added tests that mocked theme preset and Math.random to verify standard and special tip selection behavior.
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { afterEach, beforeAll, describe, expect, it, vi } from "bun:test";
|
|
import { Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
|
|
import { WelcomeComponent } from "@oh-my-pi/pi-coding-agent/modes/components/welcome";
|
|
import { initTheme, theme } from "@oh-my-pi/pi-coding-agent/modes/theme/theme";
|
|
|
|
describe("WelcomeComponent tips", () => {
|
|
beforeAll(async () => {
|
|
await Settings.init({ inMemory: true });
|
|
await initTheme(false);
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("selects standard tip when preset is not unicode", () => {
|
|
vi.spyOn(theme, "getSymbolPreset").mockReturnValue("nerd");
|
|
|
|
const welcome = new WelcomeComponent("1.0.0", "model", "provider");
|
|
expect(welcome.tip).not.toBe("Please use nerdfont 😭.");
|
|
expect(welcome.tip).toBeDefined();
|
|
});
|
|
|
|
it("selects nerdfont tip with 10% probability under unicode preset", () => {
|
|
vi.spyOn(theme, "getSymbolPreset").mockReturnValue("unicode");
|
|
|
|
// 9% chance => selects special tip
|
|
vi.spyOn(Math, "random").mockReturnValue(0.09);
|
|
const welcomeSpecial = new WelcomeComponent("1.0.0", "model", "provider");
|
|
expect(welcomeSpecial.tip).toBe("Please use nerdfont 😭.");
|
|
|
|
// 10% chance => selects regular tip
|
|
vi.spyOn(Math, "random").mockReturnValue(0.1);
|
|
const welcomeRegular = new WelcomeComponent("1.0.0", "model", "provider");
|
|
expect(welcomeRegular.tip).not.toBe("Please use nerdfont 😭.");
|
|
expect(welcomeRegular.tip).toBeDefined();
|
|
});
|
|
});
|