2023-03-22 03:46:52 +08:00
const { expect } = require ( '@playwright/test' ) ;
const { MultiUsers } = require ( '../user/multiusers' ) ;
const e = require ( '../core/elements' ) ;
const { killConnection } = require ( './util' ) ;
2023-05-11 03:51:05 +08:00
const { runScript } = require ( '../core/util' ) ;
const { ELEMENT _WAIT _TIME } = require ( '../core/constants' ) ;
2023-03-22 03:46:52 +08:00
class Reconnection extends MultiUsers {
constructor ( browser , context ) {
super ( browser , context ) ;
}
async chat ( ) {
// chat enabled
await this . modPage . waitForSelector ( e . chatBox ) ;
const chatBoxLocator = this . modPage . getLocator ( e . chatBox ) ;
await expect ( chatBoxLocator ) . toBeEnabled ( ) ;
killConnection ( ) ;
2023-05-11 03:51:05 +08:00
// chat disabled and notification bar displayed
Promise . all ( [
expect ( chatBoxLocator ) . toBeDisabled ( { timeout : ELEMENT _WAIT _TIME } ) ,
this . modPage . hasElement ( e . reconnectingBar ) ,
] ) ;
2023-03-22 03:46:52 +08:00
// reconnected -> chat enabled
await expect ( chatBoxLocator ) . toBeEnabled ( ) ;
2023-05-11 03:51:05 +08:00
await this . modPage . wasRemoved ( e . notificationBannerBar ) ;
2023-03-22 03:46:52 +08:00
}
2023-05-11 03:51:05 +08:00
async microphone ( ) {
2023-03-22 03:46:52 +08:00
// join audio
await this . modPage . waitAndClick ( e . joinAudio ) ;
await this . modPage . joinMicrophone ( ) ;
// mute is available
const muteMicButtonLocator = this . modPage . getLocator ( e . muteMicButton ) ;
await expect ( muteMicButtonLocator ) . toBeEnabled ( ) ;
killConnection ( ) ;
2023-05-11 03:51:05 +08:00
await this . modPage . hasElement ( e . reconnectingBar ) ;
2023-03-22 03:46:52 +08:00
2023-05-11 03:51:05 +08:00
// reconnected
await this . modPage . wasRemoved ( e . notificationBannerBar ) ;
2023-03-22 03:46:52 +08:00
2023-05-11 03:51:05 +08:00
// audio connection should keep connected
await this . modPage . hasElement ( e . muteMicButton ) ;
await this . modPage . hasElement ( e . isTalking ) ;
}
2023-03-22 03:46:52 +08:00
2023-05-11 03:51:05 +08:00
async checkRootPermission ( ) {
const checkSudo = await runScript ( 'timeout -k 1 1 sudo id' , {
handleOutput : ( output ) => output ? true : false
} )
await expect ( checkSudo , 'Sudo failed: need to run this test with root permission (can be fixed by running "sudo -v" and entering the password)' ) . toBeTruthy ( ) ;
2023-03-22 03:46:52 +08:00
}
}
exports . Reconnection = Reconnection ;