@@ -25,6 +25,9 @@ function pick<T>(options: T[]): T {
2525 return options [ Math . floor ( Math . random ( ) * options . length ) ] ;
2626}
2727
28+ const DEFAULT_TITLE = "baz" ;
29+ const DEFAULT_FLAG_KEY = "flag1" ;
30+
2831async function getOpenedWidgetContainer (
2932 page : Page ,
3033 initOptions : Omit < InitOptions , "publishableKey" > = { } ,
@@ -54,8 +57,8 @@ async function getOpenedWidgetContainer(
5457 const reflag = new ReflagClient({publishableKey: "${ KEY } ", user: {id: "foo"}, company: {id: "bar"}, ...${ JSON . stringify ( initOptions ?? { } ) } });
5558 await reflag.initialize();
5659 await reflag.requestFeedback({
57- flagKey: "flag1 ",
58- title: "baz ",
60+ flagKey: "${ DEFAULT_FLAG_KEY } ",
61+ title: "${ DEFAULT_TITLE } ",
5962 ...${ JSON . stringify ( feedbackOptions ?? { } ) } ,
6063 });
6164 })()
@@ -177,7 +180,7 @@ test("Opens a feedback widget in the bottom right by default", async ({
177180 const bbox = await container . locator ( "dialog" ) . boundingBox ( ) ;
178181 expect ( bbox ?. x ) . toEqual ( WINDOW_WIDTH - bbox ! . width - 16 ) ;
179182 expect ( bbox ?. y ) . toBeGreaterThan ( WINDOW_HEIGHT - bbox ! . height - 30 ) ; // Account for browser differences
180- expect ( bbox ?. y ) . toBeLessThan ( WINDOW_HEIGHT - bbox ! . height ) ;
183+ expect ( bbox ?. y ) . toBeLessThan ( WINDOW_HEIGHT - bbox ! . height + 10 ) ;
181184} ) ;
182185
183186test ( "Opens a feedback widget in the correct position when overridden" , async ( {
@@ -206,7 +209,6 @@ test("Opens a feedback widget with the correct translations", async ({
206209 page,
207210} ) => {
208211 const translations : Partial < FeedbackTranslations > = {
209- ScoreStatusDescription : "Choisissez une note et laissez un commentaire" ,
210212 ScoreVeryDissatisfiedLabel : "Très insatisfait" ,
211213 ScoreDissatisfiedLabel : "Insatisfait" ,
212214 ScoreNeutralLabel : "Neutre" ,
@@ -224,7 +226,6 @@ test("Opens a feedback widget with the correct translations", async ({
224226 } ) ;
225227
226228 await expect ( container ) . toBeAttached ( ) ;
227- await expect ( container ) . toContainText ( translations . ScoreStatusDescription ! ) ;
228229 await expect ( container ) . toContainText (
229230 translations . ScoreVeryDissatisfiedLabel ! ,
230231 ) ;
@@ -235,86 +236,6 @@ test("Opens a feedback widget with the correct translations", async ({
235236 await expect ( container ) . toContainText ( translations . SendButton ! ) ;
236237} ) ;
237238
238- test ( "Sends a request when choosing a score immediately" , async ( { page } ) => {
239- const expectedScore = pick ( [ 1 , 2 , 3 , 4 , 5 ] ) ;
240- let sentJSON : object | null = null ;
241-
242- await page . route ( `${ API_HOST } /feedback` , async ( route ) => {
243- sentJSON = route . request ( ) . postDataJSON ( ) ;
244- await route . fulfill ( {
245- status : 200 ,
246- body : JSON . stringify ( { feedbackId : "123" } ) ,
247- contentType : "application/json" ,
248- } ) ;
249- } ) ;
250-
251- const container = await getOpenedWidgetContainer ( page ) ;
252- await setScore ( container , expectedScore ) ;
253-
254- await expect
255- . poll ( ( ) => sentJSON )
256- . toEqual ( {
257- companyId : "bar" ,
258- key : "flag1" ,
259- score : expectedScore ,
260- question : "baz" ,
261- userId : "foo" ,
262- source : "widget" ,
263- } ) ;
264- } ) ;
265-
266- test ( "Shows a success message after submitting a score" , async ( { page } ) => {
267- await page . route ( `${ API_HOST } /feedback` , async ( route ) => {
268- await route . fulfill ( {
269- status : 200 ,
270- body : JSON . stringify ( { feedbackId : "123" } ) ,
271- contentType : "application/json" ,
272- } ) ;
273- } ) ;
274-
275- const container = await getOpenedWidgetContainer ( page ) ;
276-
277- await expect (
278- container . getByText ( DEFAULT_TRANSLATIONS . ScoreStatusDescription ) ,
279- ) . toHaveCSS ( "opacity" , "1" ) ;
280- await expect (
281- container . getByText ( DEFAULT_TRANSLATIONS . ScoreStatusReceived ) ,
282- ) . toHaveCSS ( "opacity" , "0" ) ;
283-
284- await setScore ( container , 3 ) ;
285-
286- await expect (
287- container . getByText ( DEFAULT_TRANSLATIONS . ScoreStatusDescription ) ,
288- ) . toHaveCSS ( "opacity" , "0" ) ;
289- await expect (
290- container . getByText ( DEFAULT_TRANSLATIONS . ScoreStatusReceived ) ,
291- ) . toHaveCSS ( "opacity" , "1" ) ;
292- } ) ;
293-
294- test ( "Shows the comment field after submitting a score" , async ( { page } ) => {
295- await page . route ( `${ API_HOST } /feedback` , async ( route ) => {
296- await route . fulfill ( {
297- status : 200 ,
298- body : JSON . stringify ( { feedbackId : "123" } ) ,
299- contentType : "application/json" ,
300- } ) ;
301- } ) ;
302-
303- const container = await getOpenedWidgetContainer ( page ) ;
304-
305- await expect ( container . locator ( ".form-expanded-content" ) ) . toHaveCSS (
306- "opacity" ,
307- "0" ,
308- ) ;
309-
310- await setScore ( container , 1 ) ;
311-
312- await expect ( container . locator ( ".form-expanded-content" ) ) . toHaveCSS (
313- "opacity" ,
314- "1" ,
315- ) ;
316- } ) ;
317-
318239test ( "Sends a request with both the score and comment when submitting" , async ( {
319240 page,
320241} ) => {
@@ -557,6 +478,7 @@ test("Submits feedback with score-only inputMode", async ({ page }) => {
557478 ) ;
558479
559480 await setScore ( container , expectedScore ) ;
481+ await submitForm ( container ) ;
560482
561483 await expect
562484 . poll ( ( ) => sentJSON )
0 commit comments