Last active
September 14, 2016 16:40
-
-
Save magistrula/c3f8cb00b0e216673a68c4028809b467 to your computer and use it in GitHub Desktop.
Wrapper & Container Component Testing
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
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
// required params | |
person: null, | |
actions: { | |
onSnooze() { | |
this.set('person.isAwake', false); | |
}, | |
onWake() { | |
this.set('person.isAwake', true); | |
} | |
} | |
}); |
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
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
// required params | |
isAwake: null, | |
onWake: null, | |
onSleep: null | |
}); |
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
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
// required params | |
person: null | |
}); |
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
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Wrapper & Container Components' | |
}); |
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
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
return Ember.Object.create({ | |
name: 'Harry Potter', | |
isAwake: false | |
}) | |
} | |
}); |
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
import Ember from 'ember'; | |
export default function destroyApp(application) { | |
Ember.run(application, 'destroy'); | |
} |
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
import Resolver from '../../resolver'; | |
import config from '../../config/environment'; | |
const resolver = Resolver.create(); | |
resolver.namespace = { | |
modulePrefix: config.modulePrefix, | |
podModulePrefix: config.podModulePrefix | |
}; | |
export default resolver; |
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
import Ember from 'ember'; | |
import Application from '../../app'; | |
import config from '../../config/environment'; | |
const { run } = Ember; | |
const assign = Ember.assign || Ember.merge; | |
export default function startApp(attrs) { | |
let application; | |
let attributes = assign({rootElement: "#test-root"}, config.APP); | |
attributes = assign(attributes, attrs); // use defaults, but you can override; | |
run(() => { | |
application = Application.create(attributes); | |
application.setupForTesting(); | |
application.injectTestHelpers(); | |
}); | |
return application; | |
} |
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
import { moduleForComponent, test } from 'ember-qunit'; | |
import hbs from 'htmlbars-inline-precompile'; | |
moduleForComponent('my-wrapper', 'TODO: put something here', { | |
integration: true | |
}); | |
test('reflects initial wake status when person.isAwake is false', function(assert) { | |
this.set('person', Ember.Object.create({ | |
name: 'Person', | |
isAwake: false | |
})); | |
this.render(hbs`{{my-wrapper person=person}}`); | |
assert.equal(this.$('[data-test-awake-status]').text().trim(), 'zzzzzz'); | |
assert.ok(this.$('[data-test-wake]').is(':visible')); | |
assert.notOk(this.$('[data-test-sleep]').is(':visible')); | |
}); | |
test('reflects initial wake status when person.isAwake is true', function(assert) { | |
this.set('person', Ember.Object.create({ | |
name: 'Person', | |
isAwake: true | |
})); | |
this.render(hbs`{{my-wrapper person=person}}`); | |
assert.equal(this.$('[data-test-awake-status]').text().trim(), 'Person is awake'); | |
assert.ok(this.$('[data-test-sleep]').is(':visible')); | |
assert.notOk(this.$('[data-test-wake]').is(':visible')); | |
}); | |
test('it can wake me up', function(assert) { | |
this.set('person', Ember.Object.create({ | |
name: 'Person', | |
isAwake: false | |
})); | |
this.render(hbs`{{my-wrapper person=person}}`); | |
this.$('[data-test-wake]').click(); | |
assert.equal(this.$('[data-test-awake-status]').text().trim(), 'Person is awake'); | |
assert.ok(this.$('[data-test-sleep]').is(':visible')); | |
assert.notOk(this.$('[data-test-wake]').is(':visible')); | |
}); | |
test('it can put me to sleep', function(assert) { | |
this.set('person', Ember.Object.create({ | |
name: 'Person', | |
isAwake: true | |
})); | |
this.render(hbs`{{my-wrapper person=person}}`); | |
this.$('[data-test-sleep]').click(); | |
assert.equal(this.$('[data-test-awake-status]').text().trim(), 'zzzzzz'); | |
assert.ok(this.$('[data-test-wake]').is(':visible')); | |
assert.notOk(this.$('[data-test-sleep]').is(':visible')); | |
}); |
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
import resolver from './helpers/resolver'; | |
import { | |
setResolver | |
} from 'ember-qunit'; | |
setResolver(resolver); |
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
{ | |
"version": "0.10.5", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": true | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.8.0", | |
"ember-data": "2.8.0", | |
"ember-template-compiler": "2.8.0", | |
"ember-testing": "2.8.0" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment