-
Notifications
You must be signed in to change notification settings - Fork 405
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 tests * chore(all): add some tests Co-authored-by: Vladimir <v.potekhin@tinkoff.ru>
- Loading branch information
1 parent
9b1043b
commit e5c0c26
Showing
5 changed files
with
96 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 {getActualTarget} from '../get-actual-target'; | ||
|
||
describe('isCurrentTarget', () => { | ||
it('Actual target from composedPath', () => { | ||
const event = new MouseEvent('click'); | ||
const target = document.createElement('button'); | ||
|
||
Object.defineProperty(event, 'composedPath', {value: () => [target]}); | ||
|
||
expect(getActualTarget(event)).toEqual(target); | ||
}); | ||
|
||
it('Actual target is event.target', () => { | ||
const target = document.createElement('button'); | ||
const event = {target: target} as any; | ||
|
||
Object.defineProperty(event, 'target', {value: target}); | ||
|
||
expect(getActualTarget(event as Event)).toEqual(target); | ||
}); | ||
}); |
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,12 @@ | ||
import {isCurrentTarget} from '../is-current-target'; | ||
|
||
describe('isCurrentTarget', () => { | ||
it('Target is equal to currentTarget', () => { | ||
const event = new MouseEvent('click'); | ||
|
||
Object.defineProperty(event, 'target', {value: '<button>'}); | ||
Object.defineProperty(event, 'currentTarget', {value: '<button>'}); | ||
|
||
expect(isCurrentTarget(event)).toEqual(true); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
projects/cdk/utils/focus/tests/is-native-focused-in.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,15 @@ | ||
import {isNativeFocusedIn} from '../is-native-focused-in'; | ||
|
||
describe('isNativeFocusedIn', () => { | ||
it('element is not focused in', () => { | ||
const element = document.createElement('buton'); | ||
|
||
expect(isNativeFocusedIn(element)).toEqual(false); | ||
}); | ||
|
||
it('should return false if ownerDocument is null', () => { | ||
const element = {ownerDocument: null} as Node; | ||
|
||
expect(isNativeFocusedIn(element)).toEqual(false); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
projects/cdk/utils/focus/tests/is-native-mouse-focusable.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,31 @@ | ||
import {isNativeMouseFocusable} from '../is-native-mouse-focusable'; | ||
|
||
describe('isNativeMouseFocusable', () => { | ||
it('DIV is not mouse focusable', () => { | ||
const element = document.createElement('div'); | ||
|
||
expect(isNativeMouseFocusable(element)).toEqual(false); | ||
}); | ||
|
||
it('BUTTON is mouse focusable', () => { | ||
const element = document.createElement('button'); | ||
|
||
expect(isNativeMouseFocusable(element)).toEqual(true); | ||
}); | ||
|
||
it('disabled BUTTON is not mouse focusable', () => { | ||
const element = document.createElement('button'); | ||
|
||
element.setAttribute('disabled', ''); | ||
|
||
expect(isNativeMouseFocusable(element)).toEqual(false); | ||
}); | ||
|
||
it('BUTTON with tabIndex === -1 is not mouse focusable', () => { | ||
const element = document.createElement('button'); | ||
|
||
element.setAttribute('disabled', ''); | ||
|
||
expect(isNativeMouseFocusable(element)).toEqual(false); | ||
}); | ||
}); |
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,17 @@ | ||
import {moveFocus} from '../move-focus'; | ||
|
||
describe('move focus', () => { | ||
it(' ', () => { | ||
const first = document.createElement('button'); | ||
const second = document.createElement('textarea'); | ||
|
||
document.body.appendChild(first); | ||
document.body.appendChild(second); | ||
|
||
const arr = [first, second]; | ||
|
||
moveFocus(0, arr, 1); | ||
|
||
expect(document.activeElement).toEqual(second); | ||
}); | ||
}); |