Skip to content

Commit 6e4559c

Browse files
kzurawclaude
andcommitted
Add unit tests for getCreator method and fix static asset import
- Add comprehensive test coverage for getCreator method with 8 test cases covering app creators (with/without logos), user creators (with/without avatars), and edge cases (null values, empty names) - Fix static asset import in OrderRefunds.stories.tsx to use default import instead of wildcard import, following Vite best practices and Copilot recommendation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fd803fa commit 6e4559c

2 files changed

Lines changed: 173 additions & 2 deletions

File tree

src/ordersV2/OrderRefunds/OrderRefundsViewModel.test.ts

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,177 @@ Array [
470470
});
471471
});
472472

473+
describe("getCreator", () => {
474+
it("should return app creator with initials and logo", () => {
475+
// Arrange
476+
const appCreator = {
477+
__typename: "App" as const,
478+
id: "app-1",
479+
name: "Payment App",
480+
brand: {
481+
__typename: "AppBrand" as const,
482+
logo: {
483+
__typename: "AppBrandLogo" as const,
484+
default: "https://example.com/app-logo.webp",
485+
},
486+
},
487+
};
488+
489+
// Act
490+
const result = OrderRefundsViewModel["getCreator"](appCreator);
491+
492+
// Assert
493+
expect(result).toStrictEqual({
494+
initials: "PA",
495+
logoUrl: "https://example.com/app-logo.webp",
496+
});
497+
});
498+
499+
it("should return app creator with initials when logo is missing", () => {
500+
// Arrange
501+
const appCreator = {
502+
__typename: "App" as const,
503+
id: "app-2",
504+
name: "Another App",
505+
brand: null,
506+
};
507+
508+
// Act
509+
const result = OrderRefundsViewModel["getCreator"](appCreator);
510+
511+
// Assert
512+
expect(result).toStrictEqual({
513+
initials: "AN",
514+
logoUrl: null,
515+
});
516+
});
517+
518+
it("should return app creator with empty initials when name is null", () => {
519+
// Arrange
520+
const appCreator = {
521+
__typename: "App" as const,
522+
id: "app-3",
523+
name: null,
524+
brand: null,
525+
};
526+
527+
// Act
528+
const result = OrderRefundsViewModel["getCreator"](appCreator);
529+
530+
// Assert
531+
expect(result).toStrictEqual({
532+
initials: "",
533+
logoUrl: null,
534+
});
535+
});
536+
537+
it("should return app creator with initials and handle nested null logo", () => {
538+
// Arrange
539+
const appCreator = {
540+
__typename: "App" as const,
541+
id: "app-4",
542+
name: "Test App",
543+
brand: {
544+
__typename: "AppBrand" as const,
545+
logo: {
546+
__typename: "AppBrandLogo" as const,
547+
default: null as any,
548+
},
549+
},
550+
};
551+
552+
// Act
553+
const result = OrderRefundsViewModel["getCreator"](appCreator);
554+
555+
// Assert
556+
expect(result).toStrictEqual({
557+
initials: "TE",
558+
logoUrl: null,
559+
});
560+
});
561+
562+
it("should return user creator with initials and avatar", () => {
563+
// Arrange
564+
const userCreator = {
565+
__typename: "User" as const,
566+
id: "user-1",
567+
email: "john.doe@example.com",
568+
firstName: "John",
569+
lastName: "Doe",
570+
isActive: true,
571+
avatar: {
572+
__typename: "Image" as const,
573+
url: "https://example.com/user-avatar.jpg",
574+
},
575+
};
576+
577+
// Act
578+
const result = OrderRefundsViewModel["getCreator"](userCreator);
579+
580+
// Assert
581+
expect(result).toStrictEqual({
582+
initials: "JD",
583+
logoUrl: "https://example.com/user-avatar.jpg",
584+
});
585+
});
586+
587+
it("should return user creator with initials when avatar is missing", () => {
588+
// Arrange
589+
const userCreator = {
590+
__typename: "User" as const,
591+
id: "user-2",
592+
email: "jane.smith@example.com",
593+
firstName: "Jane",
594+
lastName: "Smith",
595+
isActive: true,
596+
avatar: null,
597+
};
598+
599+
// Act
600+
const result = OrderRefundsViewModel["getCreator"](userCreator);
601+
602+
// Assert
603+
expect(result).toStrictEqual({
604+
initials: "JS",
605+
logoUrl: null,
606+
});
607+
});
608+
609+
it("should handle user with empty name by using email for initials", () => {
610+
// Arrange
611+
const userCreator = {
612+
__typename: "User" as const,
613+
id: "user-3",
614+
email: "user@example.com",
615+
firstName: "",
616+
lastName: "",
617+
isActive: true,
618+
avatar: null,
619+
};
620+
621+
// Act
622+
const result = OrderRefundsViewModel["getCreator"](userCreator);
623+
624+
// Assert
625+
// getUserInitials falls back to email when name is empty, generating "US" from "user@example.com"
626+
expect(result).toStrictEqual({
627+
initials: "US",
628+
logoUrl: null,
629+
});
630+
});
631+
632+
it("should handle null creator", () => {
633+
// Arrange
634+
const creator = null;
635+
636+
// Act
637+
const result = OrderRefundsViewModel["getCreator"](creator);
638+
639+
// Assert
640+
expect(result).toBeNull();
641+
});
642+
});
643+
473644
describe("groupEventsByPspReference", () => {
474645
it.each([
475646
[

src/ordersV2/storybook/OrderRefunds.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { OrderGrantedRefundStatusEnum } from "@dashboard/graphql";
22
import type { Meta, StoryObj } from "@storybook/react-vite";
33

44
import { OrderRefunds } from "../OrderRefunds/OrderRefunds";
5-
import * as testLogo from "./testLogo.webp";
5+
import testLogo from "./testLogo.webp";
66

77
const meta = {
88
title: "Order Detail Page / Content / Refunds",
@@ -69,7 +69,7 @@ export const Failure: Story = {
6969
},
7070
creator: {
7171
initials: "AD",
72-
logoUrl: testLogo.default,
72+
logoUrl: testLogo,
7373
},
7474
},
7575
],

0 commit comments

Comments
 (0)