This repository has been archived by the owner on Jul 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jeffrey Cherewaty
committed
Jul 3, 2019
1 parent
fbbebc4
commit d6e3f5f
Showing
6 changed files
with
78 additions
and
1 deletion.
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
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
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,27 @@ | ||
import { computed } from './helpers'; | ||
|
||
/** | ||
* Property creator for returning `true` or `false` when an element | ||
* should have focus. | ||
* | ||
* ``` html | ||
* <form> | ||
* <input type="email" id="email" /> | ||
* <input type="password" id="password" /> | ||
* </form> | ||
* ``` | ||
* | ||
* ``` javascript | ||
* new Interactor('#email').isFocused //=> true when email input focused | ||
* new Interactor('#password').isFocused //=> false when email input focused | ||
* ``` | ||
* | ||
* @function isFocused | ||
* @param {String} [selector] - Nested element query selector | ||
* @returns {Object} Property descriptor | ||
*/ | ||
export default function(selector) { | ||
return computed(function() { | ||
return this.$(selector) === document.activeElement; | ||
}); | ||
} |
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,8 @@ | ||
<div id="focus-form"> | ||
<label class="test-field"> | ||
<input type="email" id="email" autofocus /> | ||
</label> | ||
<label class="test-field"> | ||
<input type="password" id="password" /> | ||
</label> | ||
</div> |
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,38 @@ | ||
/* global describe, beforeEach, it */ | ||
import { expect } from 'chai'; | ||
import { useFixture } from '../helpers'; | ||
import { interactor, isFocused } from '../../src'; | ||
|
||
@interactor class FocusedInteractor { | ||
isEmailFocused = isFocused('#email'); | ||
isPasswordFocused = isFocused('#password'); | ||
} | ||
|
||
describe('BigTest Interaction: isFocused', () => { | ||
let test; | ||
|
||
useFixture('is-focused-fixture'); | ||
|
||
beforeEach(() => { | ||
test = new FocusedInteractor('#focus-form'); | ||
}); | ||
|
||
it('has isFocused properties', () => { | ||
expect(test).to.have.property('isFocused').that.is.a('boolean'); | ||
expect(test).to.have.property('isEmailFocused').that.is.a('boolean'); | ||
expect(test).to.have.property('isPasswordFocused').that.is.a('boolean'); | ||
}); | ||
|
||
it('returns true if the element is focused', () => { | ||
expect(test.isFocused).to.be.false; | ||
expect(test.isEmailFocused).to.be.true; | ||
expect(test.isPasswordFocused).to.be.true; | ||
}); | ||
|
||
it('returns false if the element is not focused', () => { | ||
test.focus('#password'); | ||
expect(test.isFocused).to.be.false; | ||
expect(test.isEmailFocused).to.be.false; | ||
expect(test.isPasswordFocused).to.be.true; | ||
}); | ||
}); |