
    5i3                     r    d Z ddlZddlmc mZ ddlZddlm	Z	  G d d      Z
 G d d      Z G d d	      Zy)
z
E2E Full User Journey Tests.

Simulates complete user workflows based on:
- /mnt/e/genesis-system/RECEPTIONISTAI/DEMO_RECORDING_SUMMARY.md
- /mnt/e/genesis-system/Conversations/gemini_ultra_plan_features_extracted.md
    N)expectc                   (    e Zd ZdZd Zd Zd Zd Zy)TestCompleteUserJourneyz'Full end-to-end user journey scenarios.c                    |j                  | d       |j                  d       t        |j                  d            j	                          |j                  d      j
                  }t        |      j	                          |j                          |j                  d       |j                  d      }t        |      j	                          |j                  d      j
                  }|j                  d       |j                  d	      j
                  }|j                          |j                  d
       |j                  d      }|j                  } |       }	d}
|	|
kD  }|st        j                  d|fd|	|
f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |	      t        j                  |
      dz  }t        j                   d      dz   d|iz  }t#        t        j$                  |            dx}x}	x}}
y)z
        Test: New visitor lands on demo page -> opens widget -> sends message.

        User Story: As a first-time visitor, I want to quickly test
        the chat widget to see how it works.
        
/demo.htmlnetworkidlebody1button.widget-trigger, button[aria-label*="call"]  z1.chat-interface, .chat-window, .message-container;input[type="text"], textarea, input[placeholder*="message"]zWhat are your hours?3button[aria-label*="send"], button:has-text("Send")  +.message, .chat-message, [class*="message"]r   >zC%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.count
}()
} > %(py7)smessagespy0py2py4py7z"No messages appeared after sending
>assert %(py9)spy9N)gotowait_for_load_stater   locatorto_be_visiblefirstclickwait_for_timeoutfillcount
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_saferepr_format_assertmsgAssertionError_format_explanation)selfpage
widget_urltriggerchat_interface
text_inputsend_buttonr   @py_assert1@py_assert3@py_assert6@py_assert5@py_format8@py_format10s                 4/mnt/e/genesis-system/tests/e2e/test_user_journey.pytest_first_time_visitor_journeyz7TestCompleteUserJourney.test_first_time_visitor_journey   s    			ZL
+,  / 	t||F#$224 ,,RSYYw%%' 	d# &YZ~,,. \\"_`ff
./ ll#XY__ 	d# << MN~~I~I!I!#III!IIIIIIxIIIxIII~IIIIII!III%IIIIIIII    c                    |j                  | d       |j                  d      j                  j                          |j	                  d       |j                  d      j                  }|j                  d       |j                  d      j                  }|j                          |j	                  d       |j                  d      }|j                  } |       }d	}||kD  }	|	st        j                  d
|	fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      dz  }
t        j                  d      dz   d|
iz  }t        t        j                  |            dx}x}x}	}|j                  d       |j                          |j	                  d       |j                  } |       }d}||k\  }	|	st        j                  d|	fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      dz  }
t        j                  d      dz   d|
iz  }t        t        j                  |            dx}x}x}	}y)z
        Test: Visitor provides contact info (lead capture scenario).

        User Story: As a potential customer, I want to leave my contact
        details so the business can call me back.
        r   r
   r   r   z-Hi, I'm Sarah. Can you call me on 0412345678?r   r   r   r   r   r   r   r   z"Lead capture message not processedr   r   NzDo you service the Bondi area?   >=)zD%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.count
}()
} >= %(py7)szFollow-up message not processedr   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r2   r3   r   r4   r5   r6   r7   r8   r9   s               r:   test_lead_capture_journeyz1TestCompleteUserJourney.test_lead_capture_journey:   s    			ZL
+,HIOOUUWd# \\"_`ff
GHll#XY__d# << MN~~I~I!I!#III!IIIIIIxIIIxIII~IIIIII!III%IIIIIIII 	89d# ~~G~G1G1$GGG1GGGGGGxGGGxGGG~GGGGGG1GGG&GGGGGGGGr<   c           	         |j                  | d       |j                  d      j                  j                          |j	                  d       g d}|D ]j  }|j                  d      j                  }|j                  |       |j                  d      j                  }|j                          |j	                  d       l |j                  d      }|j                  } |       }	t        |      }
|	|
k\  }|sat        j                  d	|fd
|	|
f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |	      dt        j                         v st        j                  t              rt        j                  t              nddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |
      dz  }t        j                  d      dz   d|iz  }t        t        j                   |            dx}x}	x}}
