@@ -28,7 +28,7 @@ describe('adobe', () => {
2828 const unifont = await createUnifont ( [ providers . adobe ( { id : [ 'bob' ] } ) ] )
2929
3030 const restoreFetch = mockFetchReturn ( / ^ h t t p s : \/ \/ t y p e k i t .c o m \/ a p i \/ / , ( ) => {
31- return { json : ( ) => Promise . resolve ( { kit : '' } ) }
31+ return Promise . resolve ( { json : ( ) => Promise . resolve ( { kit : '' } ) } )
3232 } )
3333 expect ( await unifont . resolveFont ( 'Aleo' ) . then ( r => r . fonts ) ) . toMatchInlineSnapshot ( `[]` )
3434
@@ -38,6 +38,7 @@ describe('adobe', () => {
3838 )
3939
4040 restoreFetch ( )
41+ vi . restoreAllMocks ( )
4142 } )
4243
4344 it ( 'works' , async ( ) => {
@@ -120,4 +121,103 @@ describe('adobe', () => {
120121 } )
121122 expect ( fonts . length ) . toBe ( 4 )
122123 } )
124+
125+ it ( 'refreshes kit metadata when font is not found in cache' , async ( ) => {
126+ let apiCallCount = 0
127+
128+ // Mock the API endpoint to return different kits on subsequent calls
129+ const restoreFetch = mockFetchReturn (
130+ / ^ h t t p s : \/ \/ t y p e k i t .c o m \/ a p i \/ v 1 \/ j s o n \/ k i t s \/ t e s t 1 2 3 \/ p u b l i s h e d / ,
131+ ( ) => {
132+ apiCallCount ++
133+
134+ if ( apiCallCount === 1 ) {
135+ // First API call - return kit without NewFont
136+ return Promise . resolve ( {
137+ json : ( ) => Promise . resolve ( {
138+ kit : {
139+ id : 'test123' ,
140+ families : [
141+ {
142+ id : 'aleo' ,
143+ name : 'Aleo' ,
144+ slug : 'aleo' ,
145+ css_names : [ 'aleo' ] ,
146+ css_stack : 'aleo, serif' ,
147+ variations : [ 'n4' , 'i4' ] ,
148+ } ,
149+ ] ,
150+ } ,
151+ } ) ,
152+ } )
153+ }
154+ else {
155+ // Second API call - return kit with NewFont
156+ return Promise . resolve ( {
157+ json : ( ) => Promise . resolve ( {
158+ kit : {
159+ id : 'test123' ,
160+ families : [
161+ {
162+ id : 'aleo' ,
163+ name : 'Aleo' ,
164+ slug : 'aleo' ,
165+ css_names : [ 'aleo' ] ,
166+ css_stack : 'aleo, serif' ,
167+ variations : [ 'n4' , 'i4' ] ,
168+ } ,
169+ {
170+ id : 'newfont' ,
171+ name : 'NewFont' ,
172+ slug : 'newfont' ,
173+ css_names : [ 'newfont' ] ,
174+ css_stack : 'newfont, sans-serif' ,
175+ variations : [ 'n4' , 'n7' ] ,
176+ } ,
177+ ] ,
178+ } ,
179+ } ) ,
180+ } )
181+ }
182+ } ,
183+ )
184+
185+ // Add a mock for the CSS file that will be fetched
186+ mockFetchReturn (
187+ / ^ h t t p s : \/ \/ u s e \. t y p e k i t \. n e t \/ t e s t 1 2 3 \. c s s / ,
188+ ( ) => {
189+ return Promise . resolve ( {
190+ text : ( ) => Promise . resolve ( `
191+ @font-face {
192+ font-family: "newfont";
193+ src: url("https://use.typekit.net/font.woff2") format("woff2");
194+ font-weight: 400;
195+ font-style: normal;
196+ }
197+ ` ) ,
198+ } )
199+ } ,
200+ )
201+
202+ try {
203+ // Initialize unifont with the initial kit (without NewFont)
204+ const unifont = await createUnifont ( [ providers . adobe ( { id : 'test123' } ) ] )
205+ expect ( apiCallCount ) . toBe ( 1 )
206+
207+ // Verify NewFont is not initially available
208+ const initialFonts = await unifont . listFonts ( )
209+ expect ( initialFonts ) . not . toContain ( 'NewFont' )
210+
211+ // Try to resolve NewFont - this should trigger a refetch
212+ const result = await unifont . resolveFont ( 'NewFont' )
213+
214+ // Ensure the font is now available
215+ expect ( result ) . toBeDefined ( )
216+ expect ( result . fonts ) . toBeDefined ( )
217+ expect ( result . fonts . length ) . toBeGreaterThan ( 0 )
218+ }
219+ finally {
220+ restoreFetch ( )
221+ }
222+ } )
123223} )
0 commit comments