11import environments from "@constants/environments" ;
2+ import { budgetProposalfilterOptionNames } from "@constants/index" ;
23import { faker } from "@faker-js/faker" ;
34import { test } from "@fixtures/walletExtension" ;
45import { setAllureEpic } from "@helpers/allure" ;
@@ -8,7 +9,11 @@ import { functionWaitedAssert } from "@helpers/waitedLoop";
89import BudgetDiscussionDetailsPage from "@pages/budgetDiscussionDetailsPage" ;
910import BudgetDiscussionPage from "@pages/budgetDiscussionPage" ;
1011import { expect } from "@playwright/test" ;
11- import { BudgetDiscussionEnum } from "@types" ;
12+ import {
13+ BudgetDiscussionEnum ,
14+ BudgetProposalFilterTypes ,
15+ ProposedGovAction ,
16+ } from "@types" ;
1217
1318const mockBudgetProposal = require ( "../../lib/_mock/budgetProposal.json" ) ;
1419const mockPoll = require ( "../../lib/_mock/budgetProposalPoll.json" ) ;
@@ -103,15 +108,41 @@ test.describe("Budget proposal list manipulation", () => {
103108 } ) ;
104109
105110 test ( "11B_3. Should sort budget proposals" , async ( ) => {
106- await budgetDiscussionPage . sortAndValidate (
107- "asc" ,
108- ( p1 , p2 ) => p1 . attributes . createdAt <= p2 . attributes . createdAt
109- ) ;
110-
111- await budgetDiscussionPage . sortAndValidate (
112- "desc" ,
113- ( p1 , p2 ) => p1 . attributes . createdAt >= p2 . attributes . createdAt
114- ) ;
111+ const sortOptions = {
112+ Oldest : ( p1 : ProposedGovAction , p2 : ProposedGovAction ) =>
113+ p1 . attributes . createdAt <= p2 . attributes . createdAt ,
114+ Newest : ( p1 : ProposedGovAction , p2 : ProposedGovAction ) =>
115+ p1 . attributes . createdAt >= p2 . attributes . createdAt ,
116+ "Most comments" : ( p1 : ProposedGovAction , p2 : ProposedGovAction ) =>
117+ p1 . attributes . prop_comments_number >=
118+ p2 . attributes . prop_comments_number ,
119+ "Least comments" : ( p1 : ProposedGovAction , p2 : ProposedGovAction ) =>
120+ p1 . attributes . prop_comments_number <=
121+ p2 . attributes . prop_comments_number ,
122+ "Name A-Z" : ( p1 : ProposedGovAction , p2 : ProposedGovAction ) =>
123+ p1 . attributes . bd_proposal_detail . data . attributes . proposal_name . localeCompare (
124+ p2 . attributes . bd_proposal_detail . data . attributes . proposal_name
125+ ) <= 0 ,
126+ "Name Z-A" : ( p1 : ProposedGovAction , p2 : ProposedGovAction ) =>
127+ p1 . attributes . bd_proposal_detail . data . attributes . proposal_name . localeCompare (
128+ p2 . attributes . bd_proposal_detail . data . attributes . proposal_name
129+ ) >= 0 ,
130+ "Proposer A-Z" : ( p1 : ProposedGovAction , p2 : ProposedGovAction ) =>
131+ p1 . attributes . creator . data . attributes . govtool_username . localeCompare (
132+ p2 . attributes . creator . data . attributes . govtool_username
133+ ) <= 0 ,
134+ "Proposer Z-A" : ( p1 : ProposedGovAction , p2 : ProposedGovAction ) =>
135+ p1 . attributes . creator . data . attributes . govtool_username . localeCompare (
136+ p2 . attributes . creator . data . attributes . govtool_username
137+ ) >= 0 ,
138+ } ;
139+
140+ for ( const [ option , validationFn ] of Object . entries ( sortOptions ) ) {
141+ await budgetDiscussionPage . sortAndValidate (
142+ option as BudgetProposalFilterTypes ,
143+ validationFn
144+ ) ;
145+ }
115146 } ) ;
116147 } ) ;
117148} ) ;
0 commit comments