-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Replace jQuery with native API calls (#86)
* Remove jQuery from dev convenience utilities * Remove jquery and jquery types from dependencies * Removed jQuery from notification center panel * Removed jQuery from viewPort lib * Remove jQuery from ActiveRundownView * Removed jQuery from VideoEditMonitor * Removed jQuery from ClockView * Removed jQuery from PrompterView ** Replace references to removed method PrompterViewInner#getScrollPosition() with window.scrollY * Removed jQuery from RundownView * Removed jQuery from RundownFullscreenControls * Removed jQuery from SegmentTimeline renderers * Removed jQuery from SegmentTimeline * Removed jQuery from SegmentTimelineLine * Removed jQuery from SegmentTimelineZoomControls * Removed jQuery from SourceLayerItem * Removed jQuery from TimelineGrid * Removed jQuery from AdLibPanel * Removed jQuery from Shelf component * Removed jQuery entry from startup dependency omission list * getElementWidth util now replicates jQuery width() behavior * Remove jQuery from SegmentTimelineContainer * Implement client lib loadscript() without using jQuery
- Loading branch information
Showing
37 changed files
with
4,022 additions
and
3,620 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { getElementWidth, getElementHeight } from '../../utils/dimensions' | ||
import { createSandbox } from 'sinon' | ||
|
||
const sandbox = createSandbox() | ||
|
||
describe('client/utils/dimensions', () => { | ||
let getComputedStyle | ||
|
||
beforeEach(() => { | ||
getComputedStyle = sandbox.stub(window, 'getComputedStyle') | ||
}) | ||
|
||
afterEach(() => { | ||
sandbox.restore() | ||
}) | ||
|
||
describe('getElementWidth', () => { | ||
test('returns width from getComputedStyle when it has a numeric value', () => { | ||
const expected = 20; | ||
const element = document.createElement('div'); | ||
getComputedStyle.withArgs(element).returns({ width: expected }) | ||
|
||
const actual = getElementWidth(element) | ||
|
||
expect(actual).toEqual(expected) | ||
}) | ||
|
||
test('returns element.offsetWidth - computed horizontal padding when computed width is auto', () => { | ||
const paddingLeft = 10 | ||
const paddingRight = 15 | ||
const offsetWidth = 63 | ||
const expected = offsetWidth - paddingLeft - paddingRight | ||
|
||
const element = document.createElement('div'); | ||
Object.defineProperty(element, 'offsetWidth', { value: offsetWidth }) | ||
getComputedStyle.withArgs(element).returns({ width: 'auto', paddingLeft, paddingRight }) | ||
|
||
const actual = getElementWidth(element) | ||
|
||
expect(actual).toEqual(expected) | ||
}) | ||
}) | ||
|
||
describe('getElementHeight', () => { | ||
test('returns height from getComputedStyle when it has a numeric value', () => { | ||
const expected = 20; | ||
const element = document.createElement('div'); | ||
getComputedStyle.withArgs(element).returns({ height: expected }) | ||
|
||
const actual = getElementHeight(element) | ||
|
||
expect(actual).toEqual(expected) | ||
}) | ||
|
||
test('returns element.scrollHeight - computed vertical padding when computed height is auto', () => { | ||
const paddingTop = 8 | ||
const paddingBottom = 9 | ||
const scrollHeight = 37 | ||
const expected = scrollHeight - paddingTop - paddingBottom | ||
|
||
const element = document.createElement('div'); | ||
Object.defineProperty(element, 'scrollHeight', { value: scrollHeight }) | ||
getComputedStyle.withArgs(element).returns({ height: 'auto', paddingTop, paddingBottom }) | ||
|
||
const actual = getElementHeight(element) | ||
|
||
expect(actual).toEqual(expected) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { getElementDocumentOffset } from '../../utils/positions' | ||
|
||
describe('getElementDocumentOffset', () => { | ||
const emptyRect: ClientRect = { | ||
top: 0, | ||
left: 0, | ||
bottom: 0, | ||
right: 0, | ||
height: 0, | ||
width: 0 | ||
} | ||
|
||
test('should return null for null input', () => { | ||
const actual = getElementDocumentOffset(null) | ||
|
||
expect(actual).toBe(null) | ||
}) | ||
|
||
|
||
describe('{top}', () => { | ||
test('should be 0 when bounding client rect top is 0 and window.scrollY is 0', () => { | ||
Object.defineProperty(window, 'scrollY', { value: 0 }) | ||
const container = document.createElement('div'); | ||
container.getBoundingClientRect = (): ClientRect => { | ||
return Object.assign({}, emptyRect, { top: 0 }) | ||
} | ||
|
||
const actual = getElementDocumentOffset(container) | ||
|
||
expect(actual).toHaveProperty('top', 0) | ||
}) | ||
|
||
test('should be 20 when bounding client rect top is 20 and window.scrollY is 0', () => { | ||
Object.defineProperty(window, 'scrollY', { value: 0 }) | ||
const container = document.createElement('div'); | ||
container.getBoundingClientRect = (): ClientRect => { | ||
return Object.assign({}, emptyRect, { top: 20 }) | ||
} | ||
|
||
const actual = getElementDocumentOffset(container) | ||
|
||
expect(actual).toHaveProperty('top', 20) | ||
}) | ||
|
||
test('should be 31 when bounding client rect top is 10 and window.scrollY is 21', () => { | ||
Object.defineProperty(window, 'scrollY', { value: 21 }) | ||
const container = document.createElement('div'); | ||
container.getBoundingClientRect = (): ClientRect => { | ||
return Object.assign({}, emptyRect, { top: 10 }) | ||
} | ||
|
||
const actual = getElementDocumentOffset(container) | ||
|
||
expect(actual).toHaveProperty('top', 31) | ||
}) | ||
}) | ||
|
||
describe('{left}', () => { | ||
test('should be 0 when bounding client rect left is 0 and window.scrollX is 0', () => { | ||
Object.defineProperty(window, 'scrollY', { value: 0 }) | ||
const container = document.createElement('div'); | ||
container.getBoundingClientRect = (): ClientRect => { | ||
return Object.assign({}, emptyRect, { left: 0 }) | ||
} | ||
|
||
const actual = getElementDocumentOffset(container) | ||
|
||
expect(actual).toHaveProperty('left', 0) | ||
}) | ||
|
||
test('should be 18 when bounding client rect left is 18 and window.scrollX is 0', () => { | ||
Object.defineProperty(window, 'scrollX', { value: 0 }) | ||
const container = document.createElement('div'); | ||
container.getBoundingClientRect = (): ClientRect => { | ||
return Object.assign({}, emptyRect, { left: 18 }) | ||
} | ||
|
||
const actual = getElementDocumentOffset(container) | ||
|
||
expect(actual).toHaveProperty('left', 18) | ||
}) | ||
|
||
test('should be 42 when bounding client rect left is 2 and window.scrollX is 40', () => { | ||
Object.defineProperty(window, 'scrollX', { value: 40 }) | ||
const container = document.createElement('div'); | ||
container.getBoundingClientRect = (): ClientRect => { | ||
return Object.assign({}, emptyRect, { left: 2 }) | ||
} | ||
|
||
const actual = getElementDocumentOffset(container) | ||
|
||
expect(actual).toHaveProperty('left', 42) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.