-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate ember-native-dom-helpers #325
Closed
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
afab45e
move to dom-native-helpers
ro0gr 715c2dd
unify elements search
ro0gr 9455cce
unify contexts
ro0gr 5e8b1f2
add useNativeDOMHelpers
ro0gr 6a22b55
trigger first selected element
ab28fab
conditional jquery import
f3b8748
prepend jquery
ro0gr b0fabcb
truly isolate jquery
ro0gr 6e3b06d
bump ember-cli-node-assets
ro0gr 2f35680
work-around deprecated keyCode property of KeyboardEvent
ro0gr 144c4fe
add native-context to acceptance tests
ro0gr 16fd45b
update tests to work with native-dom-helpers
ro0gr 50d8d33
don't destruct jquery collection
ro0gr 01d28c6
isolate jquery truly truly
ro0gr a56074e
rename contexts from native to native-dom
ro0gr f158437
Delete global jQuery reference
ro0gr 56efa22
properly handle ember-native-dom keyEvent
ro0gr 1eaafc7
do nothing on visit in integration contexts
ro0gr 11dded4
add support for multiple fillIn
ro0gr 253f2d1
split jquery shim into global and amd steps
ro0gr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import ExecutionContext from './native-dom-context'; | ||
|
||
import { | ||
visit | ||
} from 'ember-native-dom-helpers'; | ||
|
||
export default function AcceptanceExecutionContext(pageObjectNode) { | ||
ExecutionContext.call(this, pageObjectNode); | ||
} | ||
|
||
AcceptanceExecutionContext.prototype = Object.create(ExecutionContext.prototype); | ||
|
||
AcceptanceExecutionContext.prototype.visit = function() { | ||
return visit(...arguments); | ||
}; | ||
|
||
AcceptanceExecutionContext.prototype.runAsync = function(cb) { | ||
window.wait().then(() => { | ||
cb(this); | ||
}); | ||
|
||
return this.pageObjectNode; | ||
}; |
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
20 changes: 20 additions & 0 deletions
20
addon/-private/execution_context/integration-native-dom.js
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 ExecutionContext from './native-dom-context'; | ||
|
||
import Ember from 'ember'; | ||
const { run } = Ember; | ||
|
||
export default function IntegrationExecutionContext(pageObjectNode, testContext) { | ||
ExecutionContext.call(this, pageObjectNode, testContext); | ||
} | ||
|
||
IntegrationExecutionContext.prototype = Object.create(ExecutionContext.prototype); | ||
|
||
IntegrationExecutionContext.prototype.visit = function() {}; | ||
|
||
IntegrationExecutionContext.prototype.runAsync = function(cb) { | ||
run(() => { | ||
cb(this); | ||
}); | ||
|
||
return this.pageObjectNode; | ||
}; |
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,138 @@ | ||
import $ from '-jquery'; | ||
|
||
import { | ||
click, | ||
triggerEvent, | ||
keyEvent | ||
} from 'ember-native-dom-helpers'; | ||
|
||
import { | ||
guardMultiple, | ||
buildSelector, | ||
findClosestValue | ||
} from '../helpers'; | ||
import { | ||
fillElement | ||
} from './helpers'; | ||
import { | ||
ELEMENT_NOT_FOUND, | ||
throwBetterError | ||
} from '../better-errors'; | ||
|
||
const KEYBOARD_EVENT_TYPES = ['keydown', 'keypress', 'keyup']; | ||
|
||
export default function ExecutionContext(pageObjectNode, testContext) { | ||
this.pageObjectNode = pageObjectNode; | ||
this.testContext = testContext; | ||
} | ||
|
||
ExecutionContext.prototype = { | ||
run(cb) { | ||
return cb(this); | ||
}, | ||
|
||
runAsync() { | ||
throw new Error('not implemented'); | ||
}, | ||
|
||
click(selector, container) { | ||
const el = this.$(selector, container)[0]; | ||
click(el); | ||
}, | ||
|
||
fillIn(selector, container, options, content) { | ||
let elements = this.$(selector, container).toArray(); | ||
|
||
elements.forEach((el) => { | ||
fillElement(el, content, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Todo:
|
||
selector, | ||
pageObjectNode: this.pageObjectNode, | ||
pageObjectKey: options.pageObjectKey | ||
}); | ||
|
||
triggerEvent(el, 'input'); | ||
triggerEvent(el, 'change'); | ||
}); | ||
}, | ||
|
||
$(selector, container) { | ||
if (container) { | ||
return $(selector, container); | ||
} else { | ||
// @todo: we should fixed usage of private `_element` | ||
// after https://github.com/emberjs/ember-test-helpers/issues/184 is resolved | ||
let testsContainer = this.testContext ? | ||
this.testContext._element : | ||
'#ember-testing'; | ||
|
||
return $(selector, testsContainer); | ||
} | ||
}, | ||
|
||
triggerEvent(selector, container, eventName, eventOptions) { | ||
const element = this.$(selector, container)[0]; | ||
|
||
// `keyCode` is a deprecated property. | ||
// @see: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode | ||
// Due to this deprecation `ember-native-dom-helpers` doesn't accept `keyCode` as a `KeyboardEvent` option. | ||
if (typeof eventOptions.key === 'undefined' && typeof eventOptions.keyCode !== 'undefined') { | ||
eventOptions.key = eventOptions.keyCode.toString(); | ||
delete eventOptions.keyCode; | ||
} | ||
|
||
if (KEYBOARD_EVENT_TYPES.indexOf(eventName) > -1) { | ||
keyEvent(element, eventName, eventOptions.key, eventOptions); | ||
} else { | ||
triggerEvent(element, eventName, eventOptions); | ||
} | ||
}, | ||
|
||
assertElementExists(selector, options) { | ||
let container = options.testContainer || findClosestValue(this.pageObjectNode, 'testContainer'); | ||
|
||
let result = this.$(selector, container); | ||
|
||
if (result.length === 0) { | ||
throwBetterError( | ||
this.pageObjectNode, | ||
options.pageObjectKey, | ||
ELEMENT_NOT_FOUND, | ||
{ selector } | ||
); | ||
} | ||
}, | ||
|
||
find(selector, options) { | ||
let container = options.testContainer || findClosestValue(this.pageObjectNode, 'testContainer'); | ||
|
||
selector = buildSelector(this.pageObjectNode, selector, options); | ||
|
||
let result = this.$(selector, container); | ||
|
||
guardMultiple(result, selector, options.multiple); | ||
|
||
return result; | ||
}, | ||
|
||
findWithAssert(selector, options) { | ||
let container = options.testContainer || findClosestValue(this.pageObjectNode, 'testContainer'); | ||
|
||
selector = buildSelector(this.pageObjectNode, selector, options); | ||
|
||
let result = this.$(selector, container); | ||
|
||
if (result.length === 0) { | ||
throwBetterError( | ||
this.pageObjectNode, | ||
options.pageObjectKey, | ||
ELEMENT_NOT_FOUND, | ||
{ selector } | ||
); | ||
} | ||
|
||
guardMultiple(result, selector, options.multiple); | ||
|
||
return result; | ||
} | ||
}; | ||
|
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 |
---|---|---|
@@ -1,4 +1,21 @@ | ||
export { findElement } from './-private/extend/find-element'; | ||
export { findElementWithAssert } from './-private/extend/find-element-with-assert'; | ||
export { buildSelector, getContext, fullScope } from './-private/helpers'; | ||
export { register as registerExecutionContext } from './-private/execution_context'; | ||
import { register as registerExecutionContext } from './-private/execution_context'; | ||
|
||
import IntegrationNativeDOMContext from './-private/execution_context/integration-native-dom'; | ||
import AcceptanceNativeDOMContext from './-private/execution_context/acceptance-native-dom'; | ||
import IntegrationEmberContext from './-private/execution_context/integration'; | ||
import AcceptanceEmberContext from './-private/execution_context/acceptance'; | ||
|
||
function useNativeDOMHelpers(flag = true) { | ||
if (flag) { | ||
registerExecutionContext('integration', IntegrationNativeDOMContext); | ||
registerExecutionContext('acceptance', AcceptanceNativeDOMContext); | ||
} else { | ||
registerExecutionContext('integration', IntegrationEmberContext); | ||
registerExecutionContext('acceptance', AcceptanceEmberContext); | ||
} | ||
} | ||
|
||
export { registerExecutionContext, useNativeDOMHelpers }; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to be the last dependency on a global test helper, which means we still have to use
setContext
to be able to use PageObjects in integration tests. We can do the same thingember-native-dom-helpers
does here to make this completely independent:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right , seems like it should be fixed.