Skip to content

Commit

Permalink
👌 isolate forced layout issue tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan committed Feb 1, 2023
1 parent 433b364 commit 178c0de
Showing 1 changed file with 38 additions and 19 deletions.
57 changes: 38 additions & 19 deletions packages/rum/src/domain/record/observers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,11 @@ describe('initMouseInteractionObserver', () => {
let stopObserver: () => void
let sandbox: HTMLDivElement
let a: HTMLAnchorElement
let coordinatesComputed: boolean

beforeEach(() => {
if (isIE()) {
pending('IE not supported')
}
if (!window.visualViewport) {
pending('no visualViewport')
}

sandbox = document.createElement('div')
a = document.createElement('a')
Expand All @@ -362,27 +358,18 @@ describe('initMouseInteractionObserver', () => {
elementsScrollPositions: createElementsScrollPositions(),
})

coordinatesComputed = false
Object.defineProperty(window.visualViewport, 'offsetTop', {
get() {
coordinatesComputed = true
return 0
},
configurable: true,
})

mouseInteractionCallbackSpy = jasmine.createSpy()
stopObserver = initMouseInteractionObserver(mouseInteractionCallbackSpy, DefaultPrivacyLevel.ALLOW)
})

afterEach(() => {
sandbox.remove()
delete (window.visualViewport as any).offsetTop
stopObserver()
})

it('should compute x/y coordinates for click record', () => {
it('should generate click record', () => {
a.click()

expect(mouseInteractionCallbackSpy).toHaveBeenCalledWith({
id: jasmine.any(Number),
type: RecordType.IncrementalSnapshot,
Expand All @@ -395,12 +382,11 @@ describe('initMouseInteractionObserver', () => {
y: jasmine.any(Number),
},
})
expect(coordinatesComputed).toBeTrue()
})

// related to safari issue, see RUMF-1450
it('should not compute x/y coordinates for blur record', () => {
it('should generate blur record', () => {
a.blur()

expect(mouseInteractionCallbackSpy).toHaveBeenCalledWith({
id: jasmine.any(Number),
type: RecordType.IncrementalSnapshot,
Expand All @@ -411,6 +397,39 @@ describe('initMouseInteractionObserver', () => {
id: jasmine.any(Number),
},
})
expect(coordinatesComputed).toBeFalse()
})

// related to safari issue, see RUMF-1450
describe('forced layout issue', () => {
let coordinatesComputed: boolean

beforeEach(() => {
if (!window.visualViewport) {
pending('no visualViewport')
}

coordinatesComputed = false
Object.defineProperty(window.visualViewport, 'offsetTop', {
get() {
coordinatesComputed = true
return 0
},
configurable: true,
})
})

afterEach(() => {
delete (window.visualViewport as any).offsetTop
})

it('should compute x/y coordinates for click record', () => {
a.click()
expect(coordinatesComputed).toBeTrue()
})

it('should not compute x/y coordinates for blur record', () => {
a.blur()
expect(coordinatesComputed).toBeFalse()
})
})
})

0 comments on commit 178c0de

Please sign in to comment.