@@ -55,4 +55,64 @@ describe("templateWarnings", () => {
5555 test ( "stays silent when no eyebrow is set" , ( ) => {
5656 expect ( templateWarnings ( { template : "list" , blocks : [ ] } ) ) . toEqual ( [ ] ) ;
5757 } ) ;
58+
59+ test ( "warns when a template drops a block type it cannot render" , ( ) => {
60+ const [ warning ] = templateWarnings ( {
61+ template : "memo" ,
62+ blocks : [
63+ { type : "headline" } ,
64+ { type : "callout" , items : [ { } ] } ,
65+ ] ,
66+ } ) ;
67+ expect ( warning ) . toContain ( "memo" ) ;
68+ expect ( warning ) . toContain ( "headline" ) ;
69+ expect ( warning ) . toContain ( "will not appear" ) ;
70+ } ) ;
71+
72+ test ( "names every dropped type once, without repeating duplicates" , ( ) => {
73+ const [ warning ] = templateWarnings ( {
74+ template : "prompt" ,
75+ blocks : [ { type : "headline" } , { type : "headline" } , { type : "text" } ] ,
76+ } ) ;
77+ expect ( warning ) . toContain ( "headline" ) ;
78+ expect ( warning ) . toContain ( "text" ) ;
79+ expect ( ( warning ?? "" ) . match ( / h e a d l i n e / g) ) . toHaveLength ( 1 ) ;
80+ } ) ;
81+
82+ test ( "stays silent when every block is one the template renders" , ( ) => {
83+ expect (
84+ templateWarnings ( {
85+ template : "memo" ,
86+ blocks : [ { type : "callout" , items : [ { } ] } , { type : "text" } ] ,
87+ } ) ,
88+ ) . toEqual ( [ ] ) ;
89+ } ) ;
90+
91+ test ( "stays silent for templates that render every block type" , ( ) => {
92+ expect (
93+ templateWarnings ( {
94+ template : "manifesto" ,
95+ blocks : [ { type : "headline" } , { type : "code" } , { type : "chart" } ] ,
96+ } ) ,
97+ ) . toEqual ( [ ] ) ;
98+ } ) ;
99+
100+ test ( "says nothing about blocks when the template is unknown" , ( ) => {
101+ expect (
102+ templateWarnings ( { template : "no-such-template" , blocks : [ { type : "headline" } ] } ) ,
103+ ) . toEqual ( [ ] ) ;
104+ } ) ;
105+
106+ test ( "every shipped example renders all of its own blocks" , async ( ) => {
107+ const { readdirSync, readFileSync } = await import ( "node:fs" ) ;
108+ const dir = "content/examples" ;
109+ for ( const file of readdirSync ( dir ) . filter ( ( f ) => f . endsWith ( ".json" ) ) ) {
110+ const card = JSON . parse ( readFileSync ( `${ dir } /${ file } ` , "utf-8" ) ) as {
111+ template : string ;
112+ eyebrow ?: string ;
113+ blocks : { type : string } [ ] ;
114+ } ;
115+ expect ( [ file , templateWarnings ( card ) ] ) . toEqual ( [ file , [ ] ] ) ;
116+ }
117+ } ) ;
58118} ) ;
0 commit comments