@@ -6,27 +6,7 @@ import userEvent from "@testing-library/user-event";
66import { describe , it , expect } from "vitest" ;
77import { JsonDocRenderer } from "../src/renderer/JsonDocRenderer" ;
88import { mockBlocks , mockPageWithAllBlocks } from "./fixtures/test-blocks" ;
9-
10- // Helper to create a page with specific blocks
11- const createPageWithBlocks = ( blocks : any [ ] ) => ( {
12- object : "page" ,
13- id : "test-page" ,
14- properties : {
15- title : {
16- type : "title" ,
17- title : [
18- {
19- href : null ,
20- type : "text" ,
21- text : { link : null , content : "Test Page" } ,
22- annotations : { } ,
23- plain_text : "Test Page" ,
24- } ,
25- ] ,
26- } ,
27- } ,
28- children : blocks ,
29- } ) ;
9+ import { createPageWithBlocks } from "./utils/helpers" ;
3010
3111describe ( "JsonDocRenderer - All Block Types" , ( ) => {
3212 it ( "renders page title correctly" , ( ) => {
@@ -208,9 +188,6 @@ describe("JsonDocRenderer - All Block Types", () => {
208188 const page = createPageWithBlocks ( [ mockBlocks . paragraph ] ) ;
209189 const { container } = render ( < JsonDocRenderer page = { page } /> ) ;
210190
211- // Debug: Print the HTML structure
212- // screen.debug();
213-
214191 // Test bold annotation
215192 const boldText = screen . getByText ( "bold text" ) ;
216193 expect ( boldText ) . toBeInTheDocument ( ) ;
@@ -246,4 +223,56 @@ describe("JsonDocRenderer - All Block Types", () => {
246223 expect ( screen . getByText ( "Header 1" ) ) . toBeInTheDocument ( ) ;
247224 expect ( screen . getByText ( "Content in first column" ) ) . toBeInTheDocument ( ) ;
248225 } ) ;
226+
227+ it ( "incorrect block page number shouldn't break the rendering" , ( ) => {
228+ // Test misordered page numbers (3, 1, 2)
229+ const blocksWithMisorderedPages = [
230+ {
231+ ...mockBlocks . paragraph ,
232+ metadata : {
233+ origin : {
234+ file_id : "test-file" ,
235+ page_num : 3 ,
236+ } ,
237+ } ,
238+ } ,
239+ {
240+ ...mockBlocks . heading_1 ,
241+ metadata : {
242+ origin : {
243+ file_id : "test-file" ,
244+ page_num : 1 ,
245+ } ,
246+ } ,
247+ } ,
248+ {
249+ ...mockBlocks . heading_2 ,
250+ metadata : {
251+ origin : {
252+ file_id : "test-file" ,
253+ page_num : 2 ,
254+ } ,
255+ } ,
256+ } ,
257+ ] ;
258+
259+ const pageWithMisorderedBlocks = createPageWithBlocks (
260+ blocksWithMisorderedPages
261+ ) ;
262+
263+ // This should not throw an error or break rendering
264+ expect ( ( ) => {
265+ render ( < JsonDocRenderer page = { pageWithMisorderedBlocks } /> ) ;
266+ } ) . not . toThrow ( ) ;
267+
268+ // Verify that content still renders despite misordered page numbers
269+ expect ( screen . getByText ( / T h i s i s a p a r a g r a p h w i t h / ) ) . toBeInTheDocument ( ) ;
270+ expect ( screen . getByText ( / M a i n H e a d i n g / ) ) . toBeInTheDocument ( ) ;
271+ expect ( screen . getByText ( / S u b h e a d i n g / ) ) . toBeInTheDocument ( ) ;
272+
273+ // Verify page delimiters are rendered in the order they appear
274+ expect ( screen . getByText ( / P a g e 3 / ) ) . toBeInTheDocument ( ) ;
275+ expect ( screen . getByText ( / P a g e 1 / ) ) . toBeInTheDocument ( ) ;
276+ expect ( screen . getByText ( / P a g e 2 / ) ) . toBeInTheDocument ( ) ;
277+ } ) ;
249278} ) ;
0 commit comments