Skip to content
Closed
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
8 changes: 8 additions & 0 deletions .changeset/prospects-parallel-reading.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@launchstack/pipelines": patch
---

Keyless runs read five companies at once instead of one after another, through
a new optional `enrichConcurrency` on `DistributionPorts`. Each company's own
site is still read one page at a time. Fixture runs and the worker's durable
job are unchanged.
66 changes: 66 additions & 0 deletions apps/web/__tests__/lib/tools/useResource.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/** @jest-environment jsdom */
import { act, renderHook, waitFor } from "@testing-library/react";

jest.mock("next-intl", () => ({ useTranslations: () => (key: string) => key }));
jest.mock("~/lib/tools/errorText", () => ({
useErrorText: () => (_e: unknown, fallback: string) => fallback,
}));

import { forgetResources, useResource } from "~/lib/tools/useResource";

beforeEach(() => forgetResources());

describe("useResource across a remount", () => {
it("shows what it last loaded at once, and refreshes it in the background", async () => {
let n = 0;
const fetcher = jest.fn(async () => ({ n: ++n }));
const first = renderHook(() =>
useResource("companies:seg-1", fetcher, { keepAcrossMounts: true })
);
expect(first.result.current.loading).toBe(true);
await waitFor(() => expect(first.result.current.data).toEqual({ n: 1 }));
first.unmount();

// A tab switch away and back: the screen mounts again.
const second = renderHook(() =>
useResource("companies:seg-1", fetcher, { keepAcrossMounts: true })
);
expect(second.result.current.loading).toBe(false);
expect(second.result.current.data).toEqual({ n: 1 });
await waitFor(() => expect(second.result.current.data).toEqual({ n: 2 }));
expect(fetcher).toHaveBeenCalledTimes(2);
});

it("starts from a skeleton without the option, as before", async () => {
const fetcher = jest.fn(async () => "x");
const first = renderHook(() => useResource("deals:seg-1", fetcher));
await waitFor(() => expect(first.result.current.data).toBe("x"));
first.unmount();
const second = renderHook(() => useResource("deals:seg-1", fetcher));
expect(second.result.current.loading).toBe(true);
expect(second.result.current.data).toBeNull();
});

it("keeps an optimistic change for the next mount, and keys stay apart", async () => {
const fetcher = jest.fn(async () => ({ stage: "lead" }));
const first = renderHook(() =>
useResource("company:a", fetcher, { keepAcrossMounts: true })
);
await waitFor(() => expect(first.result.current.data).toEqual({ stage: "lead" }));
act(() => first.result.current.mutate(() => ({ stage: "won" })));
first.unmount();
const again = renderHook(() =>
useResource("company:a", () => new Promise(() => undefined), {
keepAcrossMounts: true,
})
);
expect(again.result.current.data).toEqual({ stage: "won" });
const other = renderHook(() =>
useResource("company:b", () => new Promise(() => undefined), {
keepAcrossMounts: true,
})
);
expect(other.result.current.data).toBeNull();
expect(other.result.current.loading).toBe(true);
});
});
101 changes: 101 additions & 0 deletions apps/web/__tests__/prospects/company-card.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/** @jest-environment jsdom */
import { fireEvent, render, screen } from "@testing-library/react";

jest.mock("next-intl", () => ({ useTranslations: () => (key: string) => key }));
jest.mock("~/components/tool-app/ToolLink", () => ({
ToolLink: ({ children, href }: { children: React.ReactNode; href: string }) => (
<a href={href}>{children}</a>
),
}));
jest.mock("~/lib/tools/copyText", () => ({
useCopyText: () => (_copy: unknown, text: string) => text,
}));
jest.mock("~/app/employer/tools/growth/prospects/_components/SourceChip", () => ({
FoundViaChips: () => null,
}));
jest.mock("~/app/employer/tools/growth/prospects/_components/StagePill", () => ({
StagePill: ({ stage }: { stage: string }) => <span>{stage}</span>,
}));
jest.mock("~/components/tools/FitMeter", () => ({
FitMeter: ({ value }: { value: number | null }) => <span>fit {value}</span>,
}));

import {
CompanyCard,
CompanyPicture,
} from "~/app/employer/tools/growth/prospects/_components/CompanyCard";
import type { CompanyRow } from "~/app/employer/tools/growth/prospects/api";

const row = (over: Partial<CompanyRow> = {}): CompanyRow => ({
id: "c1",
name: "Charm City Roasters",
domain: "charmcity.example",
hq: "Baltimore, US",
country: "US",
sizeBand: null,
archetype: "retailer",
why: "A Baltimore café that sells whole beans.",
imageUrl: "https://charmcity.example/og.jpg",
iconUrl: "https://charmcity.example/icon.png",
fit: 82,
fitThreshold: 70,
stage: "lead",
staleDays: null,
people: 3,
lastActivityAt: null,
foundVia: [],
isNew: true,
excluded: false,
excludedReason: null,
...over,
});

describe("CompanyPicture", () => {
it("falls back from the share image to the icon to the initials, never a broken image", () => {
const { container } = render(<CompanyPicture c={row()} />);
const image = container.querySelector("img")!;
expect(image.getAttribute("src")).toBe("https://charmcity.example/og.jpg");
expect(image.getAttribute("referrerpolicy")).toBe("no-referrer");
fireEvent.error(image);
const icon = container.querySelector("img")!;
expect(icon.getAttribute("src")).toBe("https://charmcity.example/icon.png");
fireEvent.error(icon);
expect(container.querySelector("img")).toBeNull();
expect(screen.getByText("CC")).toBeTruthy();
});

it("shows initials when the company has no pictures yet", () => {
const { container } = render(
<CompanyPicture c={row({ imageUrl: null, iconUrl: null, name: "Zeke's" })} />
);
expect(container.querySelector("img")).toBeNull();
expect(screen.getByText("Z")).toBeTruthy();
});
});

describe("CompanyCard", () => {
it("shows who, where, why, fit, stage and people, and opens on click", () => {
const onOpen = jest.fn();
render(
<CompanyCard
c={row()}
index={0}
focused={false}
checked={false}
onToggle={jest.fn()}
onOpen={onOpen}
href="/companies/c1"
/>
);
expect(screen.getByText("Charm City Roasters").closest("a")!.getAttribute("href")).toBe(
"/companies/c1"
);
expect(screen.getByText("Baltimore, US · charmcity.example")).toBeTruthy();
expect(screen.getByText("A Baltimore café that sells whole beans.")).toBeTruthy();
expect(screen.getByText("fit 82")).toBeTruthy();
expect(screen.getByText("lead")).toBeTruthy();
expect(screen.getByText("companies.newBadge")).toBeTruthy();
fireEvent.click(screen.getByText("A Baltimore café that sells whole beans."));
expect(onOpen).toHaveBeenCalled();
});
});
Loading
Loading