1- import { waitedLoop } from "@helpers/waitedLoop" ;
2- import { expect , Page } from "@playwright/test" ;
1+ import { functionWaitedAssert , waitedLoop } from "@helpers/waitedLoop" ;
2+ import { expect , Locator , Page } from "@playwright/test" ;
3+ import { BudgetProposalType } from "@types" ;
34import environments from "lib/constants/environments" ;
45
56export default class BudgetDiscussionPage {
@@ -9,6 +10,7 @@ export default class BudgetDiscussionPage {
910 "propose-a-budget-discussion-button"
1011 ) ;
1112 readonly verifyIdentityBtn = this . page . getByTestId ( "verify-identity-button" ) ;
13+ readonly filterBtn = this . page . getByTestId ( "filter-button" ) ;
1214
1315 // input
1416 readonly searchInput = this . page . getByTestId ( "search-input" ) ;
@@ -39,4 +41,80 @@ export default class BudgetDiscussionPage {
3941
4042 return proposalCards ;
4143 }
44+
45+ async clickRadioButtonsByNames ( names : string [ ] ) {
46+ for ( const name of names ) {
47+ const budgetProposalValue = Object . values ( BudgetProposalType ) . includes (
48+ name as BudgetProposalType
49+ ) ;
50+ if ( budgetProposalValue ) {
51+ await this . page . getByLabel ( name ) . click ( ) ;
52+ }
53+ }
54+ }
55+
56+ async filterProposalByNames ( names : string [ ] ) {
57+ await this . clickRadioButtonsByNames ( names ) ;
58+ }
59+
60+ async unFilterProposalByNames ( names : string [ ] ) {
61+ await this . clickRadioButtonsByNames ( names ) ;
62+ }
63+
64+ async applyAndValidateFilters (
65+ filters : string [ ] ,
66+ validateFunction : ( proposalCard : any , filters : string [ ] ) => Promise < boolean >
67+ ) {
68+ await this . page . waitForTimeout ( 4_000 ) ; // wait for the proposals to load
69+ // single filter
70+ for ( const filter of filters ) {
71+ await this . filterProposalByNames ( [ filter ] ) ;
72+ await this . validateFilters ( [ filter ] , validateFunction ) ;
73+ await this . unFilterProposalByNames ( [ filter ] ) ;
74+ }
75+
76+ // multiple filter
77+ const multipleFilters = [ ...filters ] ;
78+ while ( multipleFilters . length > 1 ) {
79+ await this . filterProposalByNames ( multipleFilters ) ;
80+ await this . validateFilters ( multipleFilters , validateFunction ) ;
81+ await this . unFilterProposalByNames ( multipleFilters ) ;
82+ multipleFilters . pop ( ) ;
83+ }
84+ }
85+
86+ async validateFilters (
87+ filters : string [ ] ,
88+ validateFunction : ( proposalCard : any , filters : string [ ] ) => Promise < boolean >
89+ ) {
90+ await functionWaitedAssert ( async ( ) => {
91+ const proposalCards = await this . getAllProposals ( ) ;
92+
93+ for ( const proposalCard of proposalCards ) {
94+ if ( await proposalCard . isVisible ( ) ) {
95+ const type = await proposalCard
96+ . getByTestId ( "budget-proposal-type" )
97+ . textContent ( ) ;
98+ const hasFilter = await validateFunction ( proposalCard , filters ) ;
99+
100+ expect (
101+ hasFilter ,
102+ ! hasFilter &&
103+ `A budget proposal type ${ type } does not contain on ${ filters } `
104+ ) . toBe ( true ) ;
105+ }
106+ }
107+ } ) ;
108+ }
109+
110+ async _validateTypeFiltersInProposalCard (
111+ proposalCard : Locator ,
112+ filters : string [ ]
113+ ) : Promise < boolean > {
114+ const govActionType = await proposalCard
115+ . getByTestId ( "budget-proposal-type" )
116+ . textContent ( ) ;
117+
118+ return filters . includes ( govActionType ) ;
119+ }
42120}
0 commit comments