forked from ichord/At.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ichord#301 from XrXr/remoteFilter-callback-timing
Make handling of resolution of remoteFilter more robust under various timings
- Loading branch information
Showing
5 changed files
with
124 additions
and
11 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,88 @@ | ||
describe "custom callbacks", -> | ||
$inputor = null | ||
|
||
beforeEach -> | ||
loadFixtures("inputors.html") | ||
afterEach -> | ||
$inputor.atwho 'destroy' | ||
|
||
describe "remoteFilter()", -> | ||
it "only renders the view for data from the latest lookup", -> | ||
callbackList = [] | ||
|
||
remoteFilter = jasmine.createSpy("remoteFilter").and.callFake (_, cb) -> | ||
callbackList.push cb | ||
|
||
$inputor = $("#inputor").atwho({ | ||
at: "@", | ||
data: [], | ||
callbacks: { | ||
remoteFilter | ||
} | ||
}) | ||
$inputor.val('@foo') | ||
|
||
app = getAppOf $inputor | ||
controller = app.controller() | ||
spyOn(controller, 'renderView') | ||
|
||
simulateTypingIn $inputor | ||
expect(remoteFilter).toHaveBeenCalled() | ||
simulateTypingIn $inputor | ||
expect(callbackList.length).toBeGreaterThan(1) | ||
while callbackList.length > 1 | ||
callbackList.shift()(['no renders']) | ||
expect(controller.renderView).not.toHaveBeenCalled() | ||
|
||
callbackList.shift()(['render']) | ||
expect(controller.renderView).toHaveBeenCalled() | ||
|
||
it "does not attempt to render the view after query has been cleared", -> | ||
remoteFilterCb = null | ||
|
||
remoteFilter = jasmine.createSpy("remoteFilter").and.callFake (_, cb) -> | ||
remoteFilterCb = cb | ||
|
||
$inputor = $("#inputor").atwho({ | ||
at: "@", | ||
data: [], | ||
callbacks: { | ||
remoteFilter | ||
} | ||
}) | ||
|
||
app = getAppOf $inputor | ||
controller = app.controller() | ||
spyOn controller, 'renderView' | ||
|
||
simulateTypingIn $inputor | ||
expect(remoteFilter).toHaveBeenCalled() | ||
$inputor.val '' | ||
simulateTypingIn $inputor | ||
expect(remoteFilter.calls.count()).toEqual(1) | ||
remoteFilterCb ['should not render'] | ||
expect(controller.renderView).not.toHaveBeenCalled() | ||
|
||
it "does not attempt to render the view after focus has been lost", -> | ||
remoteFilterCb = null | ||
|
||
remoteFilter = jasmine.createSpy("remoteFilter").and.callFake (_, cb) -> | ||
remoteFilterCb = cb | ||
|
||
$inputor = $("#inputor").atwho({ | ||
at: "@", | ||
data: [], | ||
callbacks: { | ||
remoteFilter | ||
} | ||
}) | ||
|
||
app = getAppOf $inputor | ||
controller = app.controller() | ||
spyOn controller, 'renderView' | ||
|
||
simulateTypingIn $inputor | ||
expect(remoteFilter).toHaveBeenCalled() | ||
$inputor.blur(); | ||
remoteFilterCb ['should not render'] | ||
expect(controller.renderView).not.toHaveBeenCalled() |
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