-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(all): add some more tests (#10)
- Loading branch information
1 parent
e5c0c26
commit a7746ae
Showing
5 changed files
with
128 additions
and
0 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,21 @@ | ||
import {containsOrAfter} from '../contains-or-after'; | ||
|
||
describe('containsOrAfter', () => { | ||
it('Parent contains child', () => { | ||
const parent = document.createElement('div'); | ||
const child = document.createElement('button'); | ||
|
||
parent.appendChild(child); | ||
|
||
expect(containsOrAfter(parent, child)).toEqual(true); | ||
}); | ||
|
||
it('Child does not contain parent', () => { | ||
const parent = document.createElement('div'); | ||
const child = document.createElement('button'); | ||
|
||
parent.appendChild(child); | ||
|
||
expect(containsOrAfter(child, parent)).toEqual(false); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
projects/cdk/utils/dom/test/get-clipboard-data-text.spec.ts
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,26 @@ | ||
import {getClipboardDataText} from '../get-clipboard-data-text'; | ||
|
||
describe('getClipboardDataText', () => { | ||
it('ClipboardData in event', () => { | ||
const data = 'copy!'; | ||
const clipboardData = new DataTransfer(); | ||
|
||
clipboardData.setData('text/plain', data); | ||
|
||
const event = new ClipboardEvent('copy', {clipboardData: clipboardData} as any); | ||
|
||
expect(getClipboardDataText(event)).toEqual(data); | ||
}); | ||
|
||
it('ClipboardData not in event', () => { | ||
const event = new Event('copy') as any; | ||
|
||
Object.defineProperty(event, 'target', { | ||
value: { | ||
ownerDocument: {defaultView: {clipboardData: {getData: () => 'data'}}}, | ||
}, | ||
}); | ||
|
||
expect(getClipboardDataText(event)).toEqual('data'); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
projects/cdk/utils/dom/test/get-document-or-shadow-root.spec.ts
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,21 @@ | ||
import {getDocumentOrShadowRoot} from '../get-document-or-shadow-root'; | ||
|
||
describe('getDocumentOrShadowRoot', () => { | ||
it('Node not in body', () => { | ||
const element = document.createElement('div'); | ||
|
||
expect(getDocumentOrShadowRoot(element)).toEqual( | ||
element.ownerDocument as Document, | ||
); | ||
}); | ||
|
||
it('Node in body', () => { | ||
const element = document.createElement('div'); | ||
|
||
document.body.appendChild(element); | ||
|
||
expect(getDocumentOrShadowRoot(element)).toEqual( | ||
element.getRootNode() as Document, | ||
); | ||
}); | ||
}); |
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,20 @@ | ||
import {getElementOffset} from '../get-element-offset'; | ||
|
||
describe('getElementOfset', () => { | ||
it('should return offsets', () => { | ||
const grandParent = document.createElement('div'); | ||
const parent = document.createElement('div'); | ||
const child = document.createElement('button'); | ||
|
||
grandParent.appendChild(parent); | ||
parent.appendChild(child); | ||
|
||
Object.defineProperty(child, 'offsetParent', {value: parent}); | ||
Object.defineProperty(parent, 'offsetParent', {value: grandParent}); | ||
|
||
expect(getElementOffset(grandParent, child)).toEqual({ | ||
offsetTop: 0, | ||
offsetLeft: 0, | ||
}); | ||
}); | ||
}); |
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,40 @@ | ||
import {getScrollParent} from '../get-scrollable-parent'; | ||
|
||
describe('getScrollableParent', () => { | ||
it('There is no element', () => { | ||
expect(getScrollParent(null)).toEqual(null); | ||
}); | ||
|
||
it('Should return element. Vertical is true', () => { | ||
const element = document.createElement('div'); | ||
|
||
Object.defineProperty(element, 'scrollHeight', {value: 5}); | ||
Object.defineProperty(element, 'clientHeight', {value: 0}); | ||
|
||
expect(getScrollParent(element)).toEqual(element); | ||
}); | ||
|
||
it('Should return element. Vertical is false', () => { | ||
const element = document.createElement('div'); | ||
|
||
Object.defineProperty(element, 'scrollWidth', {value: 5}); | ||
Object.defineProperty(element, 'clientWidth', {value: 0}); | ||
|
||
expect(getScrollParent(element, false)).toEqual(element); | ||
}); | ||
|
||
it('Shoul return parent element', () => { | ||
const parentElement = document.createElement('div'); | ||
const childElement = document.createElement('div'); | ||
|
||
parentElement.appendChild(childElement); | ||
|
||
Object.defineProperty(childElement, 'scrollWidth', {value: 0}); | ||
Object.defineProperty(childElement, 'clientWidth', {value: 5}); | ||
|
||
Object.defineProperty(parentElement, 'scrollWidth', {value: 5}); | ||
Object.defineProperty(parentElement, 'clientWidth', {value: 0}); | ||
|
||
expect(getScrollParent(childElement, false)).toEqual(parentElement); | ||
}); | ||
}); |