1- import { Page } from '@playwright/test' ;
1+ import { Page , expect } from '@playwright/test' ;
22import { Persona } from './sign-in.page' ;
33
44type Details = {
@@ -12,25 +12,107 @@ export class GiveSpontaneousFeedbackPage {
1212 constructor ( private page : Page ) { }
1313
1414 async goto ( ) {
15- await this . page . goto ( `/fr/give` ) ;
15+ await this . page . goto ( '/fr/give' ) ;
16+
17+ await this . page . waitForURL ( '/fr/give' ) ;
1618 }
1719
18- async give ( persona : Persona , details : Details ) {
19- await this . page . getByLabel ( 'Email de votre collègue' ) . fill ( persona ) ;
20+ async fill ( persona : Persona | '' | undefined , details : Partial < Details > ) {
21+ if ( persona !== undefined ) {
22+ await this . page . getByRole ( 'combobox' , { name : 'Email de votre collègue' } ) . fill ( persona ) ;
23+ }
24+
25+ if ( details . context !== undefined ) {
26+ await this . page . getByRole ( 'textbox' , { name : 'Contexte' } ) . fill ( details . context ) ;
27+ }
28+
29+ if ( details . positive !== undefined ) {
30+ await this . page . getByRole ( 'textbox' , { name : 'Points forts' } ) . fill ( details . positive ) ;
31+ }
32+
33+ if ( details . negative !== undefined ) {
34+ await this . page . getByRole ( 'textbox' , { name : "Axes d'améliorations" } ) . fill ( details . negative ) ;
35+ }
36+
37+ if ( details . comment !== undefined ) {
38+ await this . page . getByRole ( 'textbox' , { name : 'Commentaire' } ) . fill ( details . comment ) ;
39+ }
40+ }
2041
21- await this . page . getByText ( 'Contexte' ) . fill ( details . context ) ;
22- await this . page . getByText ( 'Points forts' ) . fill ( details . positive ) ;
23- await this . page . getByText ( "Axes d'améliorations" ) . fill ( details . negative ) ;
24- await this . page . getByText ( 'Commentaire' ) . fill ( details . comment ) ;
42+ async expect ( persona : Persona | '' | undefined , details : Partial < Details > ) {
43+ if ( persona !== undefined ) {
44+ await expect (
45+ this . page . getByRole ( 'combobox' , { name : 'Email de votre collègue' } ) ,
46+ `Feedback receiver should be ${ persona ? persona : 'empty' } ` ,
47+ ) . toHaveValue ( persona ) ;
48+ }
49+
50+ if ( details . context !== undefined ) {
51+ await expect (
52+ this . page . getByRole ( 'textbox' , { name : 'Contexte' } ) ,
53+ 'Feedback "context" should be visible' ,
54+ ) . toHaveValue ( details . context ) ;
55+ }
56+
57+ if ( details . positive !== undefined ) {
58+ await expect (
59+ this . page . getByRole ( 'textbox' , { name : 'Points forts' } ) ,
60+ 'Feedback "positive" should be visible' ,
61+ ) . toHaveValue ( details . positive ) ;
62+ }
63+
64+ if ( details . negative !== undefined ) {
65+ await expect (
66+ this . page . getByRole ( 'textbox' , { name : "Axes d'améliorations" } ) ,
67+ 'Feedback "negative" should be visible' ,
68+ ) . toHaveValue ( details . negative ) ;
69+ }
70+
71+ if ( details . comment !== undefined ) {
72+ await expect (
73+ this . page . getByRole ( 'textbox' , { name : 'Commentaire' } ) ,
74+ 'Feedback "comment" should be visible' ,
75+ ) . toHaveValue ( details . comment ) ;
76+ }
77+ }
2578
79+ async submit ( ) {
2680 await this . page . getByRole ( 'button' , { name : 'Envoyer' } ) . click ( ) ;
2781 await this . page . getByRole ( 'button' , { name : 'Confirmer' } ) . click ( ) ;
2882
2983 await this . page . waitForURL ( '/fr/give/success' ) ;
3084 }
3185
32- async gotoAndGive ( persona : Persona , details : Details ) {
86+ async gotoFillAndSubmit ( persona : Persona , details : Details ) {
3387 await this . goto ( ) ;
34- await this . give ( persona , details ) ;
88+ await this . fill ( persona , details ) ;
89+ await this . submit ( ) ;
90+ }
91+
92+ // ----- draft -----
93+
94+ async saveAsDraft ( ) {
95+ await this . page . getByRole ( 'button' , { name : 'Sauvegarder' } ) . click ( ) ;
96+ }
97+
98+ async applyDraft ( persona : Persona ) {
99+ await this . draftHandler ( persona , 'edit' ) ;
100+ }
101+
102+ async deleteDraft ( persona : Persona ) {
103+ await this . draftHandler ( persona , 'delete' ) ;
104+ }
105+
106+ private async draftHandler ( persona : Persona , action : 'edit' | 'delete' ) {
107+ await this . page . getByRole ( 'button' , { name : 'Brouillons' } ) . click ( ) ;
108+
109+ // Wait until the the `<table>` is rendered
110+ await this . page . locator ( 'tbody' ) . waitFor ( ) ;
111+
112+ await this . page
113+ . locator ( 'tbody > tr' , { has : this . page . getByRole ( 'cell' , { name : persona } ) } )
114+ . getByRole ( 'button' )
115+ . filter ( { hasText : action } )
116+ . click ( ) ;
35117 }
36118}
0 commit comments