quirk-ui 0.1.133 → 0.1.134
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.d.ts +9 -6
- package/dist/next/blocks/DocumentListBlock/DocumentListBlock.test.cjs +1 -1
- package/dist/next/blocks/DocumentListBlock/DocumentListBlock.test.mjs +122 -351
- package/dist/next/blocks/DocumentListBlock/index.cjs +1 -1
- package/dist/next/blocks/DocumentListBlock/index.mjs +117 -114
- package/dist/next/blocks/FeaturedDocumentsBlock/FeaturedDocumentsBlock.test.cjs +1 -1
- package/dist/next/blocks/FeaturedDocumentsBlock/FeaturedDocumentsBlock.test.mjs +137 -576
- package/dist/next/blocks/FeaturedDocumentsBlock/index.cjs +1 -1
- package/dist/next/blocks/FeaturedDocumentsBlock/index.mjs +43 -43
- package/dist/next/cards/BlogArticleCard/BlogArticleCard.test.cjs +1 -1
- package/dist/next/cards/BlogArticleCard/BlogArticleCard.test.mjs +107 -369
- package/dist/next/cards/BlogArticleCard/index.cjs +1 -1
- package/dist/next/cards/BlogArticleCard/index.mjs +47 -47
- package/dist/next/cards/BlogArticleCardAdapter.cjs +1 -1
- package/dist/next/cards/BlogArticleCardAdapter.mjs +10 -10
- package/dist/next/cards/BlogArticleCardAdapter.test.cjs +1 -1
- package/dist/next/cards/BlogArticleCardAdapter.test.mjs +21 -21
- package/dist/next.d.ts +5 -5
- package/dist/sanity.d.ts +4 -1
- package/package.json +1 -1
package/dist/main.d.ts
CHANGED
|
@@ -2,8 +2,7 @@ import { AccordionBlockProps } from './next/blocks/AccordionBlock/AccordionBlock
|
|
|
2
2
|
import { AccordionBlockProps as AccordionBlockProps_2 } from './AccordionBlock.types';
|
|
3
3
|
import { AdditionalCategoriesBlockProps } from './next/blocks/AdditionalCategoriesBlock/AdditionalCategoriesBlock.types';
|
|
4
4
|
import { AdditionalCategoriesBlockProps as AdditionalCategoriesBlockProps_2 } from './AdditionalCategoriesBlock.types';
|
|
5
|
-
import { ArticleItem } from './sanity/types/
|
|
6
|
-
import { ArticleItem as ArticleItem_2 } from '../../../sanity/types/article';
|
|
5
|
+
import { ArticleItem } from './sanity/types/document';
|
|
7
6
|
import { CardGridBlockProps } from './next/blocks/CardGridBlock/CardGridBlock.types';
|
|
8
7
|
import { CardGridBlockProps as CardGridBlockProps_2 } from './CardGridBlock.types';
|
|
9
8
|
import { CarouselBlockProps } from './next/blocks/CarouselBlock/CarouselBlock.types';
|
|
@@ -12,6 +11,8 @@ import { ContentBlockProps } from './next/blocks/ContentBlock/ContentBlock.types
|
|
|
12
11
|
import { ContentBlockProps as ContentBlockProps_2 } from './ContentBlock.types';
|
|
13
12
|
import { CSSProperties } from 'react';
|
|
14
13
|
import { default as default_2 } from 'react';
|
|
14
|
+
import { DocumentItem } from './sanity/types/document';
|
|
15
|
+
import { DocumentItem as DocumentItem_2 } from '../../../sanity/types/document';
|
|
15
16
|
import { DocumentListBlockProps } from './next/blocks/DocumentListBlock/DocumentListBlock.types';
|
|
16
17
|
import { DocumentListBlockProps as DocumentListBlockProps_2 } from './DocumentListBlock.types';
|
|
17
18
|
import { FeaturedDocumentsBlockProps } from './next/blocks/FeaturedDocumentsBlock/FeaturedDocumentsBlock.types';
|
|
@@ -234,12 +235,12 @@ declare type BioCardProps = ItemType_3 & {
|
|
|
234
235
|
}) => default_2.ReactElement | null;
|
|
235
236
|
};
|
|
236
237
|
|
|
237
|
-
export declare function BlogArticleCard({
|
|
238
|
+
export declare function BlogArticleCard({ document, className, index, layout, limit, renderImage, renderLink, }: BlogArticleCardProps): JSX.Element;
|
|
238
239
|
|
|
239
240
|
export declare function BlogArticleCardAdapter({ _key, title, description, image, eyebrow, style, renderImage, }: CardProps): JSX.Element;
|
|
240
241
|
|
|
241
242
|
declare type BlogArticleCardProps = {
|
|
242
|
-
|
|
243
|
+
document: DocumentItem_2;
|
|
243
244
|
className?: string;
|
|
244
245
|
index?: number;
|
|
245
246
|
layout?: string;
|
|
@@ -541,7 +542,9 @@ export declare type DividerProps = {
|
|
|
541
542
|
|
|
542
543
|
export declare type DividerVariant = "solid" | "dashed" | "dotted";
|
|
543
544
|
|
|
544
|
-
export
|
|
545
|
+
export { DocumentItem }
|
|
546
|
+
|
|
547
|
+
export declare function DocumentListBlock({ heading, layout, includeFilters, excludeFilters, limit, categoryFilters, documentType, styleOptions, initialDocuments, initialTotalCount, initialIncludeCategories, parentPage, id, renderRichText, renderCard, }: DocumentListBlockProps_2): JSX.Element;
|
|
545
548
|
|
|
546
549
|
export { DocumentListBlockProps }
|
|
547
550
|
|
|
@@ -579,7 +582,7 @@ declare type FABSize = "sm" | "md" | "lg";
|
|
|
579
582
|
|
|
580
583
|
declare type FABVariant = "primary" | "secondary" | "success" | "danger";
|
|
581
584
|
|
|
582
|
-
export declare function FeaturedDocumentsBlock({ heading, selectionMode, layout, limit,
|
|
585
|
+
export declare function FeaturedDocumentsBlock({ heading, selectionMode, layout, limit, documents, manualDocuments, sortBy, callToAction, styleOptions, id, renderRichText, renderLink, renderCard, }: FeaturedDocumentsBlockProps_2): JSX.Element | null;
|
|
583
586
|
|
|
584
587
|
export { FeaturedDocumentsBlockProps }
|
|
585
588
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const o=require("react/jsx-runtime"),l=require("react"),e=require("../../../react.esm-C_9Ma9mj.cjs"),c=require("./index.cjs");e.vi.mock("./styles.module.css",()=>({default:new Proxy({},{get:(s,i)=>i})}));e.vi.mock("../../hooks/useStyleClasses",()=>({useStyleClasses:()=>"style-classes"}));e.vi.mock("../../context/LocaleBridge",()=>({useLocaleBridge:()=>({locale:"en"})}));e.vi.mock("../../../core/components/Button",()=>({Button:({children:t,onClick:s,disabled:i,className:a})=>o.jsx("button",{onClick:s,disabled:i,className:a,children:t})}));e.vi.mock("../../../core/components/Input",()=>({Input:({value:t,onChange:s,placeholder:i})=>o.jsx("input",{"data-testid":"search-input",value:t,onChange:s,placeholder:i})}));e.vi.mock("../../../core/components/Select",()=>({Select:({options:t,onChange:s})=>o.jsx("select",{"data-testid":"sort-select",onChange:s,children:t.map(i=>o.jsx("option",{value:i.value,children:i.label},i.value))})}));e.vi.mock("./CategoryFilters",()=>({CategoryFilters:({categoryFilters:t,toggleFilters:s,onSelectionChange:i})=>o.jsxs("div",{"data-testid":"category-filters",children:[t.map(a=>o.jsxs("label",{children:[o.jsx("input",{type:"checkbox",value:a._id,onChange:()=>i([a._id])}),a.title]},a._id)),o.jsx("button",{onClick:s,children:"Close"})]})}));e.vi.mock("lucide-react",()=>({XIcon:()=>o.jsx("span",{"data-testid":"x-icon"})}));function h(t,s){return Promise.resolve({ok:!0,json:()=>Promise.resolve({articles:t,totalCount:s})})}function d(t){return[{_type:"block",_key:"b1",style:"normal",markDefs:[],children:[{_type:"span",_key:"s1",text:t,marks:[]}]}]}const g=({blocks:t,className:s})=>{var i,a,u;return o.jsx("span",{"data-testid":"rich-text",className:s,children:((u=(a=(i=t[0])==null?void 0:i.children)==null?void 0:a[0])==null?void 0:u.text)??""})};function n(t){return{_id:t,title:`Article ${t}`,slug:{current:`article-${t}`}}}function r(t={}){return{heading:{title:d("All Articles")},layout:"grid",documentType:"blog",initialArticles:[],initialTotalCount:0,styleOptions:{},renderRichText:g,renderCard:s=>o.jsx("div",{"data-testid":"article-card",children:s.title},s._id),...t}}e.beforeEach(()=>{e.vi.stubGlobal("fetch",e.vi.fn(()=>h([],0)))});e.afterEach(()=>{e.vi.unstubAllGlobals(),document.body.style.overflow=""});e.describe("1. Heading area",()=>{e.it("renders the title via renderRichText",()=>{e.render(o.jsx(c.DocumentListBlock,{...r()}));const t=e.screen.getAllByTestId("rich-text");e.globalExpect(t.some(s=>s.textContent==="All Articles")).toBe(!0)}),e.it("renders the eyebrow when provided",()=>{e.render(o.jsx(c.DocumentListBlock,{...r({heading:{title:d("Title"),eyebrow:d("Blog")}})}));const t=e.screen.getAllByTestId("rich-text");e.globalExpect(t.some(s=>s.textContent==="Blog")).toBe(!0)}),e.it("renders the description when provided",()=>{e.render(o.jsx(c.DocumentListBlock,{...r({heading:{title:d("Title"),description:d("Browse our articles")}})}));const t=e.screen.getAllByTestId("rich-text");e.globalExpect(t.some(s=>s.textContent==="Browse our articles")).toBe(!0)})});e.describe("2. Initial articles — renderCard called for each initialArticle",()=>{e.it("renders a card for each initial article",()=>{e.render(o.jsx(c.DocumentListBlock,{...r({initialArticles:[n("a1"),n("a2"),n("a3")],initialTotalCount:3})})),e.globalExpect(e.screen.getAllByTestId("article-card")).toHaveLength(3)}),e.it("renders article titles via renderCard",()=>{e.render(o.jsx(c.DocumentListBlock,{...r({initialArticles:[n("a1")],initialTotalCount:1})})),e.globalExpect(e.screen.getByText("Article a1")).toBeInTheDocument()}),e.it("renders no cards when initialArticles is empty",()=>{e.render(o.jsx(c.DocumentListBlock,{...r()})),e.globalExpect(e.screen.queryAllByTestId("article-card")).toHaveLength(0)})});e.describe("3. Results count — totalCount displayed",()=>{e.it("shows the initial total count",()=>{e.render(o.jsx(c.DocumentListBlock,{...r({initialArticles:[n("a1")],initialTotalCount:42})})),e.globalExpect(e.screen.getByText("42")).toBeInTheDocument()}),e.it("shows 0 when initialTotalCount is 0",()=>{e.render(o.jsx(c.DocumentListBlock,{...r()})),e.globalExpect(e.screen.getByText("0")).toBeInTheDocument()})});e.describe("4. Sort dropdown — rendered with all five sort options",()=>{e.it("renders a sort select",()=>{e.render(o.jsx(c.DocumentListBlock,{...r()})),e.globalExpect(e.screen.getByTestId("sort-select")).toBeInTheDocument()}),e.it("renders all five sort options",()=>{e.render(o.jsx(c.DocumentListBlock,{...r()}));const s=e.screen.getAllByRole("option").map(i=>i.value);e.globalExpect(s).toContain("date-desc"),e.globalExpect(s).toContain("date-asc"),e.globalExpect(s).toContain("title-asc"),e.globalExpect(s).toContain("title-desc"),e.globalExpect(s).toContain("popular-desc")})});e.describe("5. Search input — renders; typing updates value; clear button appears",()=>{e.it("renders the search input",()=>{e.render(o.jsx(c.DocumentListBlock,{...r()})),e.globalExpect(e.screen.getByTestId("search-input")).toBeInTheDocument()}),e.it("shows the clear button when search has a value",async()=>{e.render(o.jsx(c.DocumentListBlock,{...r()})),await l.act(async()=>{e.fireEvent.change(e.screen.getByTestId("search-input"),{target:{value:"react"}})}),e.globalExpect(e.screen.getByTestId("x-icon")).toBeInTheDocument()}),e.it("does not show the clear button when search is empty",()=>{e.render(o.jsx(c.DocumentListBlock,{...r()})),e.globalExpect(e.screen.queryByTestId("x-icon")).toBeNull()})});e.describe("6. Clear search button — clears the search value",()=>{e.it("clears the search input when the clear button is clicked",async()=>{e.render(o.jsx(c.DocumentListBlock,{...r()})),await l.act(async()=>{e.fireEvent.change(e.screen.getByTestId("search-input"),{target:{value:"react"}})}),await l.act(async()=>{e.fireEvent.click(e.screen.getByTestId("x-icon").closest("button"))}),e.globalExpect(e.screen.getByTestId("search-input").value).toBe(""),e.globalExpect(e.screen.queryByTestId("x-icon")).toBeNull()})});e.describe("7. Filter toggle buttons — shown only when categoryFilters provided",()=>{e.it("shows Filters and Reset buttons when categoryFilters are provided",()=>{e.render(o.jsx(c.DocumentListBlock,{...r({categoryFilters:[{_id:"c1",title:"AI",slug:{current:"ai"}}]})})),e.globalExpect(e.screen.getByText("Filters")).toBeInTheDocument(),e.globalExpect(e.screen.getByText("Reset")).toBeInTheDocument()}),e.it("does not show Filters or Reset buttons when categoryFilters is empty",()=>{e.render(o.jsx(c.DocumentListBlock,{...r({categoryFilters:[]})})),e.globalExpect(e.screen.queryByText("Filters")).toBeNull(),e.globalExpect(e.screen.queryByText("Reset")).toBeNull()}),e.it("does not show Filters or Reset buttons when categoryFilters is omitted",()=>{e.render(o.jsx(c.DocumentListBlock,{...r()})),e.globalExpect(e.screen.queryByText("Filters")).toBeNull(),e.globalExpect(e.screen.queryByText("Reset")).toBeNull()})});e.describe("8. Reset button disabled — when no search and no selected categories",()=>{const t={categoryFilters:[{_id:"c1",title:"AI",slug:{current:"ai"}}]};e.it("disables Reset when search is empty and no categories selected",()=>{e.render(o.jsx(c.DocumentListBlock,{...r(t)})),e.globalExpect(e.screen.getByText("Reset").closest("button")).toBeDisabled()}),e.it("enables Reset when a category is selected",async()=>{e.render(o.jsx(c.DocumentListBlock,{...r(t)})),await l.act(async()=>{e.fireEvent.click(e.screen.getByRole("checkbox"))}),e.globalExpect(e.screen.getByText("Reset").closest("button")).not.toBeDisabled()})});e.describe("9. CategoryFilters — rendered when provided; absent otherwise",()=>{e.it("renders CategoryFilters when categoryFilters prop is provided",()=>{e.render(o.jsx(c.DocumentListBlock,{...r({categoryFilters:[{_id:"c1",title:"AI",slug:{current:"ai"}}]})})),e.globalExpect(e.screen.getByTestId("category-filters")).toBeInTheDocument()}),e.it("does not render CategoryFilters when categoryFilters is omitted",()=>{e.render(o.jsx(c.DocumentListBlock,{...r()})),e.globalExpect(e.screen.queryByTestId("category-filters")).toBeNull()})});e.describe("10. Load more button — shown when hasMore; hidden when all loaded",()=>{e.it("shows Load more when there are more articles than the initial set",()=>{e.render(o.jsx(c.DocumentListBlock,{...r({initialArticles:[n("a1")],initialTotalCount:5})})),e.globalExpect(e.screen.getByText("Load more")).toBeInTheDocument()}),e.it("hides Load more when all articles are already loaded",()=>{e.render(o.jsx(c.DocumentListBlock,{...r({initialArticles:[n("a1"),n("a2")],initialTotalCount:2})})),e.globalExpect(e.screen.queryByText("Load more")).toBeNull()}),e.it("hides Load more when initialArticles is empty and totalCount is 0",()=>{e.render(o.jsx(c.DocumentListBlock,{...r()})),e.globalExpect(e.screen.queryByText("Load more")).toBeNull()})});e.describe("11. Load more fetch — calls /api/articles with correct params on click",()=>{e.it("calls fetch when Load more is clicked",async()=>{e.render(o.jsx(c.DocumentListBlock,{...r({initialArticles:[n("a1")],initialTotalCount:10,limit:3})})),await l.act(async()=>{e.fireEvent.click(e.screen.getByText("Load more"))}),e.globalExpect(e.vi.mocked(fetch)).toHaveBeenCalled();const t=e.vi.mocked(fetch).mock.calls[0][0];e.globalExpect(t).toContain("/api/articles"),e.globalExpect(t).toContain("documentType=blog"),e.globalExpect(t).toContain("locale=en"),e.globalExpect(t).toContain("sort=date-desc")}),e.it("appends new articles to the existing list on load more",async()=>{e.vi.mocked(fetch).mockResolvedValueOnce({ok:!0,json:()=>Promise.resolve({articles:[n("a2"),n("a3")],totalCount:10})}),e.render(o.jsx(c.DocumentListBlock,{...r({initialArticles:[n("a1")],initialTotalCount:10})})),await l.act(async()=>{e.fireEvent.click(e.screen.getByText("Load more"))}),await e.waitForWrapper(()=>{e.globalExpect(e.screen.getAllByTestId("article-card")).toHaveLength(3)})})});e.describe("12. Filter/sort fetch — fetches with reset on sort change",()=>{e.it("calls fetch when sort changes",async()=>{e.render(o.jsx(c.DocumentListBlock,{...r()})),await l.act(async()=>{e.fireEvent.change(e.screen.getByTestId("sort-select"),{target:{value:"title-asc"}})}),e.globalExpect(e.vi.mocked(fetch)).toHaveBeenCalled();const t=e.vi.mocked(fetch).mock.calls[0][0];e.globalExpect(t).toContain("sort=title-asc")})});e.describe("13. Search debounce — fetch not triggered until 500ms after last keystroke",()=>{e.beforeEach(()=>{e.vi.useFakeTimers()}),e.afterEach(()=>{e.vi.useRealTimers()}),e.it("does not fetch immediately after typing",async()=>{e.render(o.jsx(c.DocumentListBlock,{...r()})),await l.act(async()=>{e.fireEvent.change(e.screen.getByTestId("search-input"),{target:{value:"react"}})}),l.act(()=>{e.vi.advanceTimersByTime(499)}),e.globalExpect(e.vi.mocked(fetch)).not.toHaveBeenCalled()}),e.it("fetches after 500ms debounce",async()=>{e.render(o.jsx(c.DocumentListBlock,{...r()})),await l.act(async()=>{e.fireEvent.change(e.screen.getByTestId("search-input"),{target:{value:"react"}})}),await l.act(async()=>{e.vi.advanceTimersByTime(500)}),e.vi.useRealTimers(),await e.waitForWrapper(()=>{e.globalExpect(e.vi.mocked(fetch)).toHaveBeenCalled()});const t=e.vi.mocked(fetch).mock.calls[0][0];e.globalExpect(t).toContain("search=react")})});e.describe("14. Layout class — 'list' class applied when layout='list'",()=>{e.it("applies the list class when layout is 'list'",()=>{const{container:t}=e.render(o.jsx(c.DocumentListBlock,{...r({layout:"list"})}));e.globalExpect(t.querySelector(".list")).toBeInTheDocument()}),e.it("does not apply list class when layout is 'grid'",()=>{const{container:t}=e.render(o.jsx(c.DocumentListBlock,{...r({layout:"grid"})})),s=t.querySelector(".list");e.globalExpect(s==null?void 0:s.className.trim()).toBe("list")})});e.describe("15. id prop — forwarded to the <section> element",()=>{e.it("sets the id on the section",()=>{var s;const{container:t}=e.render(o.jsx(c.DocumentListBlock,{...r({id:"blog-list"})}));e.globalExpect((s=t.querySelector("section"))==null?void 0:s.id).toBe("blog-list")}),e.it("renders without an id when prop is omitted",()=>{var s;const{container:t}=e.render(o.jsx(c.DocumentListBlock,{...r()}));e.globalExpect((s=t.querySelector("section"))==null?void 0:s.hasAttribute("id")).toBe(!1)})});e.describe("16. Body scroll lock — overflow hidden when filters open; restored on close",()=>{e.it("locks body scroll when filters are shown",async()=>{e.render(o.jsx(c.DocumentListBlock,{...r({categoryFilters:[{_id:"c1",title:"AI",slug:{current:"ai"}}]})})),await l.act(async()=>{e.fireEvent.click(e.screen.getByText("Filters"))}),e.globalExpect(document.body.style.overflow).toBe("hidden")}),e.it("restores body scroll when filters are closed",async()=>{e.render(o.jsx(c.DocumentListBlock,{...r({categoryFilters:[{_id:"c1",title:"AI",slug:{current:"ai"}}]})})),await l.act(async()=>{e.fireEvent.click(e.screen.getByText("Filters"))}),await l.act(async()=>{e.fireEvent.click(e.screen.getByText("Close"))}),e.globalExpect(document.body.style.overflow).toBe("")})});
|
|
1
|
+
"use strict";const n=require("react/jsx-runtime"),s=require("react"),e=require("../../../react.esm-C_9Ma9mj.cjs"),i=require("./index.cjs");e.vi.mock("./styles.module.css",()=>({default:new Proxy({},{get:(o,c)=>c})}));e.vi.mock("../../hooks/useStyleClasses",()=>({useStyleClasses:()=>"style-classes"}));e.vi.mock("../../context/LocaleBridge",()=>({useLocaleBridge:()=>({locale:"en"})}));e.vi.mock("../../../core/components/Button",()=>({Button:({children:t,onClick:o,disabled:c,className:l})=>n.jsx("button",{onClick:o,disabled:c,className:l,children:t})}));e.vi.mock("../../../core/components/Input",()=>({Input:({value:t,onChange:o,placeholder:c})=>n.jsx("input",{"data-testid":"search-input",value:t,onChange:o,placeholder:c})}));e.vi.mock("../../../core/components/Select",()=>({Select:({options:t,onChange:o})=>n.jsx("select",{"data-testid":"sort-select",onChange:o,children:t.map(c=>n.jsx("option",{value:c.value,children:c.label},c.value))})}));e.vi.mock("./CategoryFilters",()=>({CategoryFilters:()=>n.jsx("div",{"data-testid":"category-filters"})}));e.vi.mock("lucide-react",()=>({XIcon:()=>n.jsx("span",{"data-testid":"x-icon"})}));function m(t){return[{_type:"block",_key:"b1",style:"normal",markDefs:[],children:[{_type:"span",_key:"s1",text:t,marks:[]}]}]}function a(t){return{_id:t,title:`Document ${t}`,slug:{current:`doc-${t}`}}}function r(t={}){return{heading:{title:m("Documents")},layout:"grid",documentType:"article",initialDocuments:[],initialTotalCount:0,styleOptions:{},renderRichText:({blocks:o,className:c})=>{var l,d,u;return n.jsx("span",{"data-testid":"rich-text",className:c,children:((u=(d=(l=o[0])==null?void 0:l.children)==null?void 0:d[0])==null?void 0:u.text)??""})},renderCard:o=>n.jsx("div",{"data-testid":"doc-card",children:o.title},o._id),...t}}e.beforeEach(()=>{e.vi.stubGlobal("fetch",e.vi.fn(()=>Promise.resolve({ok:!0,json:()=>Promise.resolve({documents:[],totalCount:0})})))});e.afterEach(()=>{e.vi.unstubAllGlobals(),document.body.style.overflow=""});e.describe("1. initialDocuments — renderCard called for each; prop renamed",()=>{e.it("renders a card for each initial document",()=>{e.render(n.jsx(i.DocumentListBlock,{...r({initialDocuments:[a("d1"),a("d2")],initialTotalCount:2})})),e.globalExpect(e.screen.getAllByTestId("doc-card")).toHaveLength(2)}),e.it("renders document titles via renderCard",()=>{e.render(n.jsx(i.DocumentListBlock,{...r({initialDocuments:[a("d1")],initialTotalCount:1})})),e.globalExpect(e.screen.getByText("Document d1")).toBeInTheDocument()}),e.it("renders no cards when initialDocuments is empty",()=>{e.render(n.jsx(i.DocumentListBlock,{...r()})),e.globalExpect(e.screen.queryAllByTestId("doc-card")).toHaveLength(0)})});e.describe("2. parentPage — parentRef query param appended when provided",()=>{e.it("appends parentRef to the fetch URL when parentPage._ref is set",async()=>{e.render(n.jsx(i.DocumentListBlock,{...r({initialDocuments:[a("d1")],initialTotalCount:10,parentPage:{_ref:"ref-abc123",_type:"page"}})})),await s.act(async()=>{e.fireEvent.click(e.screen.getByText("Load more"))}),e.globalExpect(e.vi.mocked(fetch)).toHaveBeenCalled();const t=e.vi.mocked(fetch).mock.calls[0][0];e.globalExpect(t).toContain("parentRef=ref-abc123")})});e.describe("3. parentPage absent — parentRef not in fetch URL",()=>{e.it("does not append parentRef when parentPage is undefined",async()=>{e.render(n.jsx(i.DocumentListBlock,{...r({initialDocuments:[a("d1")],initialTotalCount:10,parentPage:void 0})})),await s.act(async()=>{e.fireEvent.click(e.screen.getByText("Load more"))});const t=e.vi.mocked(fetch).mock.calls[0][0];e.globalExpect(t).not.toContain("parentRef")}),e.it("does not append parentRef when parentPage._ref is falsy",async()=>{e.render(n.jsx(i.DocumentListBlock,{...r({initialDocuments:[a("d1")],initialTotalCount:10,parentPage:{_ref:"",_type:"page"}})})),await s.act(async()=>{e.fireEvent.click(e.screen.getByText("Load more"))});const t=e.vi.mocked(fetch).mock.calls[0][0];e.globalExpect(t).not.toContain("parentRef")})});e.describe("4. fetch response — reads data.documents to populate the list",()=>{e.it("renders cards returned in data.documents after load more",async()=>{e.vi.mocked(fetch).mockResolvedValueOnce({ok:!0,json:()=>Promise.resolve({documents:[a("fetched-1"),a("fetched-2")],totalCount:10})}),e.render(n.jsx(i.DocumentListBlock,{...r({initialDocuments:[a("d1")],initialTotalCount:10})})),await s.act(async()=>{e.fireEvent.click(e.screen.getByText("Load more"))}),await e.waitForWrapper(()=>{e.globalExpect(e.screen.getByText("Document fetched-1")).toBeInTheDocument(),e.globalExpect(e.screen.getByText("Document fetched-2")).toBeInTheDocument()})})});e.describe("5. Load more — appends data.documents to existing list",()=>{e.it("keeps the initial documents and appends the fetched ones",async()=>{e.vi.mocked(fetch).mockResolvedValueOnce({ok:!0,json:()=>Promise.resolve({documents:[a("fetched-1")],totalCount:10})}),e.render(n.jsx(i.DocumentListBlock,{...r({initialDocuments:[a("d1")],initialTotalCount:10})})),await s.act(async()=>{e.fireEvent.click(e.screen.getByText("Load more"))}),await e.waitForWrapper(()=>{e.globalExpect(e.screen.getAllByTestId("doc-card")).toHaveLength(2),e.globalExpect(e.screen.getByText("Document d1")).toBeInTheDocument(),e.globalExpect(e.screen.getByText("Document fetched-1")).toBeInTheDocument()})})});
|