1- import { expect , test } from "@playwright/test" ;
1+ import { expect , test , type Page } from "@playwright/test" ;
22import { mkdirSync } from "node:fs" ;
33
44import { installMockBridge } from "../helpers/bridge" ;
@@ -10,6 +10,31 @@ test.beforeEach(async ({ page }) => {
1010 await installMockBridge ( page , { pairingStartDelayMs : 300 } ) ;
1111} ) ;
1212
13+ async function emitPairingEvent ( page : Page , event : string , payload ?: unknown ) {
14+ await page . evaluate (
15+ async ( { eventName, eventPayload } ) => {
16+ const internals = (
17+ window as Window & {
18+ __TAURI_INTERNALS__ ?: {
19+ invoke ?: (
20+ command : string ,
21+ args : Record < string , unknown > ,
22+ ) => Promise < unknown > ;
23+ } ;
24+ }
25+ ) . __TAURI_INTERNALS__ ;
26+ if ( ! internals ?. invoke ) {
27+ throw new Error ( "Tauri E2E event bridge is unavailable" ) ;
28+ }
29+ await internals . invoke ( "plugin:event|emit" , {
30+ event : eventName ,
31+ payload : eventPayload ,
32+ } ) ;
33+ } ,
34+ { eventName : event , eventPayload : payload } ,
35+ ) ;
36+ }
37+
1338test ( "mobile pairing starts on demand and reveals the QR code" , async ( {
1439 page,
1540} ) => {
@@ -103,26 +128,8 @@ test("mobile pairing starts on demand and reveals the QR code", async ({
103128 0.5 ,
104129 ) ;
105130
106- await page . evaluate ( async ( ) => {
107- const internals = (
108- window as Window & {
109- __TAURI_INTERNALS__ ?: {
110- invoke ?: (
111- command : string ,
112- args : Record < string , unknown > ,
113- ) => Promise < unknown > ;
114- } ;
115- }
116- ) . __TAURI_INTERNALS__ ;
117- if ( ! internals ?. invoke ) {
118- throw new Error ( "Tauri E2E event bridge is unavailable" ) ;
119- }
120- await internals . invoke ( "plugin:event|emit" , {
121- event : "pairing-error" ,
122- payload : {
123- message : "Session timed out" ,
124- } ,
125- } ) ;
131+ await emitPairingEvent ( page , "pairing-error" , {
132+ message : "Session timed out" ,
126133 } ) ;
127134
128135 await expect ( qrCode ) . toHaveCount ( 0 ) ;
@@ -150,3 +157,29 @@ test("mobile pairing starts on demand and reveals the QR code", async ({
150157 await card . screenshot ( { path : `${ SCREENSHOT_DIR } /pairing-card.png` } ) ;
151158 await qrCode . screenshot ( { path : `${ SCREENSHOT_DIR } /pairing-qr.png` } ) ;
152159} ) ;
160+
161+ test ( "late pairing events are ignored after canceling" , async ( { page } ) => {
162+ await page . goto ( "/" ) ;
163+ await page . getByTestId ( "open-settings" ) . click ( ) ;
164+ await page . getByTestId ( "profile-popover-settings" ) . click ( ) ;
165+ await page . getByTestId ( "settings-nav-mobile" ) . click ( ) ;
166+
167+ const card = page . getByTestId ( "mobile-pairing-card" ) ;
168+ await card . getByTestId ( "start-pairing-button" ) . click ( ) ;
169+ await expect ( page . getByTestId ( "mobile-pairing-qr" ) ) . toBeVisible ( ) ;
170+
171+ await emitPairingEvent ( page , "pairing-sas-received" , { sas : "123456" } ) ;
172+ const dialog = page . getByTestId ( "mobile-pairing-dialog" ) ;
173+ await expect ( dialog ) . toBeVisible ( ) ;
174+ await dialog . getByRole ( "button" , { name : "Close" } ) . click ( ) ;
175+
176+ await expect ( dialog ) . toHaveCount ( 0 ) ;
177+ await expect ( card . getByText ( "Pairing was canceled." ) ) . toBeVisible ( ) ;
178+
179+ await emitPairingEvent ( page , "pairing-complete" ) ;
180+ await emitPairingEvent ( page , "pairing-sas-received" , { sas : "654321" } ) ;
181+
182+ await expect ( dialog ) . toHaveCount ( 0 ) ;
183+ await expect ( page . getByTestId ( "mobile-pairing-done" ) ) . toHaveCount ( 0 ) ;
184+ await expect ( card . getByText ( "Pairing was canceled." ) ) . toBeVisible ( ) ;
185+ } ) ;
0 commit comments