-
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
Conversation
} else { | ||
let testsContainer = this.testContext ? | ||
this.testContext._element : | ||
'#ember-testing'; |
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 is definitely not the best thing to be hard-coded
guardMultiple(result, selector, options.multiple); | ||
|
||
return result; | ||
}, | ||
|
||
$(selector, container) { |
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.
copied from integration context https://github.com/san650/ember-cli-page-object/pull/325/files#diff-401dad0d4f56e66a450e3abf76d4ef5cR66
Actually |
Seems like |
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.
Hey @ro0gr, great that you have started working on this. I have not so many comments about the implementation details, mainly because I am not that familiar with the code base. But I will write some other thoughts down later...
triggerEvent(selector, container, 'input'); | ||
triggerEvent(selector, container, 'change'); | ||
triggerEvent($selection, 'input'); | ||
triggerEvent($selection, 'change'); |
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.
Can't we simply use the built-in fillIn
helper of e-n-d-h here?
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.
Ah, just saw your other comment, so ignore this...
index.js
Outdated
@@ -11,6 +11,9 @@ module.exports = { | |||
enabled: this._shouldIncludeFiles(), | |||
import: ['index.js'] | |||
}; | |||
}, | |||
jquery: { | |||
import: ['dist/jquery.js'], |
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.
What happens here when your app has not opted out of using jQuery? Do we then bundle jQuery twice?
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 needs to be verified.
Anyways seems like it's not a big deal cause it's for testing only.
Also this way we can guarantee that we don't consume jquery from ember
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.
I've just used this branch on a project with jquery@1.11.3
included. As a result both jquery
versions are bundled into vendor.js
.
The interesting thing is that 1.11.3
is still used by ember
and v3.2.1
by e-c-p-o
so their are no in conflict.
upd: tested in addon with ember originated from bower
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.
all the jquery plugins should be included before e-c-p-o
. Otherwise they will extend e-c-p-o
's jquery instead of Ember.$
:/
IIUC you have jQuery still around as a compatibility layer for jQuery-specific selectors like
This way
What's your thoughts on this? @ro0gr @san650 cc @cibernox interested in chiming in here? |
@simonihmig thank you for your thoughts.
Yes. I think all the specific selectors can be found in Selector class
Unfortunately I think it's impossible right now. Lots of
|
I agree with @simonihmig that leaving classical contexts untouched is a good thing. So I've reverted all the changes in classic contexts with global ember helpers. In order to enable // tests/test-helper.js
...
import { useNativeDOMHelpers } from 'ember-cli-page-object/extend';
useNativeDOMHelpers(); // this will replace classic contexts with `e-n-d-h` Currently it doesn't accept any args.
I've thought about build time config for this. But I think this way it will be harder to test all the contexts inside a single |
Let's assume the following:
As a result I've ended up in similar situation. truly isolate jquery tries to address this issue by calling |
5cf776c
to
7fdb8aa
Compare
- use own jquery
7fdb8aa
to
50d8d33
Compare
beforeEach() { | ||
this.adapter = new AcceptanceAdapter(AcceptanceExecutionContext); | ||
}, | ||
[true, false].forEach(_useNativeDOMHelpers => { |
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.
I'm not a big fan of this. But it gives us an ability to test native-dom-helpers
almost for free. So we can use existing test suite as a baseline.
I have few ideas on how to improve testing story, but I prefer to leave it for a separate issue/pr.
index.js
Outdated
@@ -23,6 +30,11 @@ module.exports = { | |||
|
|||
this.app = app; | |||
|
|||
if (this._shouldIncludeFiles()) { | |||
this.import('vendor/shims/-jquery.js', { prepend: true }); | |||
this.import('vendor/ecpo-jquery/dist/jquery.js', { prepend: true }); |
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.
ensure shims goes right after our private jquery
instance
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.
Should we put a comment here indicating that this ordering is important for shims/-jquery
to work? The comment in shims/-jquery
is really helpful, and I think the assumption we're making there about ordering will be more secure if there is also a warning here, where that ordering is defined.
vendor/shims/-jquery.js
Outdated
@@ -0,0 +1,11 @@ | |||
(function() { | |||
var jq = self['$'].noConflict(); |
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.
here we heavily rely on the assumption that we included jquery right a before this script
https://github.com/san650/ember-cli-page-object/pull/325/files#diff-168726dbe96b3ce427e7fedce31bb0bcR35
this way noConflict
gives us our jquery instance and disposes it from the window
.
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.
I think I'll inline some comments in code a little bit later
@@ -33,7 +33,9 @@ IntegrationExecutionContext.prototype = { | |||
}, | |||
|
|||
// Do nothing in integration test | |||
visit: $.noop, | |||
visit() { | |||
throw new Error('visit is not supported in integration mode'); |
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.
should I rollback this?
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.
I like this. If someone calls visit
in an integration test, they'll get some feedback that will help them learn more about how to use ember-cli-page-object
. I wonder...what happens if you set the context in an integration test and then forget to remove it? Is it possible that we would end up seeing this message in an acceptance test due to improper cleanup of an integration test? If so, then the error message should probably address this. Suggest using throwBetterError
for consistency with error messaging elsewhere.
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.
I've tried to use throwBetterError
here. Unfortunately it doesn't work out of the box because throwBetterError
is currently coupled exlusively to element find failures.
This pr is already quite large. I've reverted original silent behavior.
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.
For future reference, here's an example of where throwBetterError
is used outside the context of element find failures: https://github.com/san650/ember-cli-page-object/blob/master/addon/-private/properties/alias.js#L86.
Currently all the I'm sure the issue originated from |
@@ -33,7 +33,9 @@ IntegrationExecutionContext.prototype = { | |||
}, | |||
|
|||
// Do nothing in integration test | |||
visit: $.noop, | |||
visit() { | |||
throw new Error('visit is not supported in integration mode'); |
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.
I like this. If someone calls visit
in an integration test, they'll get some feedback that will help them learn more about how to use ember-cli-page-object
. I wonder...what happens if you set the context in an integration test and then forget to remove it? Is it possible that we would end up seeing this message in an acceptance test due to improper cleanup of an integration test? If so, then the error message should probably address this. Suggest using throwBetterError
for consistency with error messaging elsewhere.
@@ -0,0 +1,131 @@ | |||
import $ from '-jquery'; |
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.
Would it be more appropriate to call this file native-context.js
?
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.
yes I also thought about it.
Actually I like dom-context
more. native
sounds misleading to me a little bit. Maybe native-dom-context
is more appropriate here?
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.
native-dom-context
sounds good to me!
throw new Error('not implemented'); | ||
}, | ||
|
||
// Do nothing in integration test |
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.
I think this comment might be left over from an earlier copy/paste?
return $(selector, container); | ||
} else { | ||
let testsContainer = this.testContext ? | ||
this.testContext._element : |
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.
Would be nice not to have to use the private _element
property, and it looks like there's support in the community for making element
part of the public API. Suggest adding a TODO comment with a link to this issue so that we can update this once that issue is handled.
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.
#ember-testing
one line above also doesn't look very nice.
}, | ||
|
||
fillIn(selector, container, options, content) { | ||
let el = this.$(selector, container)[0]; |
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.
Since we are selecting only the first matched element here, what would happen if someone called fillIn
in a situation where { multiple: true }
is present? What do we gain from passing an element into fillElement
instead of a jQuery selection?
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.
I've never used fillIn
with { multiple: true }
:)
I'll update it. thanks.
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.
According to fillable
API docs there is no support for multiple
option. Does fillable
intend to support this option?
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're right that it's not called out in the docs, but fillable
does work with { multiple: true }
, so it's probably safest to preserve that functionality at this point.
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.
OK, will do. Thx
addon/extend.js
Outdated
import IntegrationNativeContext from './-private/execution_context/integration-native'; | ||
import AcceptanceNativeContext from './-private/execution_context/acceptance-native'; | ||
import IntegrationClassicContext from './-private/execution_context/integration'; | ||
import AcceptanceClassicContext from './-private/execution_context/acceptance'; |
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.
I like the idea of contrasting naming like Native
vs Classic
. Suggest IntegrationJQueryContext
and AcceptanceJQueryContext
to increase clarity. Might even be good to rename execution_context/integration
and execution_context/acceptance
to execution-context/integration-jquery
and execution-context/acceptance-jquery
.
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.
Suggest
IntegrationJQueryContext
andAcceptanceJQueryContext
to increase clarity.
Currently all the 4 actual contexts use jquery
to find elements.I'd suggest to rename all the contexts. I like your idea to rename existing contexts.
How about?
acceptance-ember-context
,integration-ember-context
acceptance-native-dom-context
integration-native-dom-context
It seem too verbose to me. But I'm ok with it.
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.
How about acceptance-jquery-event-context
, acceptance-native-event-context
, etc? And then, native-event-context
instead for context.js
above? If the file names are too long, we could add acceptance
and integration
folders, each of which could include native-event-context
and jquery-event-context
.
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.
How about acceptance-jquery-event-context
- i'm not sure why do you refer to
event
, triggering of events is only a part of context jquery
is not dedicated only for existing contexts. All of contexts(includingnative-dom
) use jquery to find elements to find DOM elements. More details here
native-event-context instead for context.js above?
yes, sure. Hovewer I think we agreed on native-dom-context
name
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.
It seems that the core difference between these contexts is the way in which the events are triggered, so that's why I'm suggesting filenames with event
in them as well as native-event-context
instead of native-dom-context
. Not a big deal either way...just pondering how to achieve the most clarity.
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.
Now I see your point about events. However acceptance-jquery-event-context
is still not explanatory enough cause it also uses global ember test helpers(find
, click
).
I also agree with you that it's not a big deal cause it's not a part of public API.
I think it might be better not too touch exiting context names at all until a better name eventually comes to us :)
hm.., I've just checked IE and all the tests started to pass(even in IE9 emulation mode) after I'm not sure if we want to fix issues in |
I think the best way to avoid issue with |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Todo:
- Update function signature of
fillElement
to indicate that the first param is an element - Update the usage of
fillElement
in the other places where it is used so that we are always passing an element and not a jQuery selection.
index.js
Outdated
@@ -23,6 +30,11 @@ module.exports = { | |||
|
|||
this.app = app; | |||
|
|||
if (this._shouldIncludeFiles()) { | |||
this.import('vendor/shims/-jquery.js', { prepend: true }); | |||
this.import('vendor/ecpo-jquery/dist/jquery.js', { prepend: true }); |
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.
Should we put a comment here indicating that this ordering is important for shims/-jquery
to work? The comment in shims/-jquery
is really helpful, and I think the assumption we're making there about ordering will be more secure if there is also a warning here, where that ordering is defined.
I tried this branch locally to see if it would work (we use native dom events so this is going to be necessary for us) and I'm getting |
@pzuraq thank you for report. I've tested it against ember-cli@2.12 and 2.16 and haven't noticed such issue yet. I'll test it with 2.12. However some more additional details would be helpful:
Thanks |
|
}; | ||
|
||
AcceptanceExecutionContext.prototype.runAsync = function(cb) { | ||
window.wait().then(() => { |
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 thing ember-native-dom-helpers
does here to make this completely independent:
import wait from 'ember-test-helpers/wait';
(window.wait || wait)().then(() => {});
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.
@pzuraq I've updated handling of jquery per you suggestion in slack. |
superseded by #339 |
addresses #311
reviewers @san650 @simonihmig
ember-native-dom
context allows not to rely on global ember test helpers(click
,fillIn
,..).We still use
jquery
due to custom selectors capabilities(:is
,:contains
etc)In order to allow ember application not to use
jquery
while keeping a backward compatibilityember-cli-page-object
now bundles its own jquery copy namespaced as'-jquery'
.To enable native dom helpers in your tests, put this lines into your
tests/test-helper.js
:Tests
I've expanded property tests with [native-dom] mode for both integration and acceptance contexts. It seems a little not optimal however it gives a solid code coverage with a minimal efforts.
Todo
we use a vendor shim to isolate jQuery from the app's one.
endh
keyEvent
keypress key vs keyCode inconsistency across browsers cibernox/ember-native-dom-helpers#112usebetterError
in integration contextvisit
. by @magistrula