y)z
        Test: User inquires about booking an appointment.

        User Story: As a customer, I want to book a service appointment
        through the chat widget.
        r   r
   r   )zI'd like to book an appointmentz&I have a leaking tap that needs fixingz!How much does a leak repair cost?z"What's your earliest availability?r   r   	  r   r?   zb%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.count
}()
} >= %(py9)s
{%(py9)s = %(py6)s(%(py7)s)
}r   lenconversationr   r   r   py6r   r   zBooking conversation incompletez
>assert %(py11)spy11N)r   r   r   r    r!   r"   r#   rG   r$   r%   r&   r'   r(   r)   r*   r+   r,   )r-   r.   r/   rH   messager2   r3   r   r4   r5   @py_assert8r7   r9   @py_format12s                 r:   test_booking_inquiry_journeyz4TestCompleteUserJourney.test_booking_inquiry_journey^   s    			ZL
+,HIOOUUWd#
 $ 	(G&cdjjJOOG$,,'\]ccK!!$'	( << MN~~W~W3|#4W#44WWW#4WWWWWWxWWWxWWW~WWWWWWWWW3WWW3WWWWWW|WWW|WWW#4WWW6WWWWWWWWr<   c                    |j                  | d       |j                  d      j                  j                          |j	                  d       |j                  d      j                  }|j                  d       |j                  d      j                  }|j                          |j	                  d       |j                  | d       |j                  d      j                  j                          |j	                  d       |j                  d      j                  }|j                  d       |j                  d      j                  }|j                          |j	                  d       |j                  d	      }|j                  } |       }d
}	||	kD  }
|
st        j                  d|
fd||	f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |	      dz  }dd|iz  }t        t        j                  |            dx}x}x}
}	y)z
        Test: User starts conversation on mobile, continues on desktop.

        User Story: As a user, I want my conversation to persist
        across devices.
        r   r
   r   r   zI need a plumberr   i  zCan you come today?r   r   r   r   r   r   assert %(py9)sr   Nr   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r+   r,   )r-   r.   mobile_pager/   r2   r3   r   r4   r5   r6   r7   r8   r9   s                r:   test_multi_device_journeyz1TestCompleteUserJourney.test_multi_device_journey~   s    	J<z23OPVV\\^$$T* !(()fgmm
*+!))*_`ff$$T* 			ZL
+,HIOOUUWd# \\"_`ff
-.ll#XY__d# << MN~~#~#!#!####!######x###x###~######!#######r<   N)__name__
__module____qualname____doc__r;   rC   rO   rT    r<   r:   r   r      s    1'JV HHX@($r<   r   c                   (    e Zd ZdZd Zd Zd Zd Zy)TestRealisticScenariosz9Real-world usage scenarios based on Gemini chat examples.c                    |j                  | d       |j                  d      j                  j                          |j	                  d       |j                  d      j                  }|j                  d       |j                  d      j                  }|j                          |j	                  d       |j                  d      }|j                  } |       }d	}||kD  }	|	st        j                  d
|	fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      dz  }
t        j                  d      dz   d|
iz  }t        t        j                  |            dx}x}x}	}y)z
        Scenario: Customer calls after business hours (AI handles 24/7).

        Based on: DEMO_RECORDING_SUMMARY.md - "24/7 availability pitch"
        r   r
   r   r   zAre you open now? It's 11pmr   r   r   r   r   r   r   r   zAfter-hours message not handledr   r   NrA   rB   s               r:   test_after_hours_inquiryz/TestRealisticScenarios.test_after_hours_inquiry   s0    			ZL
