11import { functionWaitedAssert , waitedLoop } from "@helpers/waitedLoop" ;
22import { expect , Locator , Page } from "@playwright/test" ;
3- import { BudgetProposalType } from "@types" ;
3+ import { BudgetProposalType , ProposedGovAction } from "@types" ;
44import environments from "lib/constants/environments" ;
55
66export default class BudgetDiscussionPage {
@@ -11,6 +11,7 @@ export default class BudgetDiscussionPage {
1111 ) ;
1212 readonly verifyIdentityBtn = this . page . getByTestId ( "verify-identity-button" ) ;
1313 readonly filterBtn = this . page . getByTestId ( "filter-button" ) ;
14+ readonly sortBtn = this . page . getByTestId ( "sort-button" ) ;
1415
1516 // input
1617 readonly searchInput = this . page . getByTestId ( "search-input" ) ;
@@ -117,4 +118,30 @@ export default class BudgetDiscussionPage {
117118
118119 return filters . includes ( govActionType ) ;
119120 }
121+
122+ async sortAndValidate (
123+ option : "asc" | "desc" ,
124+ validationFn : ( p1 : ProposedGovAction , p2 : ProposedGovAction ) => boolean
125+ ) {
126+ const responsePromise = this . page . waitForResponse ( ( response ) =>
127+ response
128+ . url ( )
129+ . includes ( `&sort[createdAt]=${ option } &populate[0]=bd_costing` )
130+ ) ;
131+
132+ await this . sortBtn . click ( ) ;
133+ const response = await responsePromise ;
134+
135+ let proposals : ProposedGovAction [ ] = ( await response . json ( ) ) . data ;
136+
137+ // API validation
138+ for ( let i = 0 ; i <= proposals . length - 2 ; i ++ ) {
139+ console . log (
140+ proposals [ i ] . attributes . createdAt ,
141+ proposals [ i + 1 ] . attributes . createdAt
142+ ) ;
143+ const isValid = validationFn ( proposals [ i ] , proposals [ i + 1 ] ) ;
144+ expect ( isValid ) . toBe ( true ) ;
145+ }
146+ }
120147}
0 commit comments