fix: update ImpersonationBanner tests to match current component API
- Import ImpersonationSession from @groombook/types (component was updated in #78) - Remove stale tests: "shows customer name" and "returns null when inactive" (component no longer renders customer name or checks session.active) - Add isExtended prop to all render calls (component now takes isExtended as prop) - Fix "does not show Extend button when already extended" to pass isExtended={true} instead of session.extended (prop was extracted from session in #78) - Fix clients.test.ts: selectRows typed as Record<string,unknown>[] to allow spread in returning() callbacks (resolves TS2698) Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -26,7 +26,7 @@ const DISABLED_CLIENT = {
|
|||||||
|
|
||||||
// ─── Queue-based mock DB ──────────────────────────────────────────────────────
|
// ─── Queue-based mock DB ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
let selectRows: unknown[] = [];
|
let selectRows: Record<string, unknown>[] = [];
|
||||||
let insertedValues: Record<string, unknown>[] = [];
|
let insertedValues: Record<string, unknown>[] = [];
|
||||||
let updatedValues: Record<string, unknown>[] = [];
|
let updatedValues: Record<string, unknown>[] = [];
|
||||||
let deletedId: string | null = null;
|
let deletedId: string | null = null;
|
||||||
|
|||||||
@@ -1,22 +1,21 @@
|
|||||||
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||||
import { render, screen, fireEvent, act } from "@testing-library/react";
|
import { render, screen, fireEvent, act } from "@testing-library/react";
|
||||||
import { ImpersonationBanner } from "../portal/ImpersonationBanner.js";
|
import { ImpersonationBanner } from "../portal/ImpersonationBanner.js";
|
||||||
import type { ImpersonationSession } from "../portal/mockData.js";
|
import type { ImpersonationSession } from "@groombook/types";
|
||||||
|
|
||||||
function makeSession(overrides: Partial<ImpersonationSession> = {}): ImpersonationSession {
|
function makeSession(overrides: Partial<ImpersonationSession> = {}): ImpersonationSession {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const expires = new Date(now.getTime() + 30 * 60 * 1000); // 30 min from now
|
const expires = new Date(now.getTime() + 30 * 60 * 1000); // 30 min from now
|
||||||
return {
|
return {
|
||||||
active: true,
|
id: "session-uuid-1",
|
||||||
staffName: "Jordan",
|
staffId: "staff-uuid-1",
|
||||||
staffRole: "manager",
|
clientId: "client-uuid-1",
|
||||||
customerName: "Sarah Mitchell",
|
|
||||||
reason: "Customer requested help",
|
reason: "Customer requested help",
|
||||||
|
status: "active",
|
||||||
startedAt: now.toISOString(),
|
startedAt: now.toISOString(),
|
||||||
|
endedAt: null,
|
||||||
expiresAt: expires.toISOString(),
|
expiresAt: expires.toISOString(),
|
||||||
extended: false,
|
createdAt: now.toISOString(),
|
||||||
readOnly: true,
|
|
||||||
auditLog: [],
|
|
||||||
...overrides,
|
...overrides,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -39,6 +38,7 @@ describe("ImpersonationBanner", () => {
|
|||||||
render(
|
render(
|
||||||
<ImpersonationBanner
|
<ImpersonationBanner
|
||||||
session={makeSession()}
|
session={makeSession()}
|
||||||
|
isExtended={false}
|
||||||
onEnd={onEnd}
|
onEnd={onEnd}
|
||||||
onExtend={onExtend}
|
onExtend={onExtend}
|
||||||
onShowAudit={onShowAudit}
|
onShowAudit={onShowAudit}
|
||||||
@@ -47,34 +47,11 @@ describe("ImpersonationBanner", () => {
|
|||||||
expect(screen.getByText(/STAFF VIEW/)).toBeInTheDocument();
|
expect(screen.getByText(/STAFF VIEW/)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("shows the customer name", () => {
|
|
||||||
render(
|
|
||||||
<ImpersonationBanner
|
|
||||||
session={makeSession()}
|
|
||||||
onEnd={onEnd}
|
|
||||||
onExtend={onExtend}
|
|
||||||
onShowAudit={onShowAudit}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
expect(screen.getByText("Sarah Mitchell")).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns null when session is not active", () => {
|
|
||||||
const { container } = render(
|
|
||||||
<ImpersonationBanner
|
|
||||||
session={makeSession({ active: false })}
|
|
||||||
onEnd={onEnd}
|
|
||||||
onExtend={onExtend}
|
|
||||||
onShowAudit={onShowAudit}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
expect(container.firstChild).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("calls onEnd when End Session is clicked", () => {
|
it("calls onEnd when End Session is clicked", () => {
|
||||||
render(
|
render(
|
||||||
<ImpersonationBanner
|
<ImpersonationBanner
|
||||||
session={makeSession()}
|
session={makeSession()}
|
||||||
|
isExtended={false}
|
||||||
onEnd={onEnd}
|
onEnd={onEnd}
|
||||||
onExtend={onExtend}
|
onExtend={onExtend}
|
||||||
onShowAudit={onShowAudit}
|
onShowAudit={onShowAudit}
|
||||||
@@ -88,6 +65,7 @@ describe("ImpersonationBanner", () => {
|
|||||||
render(
|
render(
|
||||||
<ImpersonationBanner
|
<ImpersonationBanner
|
||||||
session={makeSession()}
|
session={makeSession()}
|
||||||
|
isExtended={false}
|
||||||
onEnd={onEnd}
|
onEnd={onEnd}
|
||||||
onExtend={onExtend}
|
onExtend={onExtend}
|
||||||
onShowAudit={onShowAudit}
|
onShowAudit={onShowAudit}
|
||||||
@@ -104,6 +82,7 @@ describe("ImpersonationBanner", () => {
|
|||||||
render(
|
render(
|
||||||
<ImpersonationBanner
|
<ImpersonationBanner
|
||||||
session={session}
|
session={session}
|
||||||
|
isExtended={false}
|
||||||
onEnd={onEnd}
|
onEnd={onEnd}
|
||||||
onExtend={onExtend}
|
onExtend={onExtend}
|
||||||
onShowAudit={onShowAudit}
|
onShowAudit={onShowAudit}
|
||||||
@@ -123,7 +102,8 @@ describe("ImpersonationBanner", () => {
|
|||||||
const expiresAt = new Date(Date.now() + 3 * 60 * 1000).toISOString();
|
const expiresAt = new Date(Date.now() + 3 * 60 * 1000).toISOString();
|
||||||
render(
|
render(
|
||||||
<ImpersonationBanner
|
<ImpersonationBanner
|
||||||
session={makeSession({ expiresAt, extended: false })}
|
session={makeSession({ expiresAt })}
|
||||||
|
isExtended={false}
|
||||||
onEnd={onEnd}
|
onEnd={onEnd}
|
||||||
onExtend={onExtend}
|
onExtend={onExtend}
|
||||||
onShowAudit={onShowAudit}
|
onShowAudit={onShowAudit}
|
||||||
@@ -140,7 +120,8 @@ describe("ImpersonationBanner", () => {
|
|||||||
const expiresAt = new Date(Date.now() + 3 * 60 * 1000).toISOString();
|
const expiresAt = new Date(Date.now() + 3 * 60 * 1000).toISOString();
|
||||||
render(
|
render(
|
||||||
<ImpersonationBanner
|
<ImpersonationBanner
|
||||||
session={makeSession({ expiresAt, extended: true })}
|
session={makeSession({ expiresAt })}
|
||||||
|
isExtended={true}
|
||||||
onEnd={onEnd}
|
onEnd={onEnd}
|
||||||
onExtend={onExtend}
|
onExtend={onExtend}
|
||||||
onShowAudit={onShowAudit}
|
onShowAudit={onShowAudit}
|
||||||
|
|||||||
Reference in New Issue
Block a user