+,HIOOUUWd#\\"_`ff
56ll#XY__d#<< MN~~F~F!F!#FFF!FFFFFFxFFFxFFF~FFFFFF!FFF%FFFFFFFFr<   c           	         |j                  | d       |j                  d      j                  j                          |j	                  d       g d}|D ]j  }|j                  d      j                  }|j                  |       |j                  d      j                  }|j                          |j	                  d       l |j                  d      }|j                  } |       }	t        |      }
|	|
k\  }|sKt        j                  d	|fd
|	|
f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |	      dt        j                         v st        j                  t              rt        j                  t              nddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |
      dz  }dd|iz  }t        t        j                  |            dx}x}	x}}
y)z
        Scenario: Customer asks about pricing.

        Based on: ReceptionistAI demo scripts - pricing/quote requests
        r   r
   r   )zHow much do you charge?z$What's the cost for a toilet repair?zDo you have a call-out fee?r   r   rE   r   r?   rF   r   rG   pricing_questionsrI   zassert %(py11)srK   N)r   r   r   r    r!   r"   r#   rG   r$   r%   r&   r'   r(   r)   r+   r,   )r-   r.   r/   r_   questionr2   r3   r   r4   r5   rM   r7   r9   rN   s                 r:   test_pricing_inquiryz+TestRealisticScenarios.test_pricing_inquiry   s    			ZL
+,HIOOUUWd#
 * 	(H&cdjjJOOH%,,'\]ccK!!$'	( << MN~~9~93'8#99#99999#9999999x999x999~99999999939993999999'8999'8999#99999999r<   c                 \   |j                  | d       |j                  d      j                  j                          |j	                  d       |j                  d      j                  }|j                  d       |j                  d      j                  }|j                          |j	                  d       |j                  d      }|j                  } |       }d	}||kD  }	|	st        j                  d
|	fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      dz  }
dd|
iz  }t        t        j                  |            dx}x}x}	}y)zJ
        Scenario: Customer asks if business services their area.
        r   r
   r   r   z"Do you service Bondi and Randwick?r   r   r   r   r   r   r   r   rQ   r   NrR   rB   s               r:   test_service_area_inquiryz0TestRealisticScenarios.test_service_area_inquiry   s$    			ZL
+,HIOOUUWd#\\"_`ff
<=ll#XY__d#<< MN~~#~#!#!####!######x###x###~######!#######r<   c                    |j                  | d       |j                  d      j                  j                          |j	                  d       |j                  d      j                  }|j                  d       |j                  d      j                  }|j                          |j	                  d       |j                  d      }|j                  } |       }d	}||kD  }	|	st        j                  d
|	fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      dz  }
t        j                  d      dz   d|
iz  }t        t        j                  |            dx}x}x}	}y)zO
        Scenario: Customer has an emergency (burst pipe, flood, etc).
        r   r
   r   r   z0URGENT: I have a burst pipe flooding my kitchen!r   r   r   r   r   r   r   r   zEmergency message not handledr   r   NrA   rB   s               r:   test_emergency_requestz-TestRealisticScenarios.test_emergency_request   s0    			ZL
+,HIOOUUWd#\\"_`ff
JKll#XY__d#<< MN~~D~D!D!#DDD!DDDDDDxDDDxDDD~DDDDDD!DDD%DDDDDDDDr<   N)rU   rV   rW   rX   r]   ra   rc   re   rY   r<   r:   r[   r[      s    CG*:8$&Er<   r[   c                   "    e Zd ZdZd Zd Zd Zy)TestWidgetBehaviorz.Test widget-specific behaviors and edge cases.c                 f   |j                  | d       |j                  d      j                  j                          |j	                  d       |j                  d      }t        |      j                          |j                  d      j                  }|j                         r|j                          |j	                  d       t        |      j                          |j                  d      j                  j                          |j	                  d       t        |      j                          yy)zA
        Test: User can minimize and restore the widget.
        r   r
   r   z.chat-interface, .chat-windowzJbutton[aria-label*="close"], button[aria-label*="minimize"], .close-buttoni  N)	r   r   r   r    r!   r   r   
