@@ -176,9 +176,11 @@ impl TrieStringInterner {
176176
177177#[ cfg( test) ]
178178mod tests {
179- use super :: { AuthorId , TrieStringInterner , UiAuthor , UiIssue , UiIssuePool } ;
179+ use super :: TrieStringInterner ;
180180 use octocrab:: models:: IssueState ;
181181
182+ use crate :: ui:: testing:: { DummyDataConfig , dummy_ui_data_with} ;
183+
182184 #[ test]
183185 fn trie_interner_reuses_existing_string_ids ( ) {
184186 let mut interner = TrieStringInterner :: default ( ) ;
@@ -198,54 +200,25 @@ mod tests {
198200 assert_eq ! ( interner. resolve( long) , "opened" ) ;
199201 }
200202
201- fn ensure_author ( pool : & mut UiIssuePool ) -> AuthorId {
202- if let Some ( existing) = pool. author_by_github_id . get ( & 1 ) . copied ( ) {
203- return existing;
204- }
205- let login = pool. intern_str ( "octo" ) ;
206- let key = pool. authors . insert ( UiAuthor {
207- github_id : 1 ,
208- login,
209- } ) ;
210- pool. author_by_github_id . insert ( 1 , key) ;
211- key
212- }
213-
214- fn make_issue ( pool : & mut UiIssuePool , number : u64 , title : & str , state : IssueState ) -> UiIssue {
215- let author = ensure_author ( pool) ;
216- let created_at_short = pool. intern_str ( "2024-01-01 00:00" ) ;
217- let created_at_full = pool. intern_str ( "2024-01-01 00:00:00" ) ;
218- let updated_at_short = pool. intern_str ( "2024-01-01 00:00" ) ;
219- UiIssue {
220- number,
221- state,
222- title : pool. intern_str ( title) ,
223- body : Some ( pool. intern_str ( "body" ) ) ,
224- author,
225- created_ts : 0 ,
226- created_at_short,
227- created_at_full,
228- updated_at_short,
229- comments : 0 ,
230- assignees : Vec :: new ( ) ,
231- milestone : None ,
232- is_pull_request : false ,
233- pull_request_url : None ,
234- labels : Vec :: new ( ) ,
235- }
236- }
237-
238203 #[ test]
239204 fn upsert_issue_reuses_existing_id ( ) {
240- let mut pool = UiIssuePool :: default ( ) ;
241- let first = make_issue ( & mut pool, 42 , "open issue" , IssueState :: Open ) ;
242- let first_id = pool. upsert_issue ( first) ;
243- let second = make_issue ( & mut pool, 42 , "closed issue" , IssueState :: Closed ) ;
244- let second_id = pool. upsert_issue ( second) ;
205+ let mut data = dummy_ui_data_with ( DummyDataConfig {
206+ issue_count : 1 ,
207+ author_count : 2 ,
208+ comments_per_issue : 0 ,
209+ timeline_events_per_issue : 0 ,
210+ seed : 7 ,
211+ } ) ;
212+ let first_id = data. issue_ids [ 0 ] ;
213+ let mut second = data. pool . get_issue ( first_id) . clone ( ) ;
214+ second. state = IssueState :: Closed ;
215+ second. title = data. pool . intern_str ( "closed issue" ) ;
216+ let second_id = data. pool . upsert_issue ( second) ;
217+
245218 assert_eq ! ( first_id, second_id) ;
246- let stored = pool. get_issue ( second_id) ;
219+ let stored = data . pool . get_issue ( second_id) ;
247220 assert_eq ! ( stored. state, IssueState :: Closed ) ;
248- assert_eq ! ( pool. resolve_str( stored. title) , "closed issue" ) ;
221+ assert_eq ! ( data . pool. resolve_str( stored. title) , "closed issue" ) ;
249222 }
250223}
251224
@@ -303,6 +276,18 @@ impl UiIssuePool {
303276 self . resolve_str ( author. login )
304277 }
305278
279+ #[ cfg( test) ]
280+ pub ( crate ) fn intern_test_author ( & mut self , github_id : u64 , login : & str ) -> AuthorId {
281+ if let Some ( existing) = self . author_by_github_id . get ( & github_id) . copied ( ) {
282+ return existing;
283+ }
284+
285+ let login = self . intern_str ( login) ;
286+ let key = self . authors . insert ( UiAuthor { github_id, login } ) ;
287+ self . author_by_github_id . insert ( github_id, key) ;
288+ key
289+ }
290+
306291 pub fn insert_issue ( & mut self , issue : UiIssue ) -> IssueId {
307292 self . upsert_issue ( issue)
308293 }
0 commit comments