88
99import { describe , it , expect } from 'vitest' ;
1010import React from 'react' ;
11- import { render , screen } from '@testing-library/react' ;
11+ import { render } from '@testing-library/react' ;
1212import { Ast } from './ReactAstDebugRenderer' ;
1313import type { PandocAST } from './ReactAstDebugRenderer' ;
1414import { NodeAttributionContext } from './ReactAstDebugRenderer' ;
@@ -30,8 +30,8 @@ function makeAstJson(opts?: { sourceInfoId?: number }): string {
3030}
3131
3232describe ( 'Node rendering with attribution' , ( ) => {
33- it ( 'renders with attribution color and title tooltip when context is provided ' , ( ) => {
34- const mockGetNodeAttribution = ( sourceInfoId : number ) : NodeAttribution | null => ( {
33+ it ( 'renders colored badge with author name on attributed nodes ' , ( ) => {
34+ const mockGetNodeAttribution = ( _sourceInfoId : number ) : NodeAttribution | null => ( {
3535 actor : 'actor1' ,
3636 time : 1700000000000 ,
3737 color : '#E91E63' ,
@@ -42,44 +42,48 @@ describe('Node rendering with attribution', () => {
4242
4343 const { container } = render (
4444 < NodeAttributionContext . Provider value = { { getNodeAttribution : mockGetNodeAttribution } } >
45- < Ast
46- astJson = { astJson }
47- setAst = { ( ) => { } }
48- />
45+ < Ast astJson = { astJson } setAst = { ( ) => { } } />
4946 </ NodeAttributionContext . Provider >
5047 ) ;
5148
52- // Find the Str node's span — it should have the attribution color
53- const strSpan = container . querySelector ( '[title]' ) ;
54- expect ( strSpan ) . not . toBeNull ( ) ;
55- expect ( strSpan ! . getAttribute ( 'title' ) ) . toContain ( 'Alice' ) ;
56- expect ( ( strSpan as HTMLElement ) . style . color ) . toBe ( 'rgb(233, 30, 99)' ) ; // #E91E63
49+ // Badge element should exist with author name
50+ const badge = container . querySelector ( '.q2-attr-badge' ) ;
51+ expect ( badge ) . not . toBeNull ( ) ;
52+ expect ( badge ! . textContent ) . toContain ( 'Alice' ) ;
53+
54+ // Wrapper should have the attribution color
55+ const wrapper = container . querySelector ( '.q2-attr-wrap' ) ;
56+ expect ( wrapper ) . not . toBeNull ( ) ;
57+ expect ( ( wrapper as HTMLElement ) . style . color ) . toBe ( 'rgb(233, 30, 99)' ) ; // #E91E63
5758 } ) ;
5859
59- it ( 'renders identically to current behavior when attribution context is null' , ( ) => {
60+ it ( 'renders without badge when attribution context is null' , ( ) => {
6061 const astJson = makeAstJson ( { sourceInfoId : 42 } ) ;
6162
62- const { container : withoutCtx } = render (
63+ const { container } = render (
6364 < Ast astJson = { astJson } setAst = { ( ) => { } } />
6465 ) ;
6566
66- // Should render without any attribution styling — no title attribute on Str
67- const strSpans = withoutCtx . querySelectorAll ( 'span' ) ;
68- const strSpan = Array . from ( strSpans ) . find ( s => s . textContent ?. includes ( 'hello' ) ) ;
67+ // No badge or attribution wrapper
68+ expect ( container . querySelector ( '.q2-attr-badge' ) ) . toBeNull ( ) ;
69+ expect ( container . querySelector ( '.q2-attr-wrap' ) ) . toBeNull ( ) ;
70+
71+ // Str still renders
72+ const strSpan = Array . from ( container . querySelectorAll ( 'span' ) ) . find (
73+ s => s . textContent ?. includes ( 'hello' ) ,
74+ ) ;
6975 expect ( strSpan ) . toBeTruthy ( ) ;
70- // No title attribute when no attribution context
71- expect ( strSpan ! . hasAttribute ( 'title' ) ) . toBe ( false ) ;
7276 } ) ;
7377
74- it ( 'renders without attribution styling when node has no s field' , ( ) => {
78+ it ( 'renders without badge when node has no s field' , ( ) => {
7579 const mockGetNodeAttribution = ( _id : number ) : NodeAttribution | null => ( {
7680 actor : 'actor1' ,
7781 time : 1700000000000 ,
7882 color : '#E91E63' ,
7983 name : 'Alice' ,
8084 } ) ;
8185
82- // No sourceInfoId set on the Str node
86+ // No sourceInfoId on the Str node
8387 const astJson = makeAstJson ( ) ;
8488
8589 const { container } = render (
@@ -88,10 +92,7 @@ describe('Node rendering with attribution', () => {
8892 </ NodeAttributionContext . Provider >
8993 ) ;
9094
91- // Str span should render but without attribution (no title)
92- const strSpans = container . querySelectorAll ( 'span' ) ;
93- const strSpan = Array . from ( strSpans ) . find ( s => s . textContent ?. includes ( 'hello' ) ) ;
94- expect ( strSpan ) . toBeTruthy ( ) ;
95- expect ( strSpan ! . hasAttribute ( 'title' ) ) . toBe ( false ) ;
95+ // No badge since node has no source info
96+ expect ( container . querySelector ( '.q2-attr-badge' ) ) . toBeNull ( ) ;
9697 } ) ;
9798} ) ;
0 commit comments