Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,343 changes: 1,342 additions & 1 deletion package-lock.json

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
"preview": "vite preview",
"type-check": "tsc --noEmit",
"serve": "npm run build && node server.js",
"test": "vitest",
"test:ui": "vitest --ui",
"test:run": "vitest run",
"postversion": "node scripts/update-readme-urls.js"
},
"keywords": [
Expand All @@ -46,11 +49,16 @@
"react": ">=18.0.0"
},
"devDependencies": {
"@testing-library/jest-dom": "^6.8.0",
"@testing-library/react": "^16.3.0",
"@types/node": "^24.3.1",
"@types/react": "^18.2.0",
"@vitejs/plugin-react": "^4.2.0",
"@vitest/ui": "^3.2.4",
"express": "^4.18.0",
"jsdom": "^26.1.0",
"typescript": "^5.0.0",
"vite": "^5.0.0"
"vite": "^5.0.0",
"vitest": "^3.2.4"
}
}
4 changes: 3 additions & 1 deletion src/auth-store/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { create } from "zustand";
import { getOutseta, outsetaLog } from "../outseta";
import { setNestedProperty, debounce } from "./utils";
import { setNestedProperty, getNestedProperty, debounce } from "./utils";

export { getNestedProperty };

// Type for the original Outseta user object (nested structure)
export type OutsetaUser = any;
Expand Down
File renamed without changes.
19 changes: 19 additions & 0 deletions src/framer/overrides.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export {
toggleUserProperty,
showForUserProperty,
hideForUserPayloadProperty,
withUserProperty,
withUserImageProperty,
} from "./overrides/user-properties";

export {
withPayloadProperty,
showForPayloadProperty,
hideForPayloadProperty,
} from "./overrides/payload-properties";

export {
showForAuthStatus,
triggerPopup,
triggerAction,
} from "./overrides/auth";
304 changes: 304 additions & 0 deletions src/framer/overrides/auth.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,304 @@
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { render } from "@testing-library/react";
import React from "react";
import { showForAuthStatus, triggerPopup, triggerAction } from "./auth";
import { authStore } from "../../auth-store";

// Mock the auth store
vi.mock("../../auth-store", () => ({
authStore: vi.fn(),
}));

// Mock the utils log function
vi.mock("./utils", () => ({
log: vi.fn(),
}));

