-
Notifications
You must be signed in to change notification settings - Fork 154
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
Component unit test example #20
Merged
lukemelia
merged 5 commits into
yapplabs:master
from
varblob:component_unit_test_example
May 5, 2015
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b39842f
adding to dummy app a component that uses a modal dialog with test
30fefb3
add a comment to mention why Ember.$ is used vs just this.$
849be7a
update the readme to include a not on unit testing
88d58ea
make url to component-unit test relative
df6da1b
component folder should be components
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
13 changes: 13 additions & 0 deletions
13
tests/dummy/app/components/component-that-uses-modal-dialog.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,13 @@ | ||
import Ember from 'ember'; | ||
|
||
export default Ember.Component.extend({ | ||
isShowingModalDialog: false, | ||
actions: { | ||
openModalDialog: function(){ | ||
this.set('isShowingModalDialog', true); | ||
}, | ||
closeModalDialog: function(){ | ||
this.set('isShowingModalDialog', false); | ||
} | ||
} | ||
}); |
9 changes: 9 additions & 0 deletions
9
tests/dummy/app/templates/components/component-that-uses-modal-dialog.hbs
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,9 @@ | ||
{{#if isShowingModalDialog}} | ||
{{#modal-dialog}} | ||
<h1>Stop! Modal Time!</h1> | ||
<button class="close" {{action 'closeModalDialog'}}>Close</button> | ||
{{/modal-dialog}} | ||
{{/if}} | ||
|
||
<h1>A component that has a modal dialog</h1> | ||
<button class="open" {{action 'openModalDialog'}}>Open Dialog</button> |
44 changes: 44 additions & 0 deletions
44
tests/unit/component/component-that-uses-modal-dialog-test.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,44 @@ | ||
import { test, moduleForComponent } from 'ember-qunit'; | ||
/* global Ember */ | ||
|
||
moduleForComponent('component-that-uses-modal-dialog', { | ||
/* | ||
* Setting up the container for the modal dialog to wormhole into and | ||
* injecting the id of that element into the modal-dialog component | ||
*/ | ||
beforeEach: function(){ | ||
var modalContainerEl = document.createElement("div"); | ||
modalContainerEl.id = 'modal-overlays'; | ||
var rootEl = document.querySelector("#ember-testing"); | ||
rootEl.appendChild(modalContainerEl); | ||
this.container.register('config:modals-container-id', 'modal-overlays', {instantiate: false}); | ||
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. during migration ember app from 1.13 to 2.13 found unit test with similar code. it was probably copied from related discussion. could you please provide details is this test code still relevant and how I can do that in Ember 2.0 |
||
this.container.injection('component:modal-dialog', 'destinationElementId', 'config:modals-container-id'); | ||
}, | ||
needs: [ | ||
'component:modal-dialog', | ||
'component:ember-modal-dialog-positioned-container', | ||
'component:ember-wormhole' | ||
] | ||
}); | ||
|
||
test("it doesn't show component on start", function(assert){ | ||
assert.expect(1); | ||
|
||
var component = this.subject(); | ||
// render the component | ||
this.$(); | ||
|
||
// cannot use this.$ because the modal-dialog exists outside of the component | ||
assert.equal(Ember.$('.ember-modal-dialog').length, 0); | ||
}); | ||
|
||
test('it shows component when open modal clicked', function(assert){ | ||
assert.expect(1); | ||
|
||
var component = this.subject(); | ||
|
||
this.$('button.open').click(); | ||
|
||
// cannot use this.$ because the modal-dialog exists outside of the component | ||
assert.equal(Ember.$('.ember-modal-dialog').length, 1); | ||
}); |
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.
It would be nice to use a relative link here that will work on all branches.
Looks really good overall.. thanks!