In my Ember Application you can add, edit and delete events and todos and connect the todos with the events. The backend is a rails application. For testing I use Mirage. The models in Mirage have following relationships:
//Mirage event
import { belongsTo, hasMany, Model } from 'ember-cli-mirage';
export default Model.extend({
user: belongsTo('user'),
todos: hasMany('todo')
});
//Mirage todo
import { belongsTo, Model } from 'ember-cli-mirage';
export default Model.extend({
user: belongsTo('user'),
event: belongsTo('event')
});
In my acceptance test I create a user with an event and some todos connected with the event and the user. I visit the events page and click on the created event. You can select all todos connected with the event to delete them too. But in this case I just want to delete the event without the connected todos. Than I start the delete request by confirming.
//acceptance test events-test.js
test('delete event without todo', function(assert) {
const user = server.create('user'),
event = server.create('event', {
user
}),
todos = server.createList('todo', 4, { user, event });
authenticateSession(this.application, {
id: user.id,
token: user.token
});
visit('/events');
andThen(function() {
assert.equal(find('td.fc-event-container').length, 5, 'There should be exactly one Event and four Todo');
assert.equal(currentURL(), '/events', 'currentURL should be /events');
click(find('td.fc-event-container a').eq(0));
andThen(function() {
click('button.delete');
andThen(function() {
click('button.confirm');
andThen(function() {
assert.equal(find('td.fc-event-container').length, 4, 'There should be exactly zero Events but four Todo');
assert.equal(currentURL(), '/events', 'currentURL should be /events');
});
});
});
});
});
The delete route in the config.js:
//Mirage config.js
this.del('/events/:id');
In productive code everything works fine. But in the test the created event has zero todos as relations and after confirming it deletes the event and exactly one todo. error message
Aucun commentaire:
Enregistrer un commentaire