describe("auth.tsx", () => {
let mockAuthStore: any;
let TestComponent: React.ComponentType<any>;

beforeEach(() => {
// Create a mock component for testing
TestComponent = React.forwardRef<HTMLDivElement, any>((props, ref) => (
<div ref={ref} data-testid="test-component" {...props}>
Test Component
</div>
));

// Reset mocks
vi.clearAllMocks();

// Mock window.location for Framer canvas detection
Object.defineProperty(window, "location", {
value: {
host: "localhost:3000",
href: "http://localhost:3000",
},
writable: true,
});

// Setup mock auth store
mockAuthStore = vi.fn();
vi.mocked(authStore).mockImplementation(mockAuthStore);
});

afterEach(() => {
vi.restoreAllMocks();
});

describe("authenticated", () => {
beforeEach(() => {
mockAuthStore.mockImplementation((selector: any) => {
const state = {
status: "authenticated",
payload: { sub: 1 },
user: { Uid: 1, FullName: "Test User" },
};
return selector(state);
});
});

describe("showForAuthStatus: pending", () => {
it("should NOT render the component", () => {
const WrappedComponent = showForAuthStatus(TestComponent, "pending");
const { queryByTestId } = render(<WrappedComponent />);
expect(queryByTestId("test-component")).not.toBeInTheDocument();
});
});

describe("showForAuthStatus: anonymous", () => {
it("should NOT render the component", () => {
const WrappedComponent = showForAuthStatus(TestComponent, "anonymous");
const { queryByTestId } = render(<WrappedComponent />);
expect(queryByTestId("test-component")).not.toBeInTheDocument();
});

it("should render the component when in Framer canvas", () => {
Object.defineProperty(window, "location", {
value: {
host: "test.framercanvas.com",
href: "https://test.framercanvas.com",
},
writable: true,
});

const WrappedComponent = showForAuthStatus(TestComponent, "anonymous");
const { getByTestId } = render(<WrappedComponent />);
expect(getByTestId("test-component")).toBeInTheDocument();
});
});

describe("showForAuthStatus: authenticated", () => {
it("should render the component", () => {
const WrappedComponent = showForAuthStatus(
TestComponent,
"authenticated"
);
const { getByTestId } = render(<WrappedComponent />);
expect(getByTestId("test-component")).toBeInTheDocument();
});
});

describe("showForAuthStatus: user-loaded", () => {
it("should render the component when user exists", () => {
const WrappedComponent = showForAuthStatus(
TestComponent,
"user-loaded"
);
const { getByTestId } = render(<WrappedComponent />);
expect(getByTestId("test-component")).toBeInTheDocument();
});

it("should NOT render the component when no user", () => {
// Override mock for this specific test
mockAuthStore.mockImplementation((selector: any) => {
const state = {
status: "authenticated",
user: null,
payload: { sub: 1 },
};
return selector(state);
});

const WrappedComponent = showForAuthStatus(
TestComponent,
"user-loaded"
);
const { queryByTestId } = render(<WrappedComponent />);
expect(queryByTestId("test-component")).not.toBeInTheDocument();
});
});

describe("triggerPopup: register", () => {
it("should NOT render the component when not in Framer", () => {
const WrappedComponent = triggerPopup(TestComponent, "register");
const { queryByTestId } = render(<WrappedComponent />);
expect(queryByTestId("test-component")).not.toBeInTheDocument();
});

it("should render the component when in Framer canvas", () => {
Object.defineProperty(window, "location", {
value: {
host: "test.framercanvas.com",
href: "https://test.framercanvas.com",
},
writable: true,
});

const WrappedComponent = triggerPopup(TestComponent, "register");
const { getByTestId } = render(<WrappedComponent />);
const component = getByTestId("test-component");
expect(component).toHaveAttribute("data-mode", "popup");
expect(component).toHaveAttribute("data-o-auth", "1");
expect(component).toHaveAttribute("data-widget-mode", "register");
});
});

describe("triggerPopup: profile", () => {
it("should render the component", () => {
const WrappedComponent = triggerPopup(TestComponent, "profile");
const { getByTestId } = render(<WrappedComponent />);
const component = getByTestId("test-component");
expect(component).toHaveAttribute("data-mode", "popup");
expect(component).toHaveAttribute("data-o-profile", "1");
});
});

describe("triggerAction: logout", () => {
it("should render the component", () => {
const WrappedComponent = triggerAction(TestComponent, "logout");
const { getByTestId } = render(<WrappedComponent />);
const component = getByTestId("test-component");
expect(component).toHaveAttribute("data-o-logout-link", "1");
});
});
});

describe("anonymous", () => {
beforeEach(() => {
mockAuthStore.mockImplementation((selector: any) => {
const state = { status: "anonymous", payload: null, user: null };
return selector(state);
});
});

describe("showForAuthStatus: anonymous", () => {
it("should render the component", () => {
const WrappedComponent = showForAuthStatus(TestComponent, "anonymous");
const { getByTestId } = render(<WrappedComponent />);
expect(getByTestId("test-component")).toBeInTheDocument();
});
});

describe("showForAuthStatus: authenticated", () => {
it("should NOT render the component", () => {
const WrappedComponent = showForAuthStatus(
TestComponent,
"authenticated"
);
const { queryByTestId } = render(<WrappedComponent />);
expect(queryByTestId("test-component")).not.toBeInTheDocument();
});
});

describe("showForAuthStatus: pending", () => {
it("should NOT render the component", () => {
const WrappedComponent = showForAuthStatus(TestComponent, "pending");
const { queryByTestId } = render(<WrappedComponent />);
expect(queryByTestId("test-component")).not.toBeInTheDocument();
});
});

describe("triggerPopup: register", () => {
it("should render the component", () => {
const WrappedComponent = triggerPopup(TestComponent, "register");
const { getByTestId } = render(<WrappedComponent />);
const component = getByTestId("test-component");
expect(component).toHaveAttribute("data-mode", "popup");
expect(component).toHaveAttribute("data-o-auth", "1");
expect(component).toHaveAttribute("data-widget-mode", "register");
});
});

describe("triggerPopup: profile", () => {
it("should NOT render the component", () => {
const WrappedComponent = triggerPopup(TestComponent, "profile");
const { queryByTestId } = render(<WrappedComponent />);
expect(queryByTestId("test-component")).not.toBeInTheDocument();
});
});

describe("triggerAction: logout", () => {
it("should NOT render the component", () => {
const WrappedComponent = triggerAction(TestComponent, "logout");
const { queryByTestId } = render(<WrappedComponent />);
expect(queryByTestId("test-component")).not.toBeInTheDocument();
});
});
});

describe("pending", () => {
beforeEach(() => {
mockAuthStore.mockImplementation((selector: any) => {
const state = { status: "pending", user: null, payload: null };
return selector(state);
});
});

describe("showForAuthStatus: pending", () => {
it("should render the component", () => {
const WrappedComponent = showForAuthStatus(TestComponent, "pending");
const { getByTestId } = render(<WrappedComponent />);
expect(getByTestId("test-component")).toBeInTheDocument();
});
});

describe("showForAuthStatus: anonymous", () => {
it("should render the component when in Framer canvas", () => {
Object.defineProperty(window, "location", {
value: {
host: "test.framercanvas.com",
href: "https://test.framercanvas.com",
},
writable: true,
});

const WrappedComponent = showForAuthStatus(TestComponent, "anonymous");
const { getByTestId } = render(<WrappedComponent />);
expect(getByTestId("test-component")).toBeInTheDocument();
});
});

describe("showForAuthStatus: authenticated", () => {
it("should NOT render the component", () => {
const WrappedComponent = showForAuthStatus(
TestComponent,
"authenticated"
);
const { queryByTestId } = render(<WrappedComponent />);
expect(queryByTestId("test-component")).not.toBeInTheDocument();
});
});
});

describe("Framer canvas detection", () => {
it("should handle window.location access errors gracefully", () => {
Object.defineProperty(window, "location", {
get: () => {
throw new Error("Access denied");
},
configurable: true,
});

mockAuthStore.mockImplementation((selector: any) => {
const state = { status: "anonymous", user: null };
return selector(state);
});

const WrappedComponent = showForAuthStatus(TestComponent, "anonymous");
const { getByTestId } = render(<WrappedComponent />);
expect(getByTestId("test-component")).toBeInTheDocument();
});
});
});
Loading