1- import { test , expect } from "../fixtures/AdminFixtures" ;
1+ import { test , expect } from "../fixtures/AdminFixtures" ;
2+ import CoreLocators from "../locator/CoreLocators" ;
23import { LeadPage } from "../pages/leads/LeadPage" ;
34import { generateDescription , generateEmail , generateName , generatePhoneNumber } from "../utils/faker" ;
45
56
6- test . describe ( "lead management" , async ( ) => {
7+ test . describe ( "lead management" , async ( ) => {
78
89 const leadData = {
910 title : generateName ( ) ,
1011 description : generateDescription ( ) ,
1112 email : generateEmail ( ) ,
1213 phone : generatePhoneNumber ( ) ,
1314 } ;
15+
1416
15-
16- test ( "should create a new lead" , async ( { adminPage } ) => {
17- const leadPage = new LeadPage ( adminPage ) ;
1817
19- await leadPage . navigateToLeadList ( ) ;
18+ test ( "should create a new lead" , async ( { adminPage } ) => {
19+ const leadPage = new LeadPage ( adminPage ) ;
2020
21- await leadPage . createLeadButton . click ( ) ;
21+ await leadPage . navigateToLeadList ( ) ;
2222
23- await leadPage . titleInput . fill ( leadData . title ) ;
24- await leadPage . descriptionTextarea . fill ( leadData . description ) ;
25- await leadPage . sourceDropdown . selectOption ( "1" ) ;
26- await leadPage . expectedCloseDate . fill ( "2025-11-10" ) ;
27- await leadPage . typeDropdown . selectOption ( "1" ) ;
28- await leadPage . userDropdown . selectOption ( "1" ) ;
29- await leadPage . leadValueInput . fill ( "1000" ) ;
23+ await leadPage . createLeadButton . click ( ) ;
3024
31- await leadPage . addPersonButton . click ( ) ;
32- await leadPage . personSearchInput . fill ( leadData . title ) ;
33- await leadPage . addAsNewButton . click ( ) ;
34- await leadPage . personEmailInput . fill ( leadData . email ) ;
35- await leadPage . personPhoneInput . fill ( leadData . phone ) ;
25+ await leadPage . titleInput . fill ( leadData . title ) ;
26+ await leadPage . descriptionTextarea . fill ( leadData . description ) ;
27+ await leadPage . sourceDropdown . selectOption ( "1" ) ;
28+ await leadPage . expectedCloseDate . fill ( "2025-11-10" ) ;
29+ await leadPage . typeDropdown . selectOption ( "1" ) ;
30+ await leadPage . userDropdown . selectOption ( "1" ) ;
31+ await leadPage . leadValueInput . fill ( "1000" ) ;
3632
37- await leadPage . addOrganizationButton . click ( ) ;
38- await leadPage . organizationSearchInput . fill ( leadData . title ) ;
39- await leadPage . addAsNewButton . click ( ) ;
33+ await leadPage . addPersonButton . click ( ) ;
34+ await leadPage . personSearchInput . fill ( leadData . title ) ;
35+ await leadPage . addAsNewButton . click ( ) ;
36+ await leadPage . personEmailInput . fill ( leadData . email ) ;
37+ await leadPage . personPhoneInput . fill ( leadData . phone ) ;
4038
41- await leadPage . saveLead ( ) ;
39+ await leadPage . addOrganizationButton . click ( ) ;
40+ await leadPage . organizationSearchInput . fill ( leadData . title ) ;
41+ await leadPage . addAsNewButton . click ( ) ;
42+
43+ await leadPage . saveLead ( ) ;
44+
45+
46+
47+ } ) ;
48+
49+ test ( "should update an existing lead" , async ( { adminPage } ) => {
50+ const leadPage = new LeadPage ( adminPage ) ;
51+ const coreLocators = await new CoreLocators ( adminPage ) ;
52+
53+ // Now update the lead with new data
54+ const updatedLeadData = {
55+ title : generateName ( ) ,
56+ description : generateDescription ( ) ,
57+ email : generateEmail ( ) ,
58+ phone : generatePhoneNumber ( ) ,
59+ } ;
60+
61+ // Fill updated lead data
62+ await leadPage . navigateToLeadList ( ) ;
63+ await leadPage . searchInput . fill ( leadData . title ) ;
64+ await leadPage . page . keyboard . press ( 'Enter' ) ;
65+ await leadPage . titleInput . fill ( updatedLeadData . title ) ;
66+ await leadPage . descriptionTextarea . fill ( updatedLeadData . description ) ;
67+ await leadPage . sourceDropdown . selectOption ( "2" ) ; // Change source
68+ await leadPage . expectedCloseDate . fill ( "2025-12-31" ) ; // Update close date
69+ await leadPage . typeDropdown . selectOption ( "2" ) ; // Change type
70+ await leadPage . leadValueInput . fill ( "2000" ) ; // Update lead value
71+
72+ // Update person details
73+ await leadPage . personEmailInput . fill ( updatedLeadData . email ) ;
74+ await leadPage . personPhoneInput . fill ( updatedLeadData . phone ) ;
75+
76+ // Save the updated lead
77+ await leadPage . saveLead ( ) ;
78+
79+ // Verify the updates were successful
80+ await expect ( leadPage . titleInput ) . toHaveValue ( updatedLeadData . title ) ;
81+ await expect ( leadPage . descriptionTextarea ) . toHaveValue ( updatedLeadData . description ) ;
82+ await expect ( leadPage . leadValueInput ) . toHaveValue ( "2000" ) ;
83+ await expect ( leadPage . personEmailInput ) . toHaveValue ( updatedLeadData . email ) ;
84+ await expect ( leadPage . personPhoneInput ) . toHaveValue ( updatedLeadData . phone ) ;
85+ } ) ;
4286
43-
44- } ) ;
4587
4688} )
0 commit comments