Last active
January 4, 2016 19:59
-
-
Save Bestra/d60e2e995c3b8775fb4a to your computer and use it in GitHub Desktop.
Component Integration Test blog post snippets
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
export default Ember.Component.extend({ | |
user: null, | |
actions: { | |
createVacation(startDate, endDate) { | |
this.store.createRecord('vacation', {user: this.get('user'), startDate, endDate}); | |
} | |
} | |
}); |
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(params) { | |
return this.store.peekRecord('user', params.id); | |
} | |
}); |
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'; | |
import Ember from 'ember'; | |
moduleForComponent('user/vacation-list', 'Integration | Component | user/vacation list', { | |
integration: true | |
}); | |
test('it renders', function(assert) { | |
// Set any properties with this.set('myProperty', 'value'); | |
// Handle any actions with this.on('myAction', function(val) { ... });" + EOL + EOL + | |
let testUser = Ember.Object.create({ | |
fullName: "Bruce Wayne", | |
}); | |
this.on('stubCreate', function() { return null; }); | |
this.set('userToTest', testUser); | |
this.render(hbs`{{user/vacation-list user=userToTest create=(action 'stubCreate')}}`); | |
let text = this.$().text(); | |
assert.ok(text.match(/Vacation Time for Bruce Wayne/)); | |
}); |
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
let userWithoutVacations = (container) => { | |
const store = container.lookup('service:store'); | |
let testUser = Ember.run(() => { | |
return store.createRecord('user', { | |
firstName: "Bruce", | |
lastName: "Wayne" | |
}); | |
}); | |
return testUser; | |
}; | |
let setDates = function(start, end) { | |
this.$("[data-test-id='date-pickers'] input:first").val(start).change(); | |
this.$("[data-test-id='date-pickers'] input:last").val(end).change(); | |
}; | |
test('it updates the new vacation length', function(assert) { | |
this.on('stubCreate', function() { return null; }); | |
this.set('userToTest', userWithoutVacations(this.container)); | |
this.render(hbs`{{user/vacation-list user=userToTest create=(action 'stubCreate')}}`); | |
setDates.call(this, '2015-02-01', '2015-02-04'); | |
assert.equal(this.$("[data-test-id='vacation-length']").text(), "3"); | |
}); |
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
test('the Create button invokes the "create" action with start and end date', function(assert) { | |
assert.expect(2); | |
this.on('stubCreate', function(start, end) { | |
let fmt = 'YYYY-MM-DD'; | |
assert.equal(start.format(fmt), '2015-02-01'); | |
assert.equal(end.format(fmt), '2015-02-03'); | |
}); | |
this.set('userToTest', userWithoutVacations(this.container)); | |
this.render(hbs`{{user/vacation-list user=userToTest create=(action 'stubCreate')}}`); | |
setDates.call(this, '2015-02-01', '2015-02-03'); | |
this.$('button:first').click(); | |
}); |
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 DS from 'ember-data'; | |
export default DS.Model.extend({ | |
firstName: DS.attr('string'), | |
lastName: DS.attr('string') | |
}) |
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({ | |
auth: Ember.inject.service() | |
}) |
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({ | |
auth: Ember.inject.service(), | |
actions: { | |
createVacation(user, startDate, endDate) { | |
return this.store.createRecord('vacation', {user, startDate, endDate}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment