11import { test } from "@fixtures/walletExtension" ;
22import { setAllureEpic } from "@helpers/allure" ;
3+ import { functionWaitedAssert } from "@helpers/waitedLoop" ;
34import BudgetDiscussionPage from "@pages/budgetDiscussionPage" ;
45import { expect } from "@playwright/test" ;
56
67test . beforeEach ( async ( { } ) => {
78 await setAllureEpic ( "11. Proposal Budget" ) ;
89} ) ;
910
10- test ( "11A. Should access budget proposal page in disconnect state" , async ( { page } ) => {
11+ test ( "11A. Should access budget proposal page in disconnect state" , async ( {
12+ page,
13+ } ) => {
1114 const budgetDiscussionPage = new BudgetDiscussionPage ( page ) ;
1215 await budgetDiscussionPage . goto ( ) ;
1316
@@ -17,7 +20,58 @@ test("11A. Should access budget proposal page in disconnect state", async ({ pag
1720} ) ;
1821
1922test . describe ( "Budget proposal list manipulation" , ( ) => {
20- test ( "11B_1. Should search for budget proposals by title" , async ( { } ) => { } ) ;
23+ test ( "11B_1. Should search for budget proposals by title" , async ( {
24+ page,
25+ } ) => {
26+ let proposalName = "EchoFeed" ;
27+ let proposalNameSet = false ;
28+
29+ await page . route ( "**/api/bds?**" , async ( route ) => {
30+ const response = await route . fetch ( ) ;
31+ const json = await response . json ( ) ;
32+ if ( ! proposalNameSet && "data" in json && json [ "data" ] . length > 0 ) {
33+ const randomIndex = Math . floor ( Math . random ( ) * json [ "data" ] . length ) ;
34+ proposalName =
35+ json [ "data" ] [ randomIndex ] [ "attributes" ] [ "bd_proposal_detail" ] [ "data" ] [
36+ "attributes"
37+ ] [ "proposal_name" ] ;
38+ proposalNameSet = true ;
39+ }
40+ await route . fulfill ( {
41+ status : 200 ,
42+ contentType : "application/json" ,
43+ body : JSON . stringify ( json ) ,
44+ } ) ;
45+ } ) ;
46+
47+ const responsePromise = page . waitForResponse ( "**/api/bds?**" ) ;
48+ const budgetDiscussionPage = new BudgetDiscussionPage ( page ) ;
49+ await budgetDiscussionPage . goto ( ) ;
50+
51+ await responsePromise ;
52+
53+ await budgetDiscussionPage . searchInput . fill ( proposalName ) ;
54+
55+ await page . waitForTimeout ( 2000 ) ;
56+
57+ await functionWaitedAssert (
58+ async ( ) => {
59+ const proposalCards = await budgetDiscussionPage . getAllProposals ( ) ;
60+ for ( const proposalCard of proposalCards ) {
61+ await expect ( proposalCard ) . toBeVisible ( ) ;
62+ const proposalTitle = await proposalCard
63+ . getByTestId ( "budget-discussion-title" )
64+ . textContent ( ) ;
65+ expect ( proposalTitle . toLowerCase ( ) ) . toContain (
66+ proposalName . toLowerCase ( )
67+ ) ;
68+ }
69+ } ,
70+ {
71+ message : `A proposal card does not contain the search term ${ proposalName } ` ,
72+ }
73+ ) ;
74+ } ) ;
2175
2276 test ( "11B_2. Should filter budget proposals by categories" , async ( { } ) => { } ) ;
2377
0 commit comments