* feat(tracker): add support for multi tab sessions
* feat(backend): added support of multitabs
* fix(backend): added support of deprecated batch meta message to pre-decoder
* fix(backend): fixed nil meta issue for TabData messages in sink
* feat(player): add tabmanager
* feat(player): basic tabchange event support
* feat(player): pick tabstate for console panel and timeline
* fix(player): only display tabs that are created
* feat(player): connect performance, xray and events to tab state
* feat(player): merge all tabs data for overview
* feat(backend/tracker): extract tabdata into separate message from batchmeta
* fix(tracker): fix new session check
* fix(backend): remove batchmetadeprecated
* fix(backend): fix switch case
* fix(player): fix for tab message size
* feat(tracker): check for active tabs with broadcast channel
* feat(tracker): prevent multiple messages
* fix(tracker): ignore beacons from same tab, only ask if token isnt present yet, add small delay before start to wait for answer
* feat(player): support new msg struct in assist player
* fix(player): fix some livepl components for multi tab states
* feat(tracker): add option to disable multitab
* feat(tracker): add multitab to assist plugin
* feat(player): back compat for tab id
* fix(ui): fix missing list in controls
* fix(ui): optional list update
* feat(ui): fix visuals for multitab; use window focus event for tabs
* fix(tracker): fix for dying tests (added tabid to writer, refactored other tests)
* feat(ui): update LivePlayerSubHeader.tsx to support tabs
* feat(backend): added tabs support to devtools mob files
* feat(ui): connect state to current tab properly
* feat(backend): added multitab support to assits
* feat(backend): removed data check in agent message
* feat(backend): debug on
* fix(backend): fixed typo in message broadcast
* feat(backend): fixed issue in connect method
* fix(assist): fixed typo
* feat(assist): added more debug logs
* feat(assist): removed one log
* feat(assist): more logs
* feat(assist): use query.peerId
* feat(assist): more logs
* feat(assist): fixed session update
* fix(assist): fixed getSessions
* fix(assist): fixed request_control broadcast
* fix(assist): fixed typo
* fix(assist): added missed line
* fix(assist): fix typo
* feat(tracker): multitab support for assist sessions
* fix(tracker): fix dead tests (tabid prop)
* fix(tracker): fix yaml
* fix(tracker): timers issue
* fix(ui): fix ui E2E tests with magic?
* feat(assist): multitabs support for ee version
* fix(assist): added missed method import
* fix(tracker): fix fix events in assist
* feat(assist): added back compatibility for sessions without tabId
* fix(assist): apply message's top layer structure before broadcast call
* fix(assist): added random tabID for prev version
* fix(assist): added random tabID for prev version (ee)
* feat(assist): added debug logs
* fix(assist): fix typo in sessions_agents_count method
* fix(assist): fixed more typos in copy-pastes
* fix(tracker): fix restart timings
* feat(backend): added tabIDs for some events
* feat(ui): add tab change event to the user steps bar
* Revert "feat(backend): added tabIDs for some events"
This reverts commit 1467ad7f9f.
* feat(ui): revert timeline and xray to grab events from all tabs
* fix(ui): fix typo
---------
Co-authored-by: Alexander Zavorotynskiy <zavorotynskiy@pm.me>
208 lines
6 KiB
TypeScript
208 lines
6 KiB
TypeScript
import RemoteControl, { RCStatus, } from '../src/RemoteControl'
|
|
import ConfirmWindow from '../src/ConfirmWindow/ConfirmWindow'
|
|
import { describe, expect, test, jest, beforeEach, afterEach, } from '@jest/globals'
|
|
|
|
describe('RemoteControl', () => {
|
|
let remoteControl
|
|
let options
|
|
let onGrand
|
|
let onRelease
|
|
let confirmWindowMountMock
|
|
let confirmWindowRemoveMock
|
|
|
|
beforeEach(() => {
|
|
options = {
|
|
/* mock options */
|
|
}
|
|
onGrand = jest.fn()
|
|
onRelease = jest.fn()
|
|
confirmWindowMountMock = jest.fn(() => Promise.resolve(true))
|
|
confirmWindowRemoveMock = jest.fn()
|
|
|
|
jest.spyOn(window, 'HTMLInputElement').mockImplementation((): any => ({
|
|
value: '',
|
|
dispatchEvent: jest.fn(),
|
|
}))
|
|
|
|
jest.spyOn(window, 'HTMLTextAreaElement').mockImplementation((): any => ({
|
|
value: '',
|
|
dispatchEvent: jest.fn(),
|
|
}))
|
|
|
|
jest
|
|
.spyOn(ConfirmWindow.prototype, 'mount')
|
|
.mockImplementation(confirmWindowMountMock)
|
|
jest
|
|
.spyOn(ConfirmWindow.prototype, 'remove')
|
|
.mockImplementation(confirmWindowRemoveMock)
|
|
|
|
remoteControl = new RemoteControl(options, onGrand, onRelease)
|
|
})
|
|
|
|
afterEach(() => {
|
|
jest.restoreAllMocks()
|
|
})
|
|
|
|
test('should initialize with disabled status', () => {
|
|
expect(remoteControl.status).toBe(RCStatus.Disabled)
|
|
expect(remoteControl.agentID).toBeNull()
|
|
expect(remoteControl.confirm).toBeNull()
|
|
expect(remoteControl.mouse).toBeNull()
|
|
})
|
|
|
|
test('should request control when calling requestControl method', () => {
|
|
const id = 'agent123'
|
|
remoteControl.requestControl(id)
|
|
|
|
expect(remoteControl.agentID).toBe(id)
|
|
expect(remoteControl.status).toBe(RCStatus.Requesting)
|
|
expect(confirmWindowMountMock).toHaveBeenCalled()
|
|
})
|
|
|
|
test('should grant control when calling grantControl method', () => {
|
|
const id = 'agent123'
|
|
remoteControl.grantControl(id)
|
|
|
|
expect(remoteControl.agentID).toBe(id)
|
|
expect(remoteControl.status).toBe(RCStatus.Enabled)
|
|
expect(onGrand).toHaveBeenCalledWith(id)
|
|
expect(remoteControl.mouse).toBeDefined()
|
|
})
|
|
|
|
test('should release control when calling releaseControl method', () => {
|
|
const isDenied = true
|
|
remoteControl['confirm'] = { remove: jest.fn(), } as unknown as ConfirmWindow
|
|
const confirmSpy = jest.spyOn(remoteControl['confirm'], 'remove')
|
|
|
|
remoteControl.releaseControl(isDenied)
|
|
expect(remoteControl.agentID).toBeNull()
|
|
expect(remoteControl.status).toBe(RCStatus.Disabled)
|
|
expect(onRelease).toHaveBeenCalledWith(null, isDenied)
|
|
expect(confirmSpy).toHaveBeenCalled()
|
|
expect(remoteControl.mouse).toBeNull()
|
|
})
|
|
|
|
test('should reset mouse when calling resetMouse method', () => {
|
|
remoteControl.resetMouse()
|
|
|
|
expect(remoteControl.mouse).toBeNull()
|
|
})
|
|
|
|
test('should call mouse.scroll when calling scroll method with correct agentID', () => {
|
|
const id = 'agent123'
|
|
const d = 10
|
|
remoteControl.agentID = id
|
|
remoteControl.mouse = {
|
|
scroll: jest.fn(),
|
|
}
|
|
|
|
remoteControl.scroll(id, d)
|
|
|
|
expect(remoteControl.mouse.scroll).toHaveBeenCalledWith(d)
|
|
})
|
|
|
|
test('should not call mouse.scroll when calling scroll method with incorrect agentID', () => {
|
|
const id = 'agent123'
|
|
const d = 10
|
|
remoteControl.agentID = 'anotherAgent'
|
|
remoteControl.mouse = {
|
|
scroll: jest.fn(),
|
|
}
|
|
|
|
remoteControl.scroll(id, d)
|
|
|
|
expect(remoteControl.mouse.scroll).not.toHaveBeenCalled()
|
|
})
|
|
|
|
test('should call mouse.move when calling move method with correct agentID', () => {
|
|
const id = 'agent123'
|
|
const xy = { x: 10, y: 20, }
|
|
remoteControl.agentID = id
|
|
remoteControl.mouse = {
|
|
move: jest.fn(),
|
|
}
|
|
|
|
remoteControl.move(id, xy)
|
|
|
|
expect(remoteControl.mouse.move).toHaveBeenCalledWith(xy)
|
|
})
|
|
|
|
test('should not call mouse.move when calling move method with incorrect agentID', () => {
|
|
const id = 'agent123'
|
|
const xy = { x: 10, y: 20, }
|
|
remoteControl.agentID = 'anotherAgent'
|
|
remoteControl.mouse = {
|
|
move: jest.fn(),
|
|
}
|
|
|
|
remoteControl.move(id, xy)
|
|
|
|
expect(remoteControl.mouse.move).not.toHaveBeenCalled()
|
|
})
|
|
|
|
test('should call mouse.click when calling click method with correct agentID', () => {
|
|
const id = 'agent123'
|
|
const xy = { x: 10, y: 20, }
|
|
remoteControl.agentID = id
|
|
remoteControl.mouse = {
|
|
click: jest.fn(),
|
|
}
|
|
|
|
remoteControl.click(id, xy)
|
|
|
|
expect(remoteControl.mouse.click).toHaveBeenCalledWith(xy)
|
|
})
|
|
|
|
test('should not call mouse.click when calling click method with incorrect agentID', () => {
|
|
const id = 'agent123'
|
|
const xy = { x: 10, y: 20, }
|
|
remoteControl.agentID = 'anotherAgent'
|
|
remoteControl.mouse = {
|
|
click: jest.fn(),
|
|
}
|
|
|
|
remoteControl.click(id, xy)
|
|
|
|
expect(remoteControl.mouse.click).not.toHaveBeenCalled()
|
|
})
|
|
|
|
test('should set the focused element when calling focus method', () => {
|
|
const id = 'agent123'
|
|
const element = document.createElement('div')
|
|
|
|
remoteControl.focus(id, element)
|
|
|
|
expect(remoteControl.focused).toBe(element)
|
|
})
|
|
|
|
test('should call setInputValue and dispatch input event when calling input method with HTMLInputElement', () => {
|
|
const id = 'agent1234'
|
|
const value = 'test_test'
|
|
const element = document.createElement('input')
|
|
const dispatchSpy = jest.spyOn(element, 'dispatchEvent')
|
|
remoteControl.agentID = id
|
|
remoteControl.mouse = true
|
|
remoteControl.focused = element
|
|
|
|
remoteControl.input(id, value)
|
|
|
|
expect(element.value).toBe(value)
|
|
expect(dispatchSpy).toHaveBeenCalledWith(
|
|
new Event('input', { bubbles: true, })
|
|
)
|
|
})
|
|
|
|
test('should update innerText when calling input method with content editable element', () => {
|
|
const id = 'agent123'
|
|
const value = 'test'
|
|
const element = document.createElement('div')
|
|
// @ts-ignore
|
|
element['isContentEditable'] = true
|
|
remoteControl.agentID = id
|
|
remoteControl.mouse = true
|
|
remoteControl.focused = element
|
|
|
|
remoteControl.input(id, value)
|
|
expect(element.innerText).toBe(value)
|
|
})
|
|
})
|