is_visiblenot_to_be_visible)r-   r.   r/   r1   close_buttons        r:   test_widget_minimize_restorez/TestWidgetBehavior.test_widget_minimize_restore  s     			ZL
+, 	HIOOUUWd#&EF~,,. ||$pqww""$ !!#& >"446 LLLMSSYY[!!#& >"002 %r<   c                 z   |j                  | d       |j                  d      j                  }|j                         }|j                  }|d   }|d   }d}||z  }	||	kD  }
|
st        j                  d|
fd||	f      t        j                  |      t        j                  |      t        j                  |      dz  }t        j                  d	      d
z   d|iz  }t        t        j                  |            dx}x}
x}x}}	|d   }|d   }d}||z  }	||	kD  }
|
st        j                  d|
fd||	f      t        j                  |      t        j                  |      t        j                  |      dz  }t        j                  d      d
z   d|iz  }t        t        j                  |            dx}x}
x}x}}	y)zQ
        Test: Widget appears in correct position (bottom-right corner).
        r   r
   xwidthgffffff?r   )z%(py1)s > (%(py4)s * %(py6)s))py1r   rJ   z#Widget not positioned on right sider   r   Nyheightg      ?z#Widget not positioned in lower half)r   r   r   bounding_boxviewport_sizer$   r%   r)   r*   r+   r,   )r-   r.   r/   r0   boxviewport@py_assert0r5   r7   @py_assert7@py_assert2r8   r9   s                r:   test_widget_positionz'TestWidgetBehavior.test_widget_position%  sC    			ZL
+,,,RSYY ""$%% 3xX(7+XcX+c1Xx11XXXx1XXXxXXX+XXXcXXX3XXXXXXXX3xY(8,YsY,s2Yx22YYYx2YYYxYYY,YYYsYYY4YYYYYYYYr<   c                    |j                  | d       |j                  d      j                  j                          |j	                  d       t        d      D ]p  }|j                  d      j                  }|j                  d|dz           |j                  d      j                  }|j                          |j	                  d	       r |j                  d
      j                  }|j                         r|j                  d      }|j                  d      }||k\  }	|	st        j                  d|	fd||f      dt        j                         v st        j                  |      rt        j                  |      nddt        j                         v st        j                  |      rt        j                  |      nddz  }
t        j                  d      dz   d|
iz  }t!        t        j"                  |            d}	yy)zB
        Test: Long conversations should scroll properly.
        r   r
   r   
   r   zTest message number    r   i  z7.messages, .chat-messages, [class*="message-container"]zel => el.scrollHeightzel => el.clientHeightr?   )z%(py0)s >= %(py2)sscroll_heightclient_height)r   r   z(Messages container not handling overflowz
>assert %(py4)sr   N)r   r   r   r    r!   ranger"   ri   evaluater$   r%   r&   r'   r(   r)   r*   r+   r,   )r-   r.   r/   ir2   r3   messages_containerr~   r   r4   @py_format3@py_format5s               r:   test_conversation_scrollz+TestWidgetBehavior.test_conversation_scroll7  ss    			ZL
+,HIOOUUWd# r 	(A&cdjjJOO21Q3%89,,'\]ccK!!$'	( "\\*cdjj((*.778OPM.778OPM !M1]]]=M]]]]]]=]]]=]]]]]]M]]]M]]]]3]]]]]]] +r<   N)rU   rV   rW   rX   rl   rz   r   rY   r<   r:   rg   rg     s    83<Z$^r<   rg   )rX   builtinsr&   _pytest.assertion.rewrite	assertionrewriter$   pytestplaywright.sync_apir   r   r[   rg   rY   r<   r:   <module>r      s@      &Z$ Z$zXE XEvN^ N^r<   