@@ -17,14 +17,15 @@ export class EntryApiHelper {
1717 } ) ;
1818 }
1919
20- async getEntryAtIndex ( index : number ) : Promise < { id : string ; headword : string } > {
20+ async getEntryAtIndex ( index : number ) : Promise < { entryId : string ; headword : string ; senseCount : number } > {
2121 return this . page . evaluate ( async ( { idx, order} ) => {
2222 const api = window . __PLAYWRIGHT_UTILS__ . demoApi ;
2323 const entries = await api . getEntries ( { offset : idx , count : 1 , order} ) ;
2424 const entry = entries [ 0 ] ;
2525 return {
26- id : entry . id ,
26+ entryId : entry . id ,
2727 headword : entry . citationForm ?. seh ?? entry . lexemeForm ?. seh ?? '' ,
28+ senseCount : entry . senses . length ,
2829 } ;
2930 } , { idx : index , order : DEFAULT_ORDER } ) ;
3031 }
@@ -34,6 +35,11 @@ export class EntryApiHelper {
3435 return headword ;
3536 }
3637
38+ async getEntryIdAtIndex ( index : number ) : Promise < string > {
39+ const { entryId} = await this . getEntryAtIndex ( index ) ;
40+ return entryId ;
41+ }
42+
3743 async getLastEntry ( ) : Promise < { headword : string ; index : number } > {
3844 return this . page . evaluate ( async ( { order} ) => {
3945 const api = window . __PLAYWRIGHT_UTILS__ . demoApi ;
@@ -139,4 +145,58 @@ export class EntryApiHelper {
139145 return { id : entry . id , updatedHeadword : newHeadword } ;
140146 } , { idx : index , pfx : prefix , order : DEFAULT_ORDER } ) ;
141147 }
148+
149+ async getEntryWithEnglishGloss ( ) : Promise < { entryId : string ; headword : string ; originalGloss : string } > {
150+ return this . page . evaluate ( async ( { order} ) => {
151+ const api = window . __PLAYWRIGHT_UTILS__ . demoApi ;
152+ const entries = await api . getEntries ( { offset : 0 , count : 50 , order} ) ;
153+ const entry = entries . find ( e => e . senses . length > 0 && e . senses [ 0 ] . gloss ?. en ) ;
154+ if ( ! entry ) throw new Error ( 'No suitable entry with English gloss found in demo data' ) ;
155+ return {
156+ entryId : entry . id ,
157+ headword : entry . citationForm ?. seh ?? entry . lexemeForm ?. seh ?? '' ,
158+ originalGloss : entry . senses [ 0 ] . gloss ?. en ?? '' ,
159+ } ;
160+ } , { order : DEFAULT_ORDER } ) ;
161+ }
162+
163+ async getEntry ( entryId : string ) : Promise < unknown > {
164+ return this . page . evaluate ( async ( id ) => {
165+ return window . __PLAYWRIGHT_UTILS__ . demoApi . getEntry ( id ) ;
166+ } , entryId ) ;
167+ }
168+
169+ async getEntryGloss ( entryId : string , writingSystem : string ) : Promise < string > {
170+ return this . page . evaluate ( async ( { id, ws} ) => {
171+ const api = window . __PLAYWRIGHT_UTILS__ . demoApi ;
172+ const entry = await api . getEntry ( id ) ;
173+ return entry ?. senses [ 0 ] ?. gloss ?. [ ws ] ?? '' ;
174+ } , { id : entryId , ws : writingSystem } ) ;
175+ }
176+
177+ async getEntryLexeme ( entryId : string ) : Promise < string > {
178+ return this . page . evaluate ( async ( id ) => {
179+ const api = window . __PLAYWRIGHT_UTILS__ . demoApi ;
180+ const entry = await api . getEntry ( id ) ;
181+ return entry ?. lexemeForm ?. seh ?? '' ;
182+ } , entryId ) ;
183+ }
184+
185+ async getEntrySenseCount ( entryId : string ) : Promise < number > {
186+ return this . page . evaluate ( async ( id ) => {
187+ const api = window . __PLAYWRIGHT_UTILS__ . demoApi ;
188+ const entry = await api . getEntry ( id ) ;
189+ return entry ?. senses . length ?? 0 ;
190+ } , entryId ) ;
191+ }
192+
193+ async entryHasGlossValue ( entryId : string , glossValue : string ) : Promise < boolean > {
194+ return this . page . evaluate ( async ( { id, value} ) => {
195+ const api = window . __PLAYWRIGHT_UTILS__ . demoApi ;
196+ const entry = await api . getEntry ( id ) ;
197+ return entry ?. senses . some ( s =>
198+ Object . values ( s . gloss || { } ) . some ( v => v === value )
199+ ) ?? false ;
200+ } , { id : entryId , value : glossValue } ) ;
201+ }
142202}
0 commit comments