feat(chat): implement external browser prompt logic and update tests
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
getInsufficientCreditsMessageLimitView,
|
||||
shouldStartExternalBrowserPrompt,
|
||||
shouldShowMessageLimitBanner,
|
||||
} from "../chat-screen.helpers";
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
describe("getInsufficientCreditsMessageLimitView", () => {
|
||||
it("asks guests to log in for more free chats", () => {
|
||||
expect(getInsufficientCreditsMessageLimitView("guest")).toEqual({
|
||||
@@ -65,3 +70,73 @@ describe("shouldShowMessageLimitBanner", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("shouldStartExternalBrowserPrompt", () => {
|
||||
it("shows for facebook users inside an in-app browser", () => {
|
||||
vi.stubEnv("NEXT_PUBLIC_APP_ENV", "production");
|
||||
|
||||
expect(
|
||||
shouldStartExternalBrowserPrompt({
|
||||
hasInitialized: true,
|
||||
isLoading: false,
|
||||
loginStatus: "facebook",
|
||||
isInAppBrowser: true,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it.each(["guest", "notLoggedIn", "email", "google"] as const)(
|
||||
"hides for %s users even inside an in-app browser",
|
||||
(loginStatus) => {
|
||||
vi.stubEnv("NEXT_PUBLIC_APP_ENV", "production");
|
||||
|
||||
expect(
|
||||
shouldStartExternalBrowserPrompt({
|
||||
hasInitialized: true,
|
||||
isLoading: false,
|
||||
loginStatus,
|
||||
isInAppBrowser: true,
|
||||
}),
|
||||
).toBe(false);
|
||||
},
|
||||
);
|
||||
|
||||
it("hides for facebook users in normal browsers", () => {
|
||||
vi.stubEnv("NEXT_PUBLIC_APP_ENV", "production");
|
||||
|
||||
expect(
|
||||
shouldStartExternalBrowserPrompt({
|
||||
hasInitialized: true,
|
||||
isLoading: false,
|
||||
loginStatus: "facebook",
|
||||
isInAppBrowser: false,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("shows in development for easier testing", () => {
|
||||
vi.stubEnv("NEXT_PUBLIC_APP_ENV", "development");
|
||||
|
||||
expect(
|
||||
shouldStartExternalBrowserPrompt({
|
||||
hasInitialized: true,
|
||||
isLoading: false,
|
||||
loginStatus: "guest",
|
||||
isInAppBrowser: false,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("waits for auth initialization", () => {
|
||||
vi.stubEnv("NEXT_PUBLIC_APP_ENV", "production");
|
||||
|
||||
expect(
|
||||
shouldStartExternalBrowserPrompt({
|
||||
hasInitialized: false,
|
||||
isLoading: false,
|
||||
loginStatus: "facebook",
|
||||
isInAppBrowser: true,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user