Skip to content

Commit

Permalink
Merge pull request #503 from marmelab/fix_batch_delete
Browse files Browse the repository at this point in the history
[RFR] fix back method on batchDeleteController
  • Loading branch information
jeromemacias committed Jun 10, 2015
2 parents cd5b9af + d7594da commit 4dfe7f5
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ define(function () {
BatchDeleteController.prototype.back = function () {

this.$state.go(this.$state.get('list'), angular.extend({
entity: this.entity().name()
entity: this.entity.name()
}, this.$state.params));
};

Expand Down
83 changes: 74 additions & 9 deletions src/javascripts/test/e2e/ListViewSpec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*global xdescribe,xit,expect,$$,element,browser,by*/
xdescribe('ListView', function () {
/*global describe,it,expect,$$,element,browser,by*/
describe('ListView', function () {
'use strict';

beforeEach(function () {
browser.get(browser.baseUrl + '#/posts/list');
});

xdescribe('Edition link', function () {
xit('should allow edition of an entity', function () {
describe('Edition link', function () {
it('should allow edition of an entity', function () {
// Retrieve first edit button
$('table tr:nth-child(1) ma-edit-button a').click();

Expand All @@ -18,8 +18,8 @@ xdescribe('ListView', function () {
});
});

xdescribe('Show link', function () {
xit('should allow display of an entity', function () {
describe('Show link', function () {
it('should allow display of an entity', function () {
// Retrieve first edit button
$('table tr:nth-child(1) ma-show-button a').click();

Expand All @@ -30,15 +30,15 @@ xdescribe('ListView', function () {
});
});

xdescribe('ma-list-button', function () {
describe('ma-list-button', function () {
var listUrl;

beforeEach(function() {
listUrl = encodeURI(browser.baseUrl + '/#/comments/list?search={"post_id":"9"}&page=1');
browser.get(listUrl);
});

xit('should restore the list with filter when used from edit', function () {
it('should restore the list with filter when used from edit', function () {
browser.executeScript('window.scrollTo(810, 481)').then(function () {
$$('ma-edit-button a').then(function (elements) {
expect(elements[0].getText()).toBe(' Edit');
Expand All @@ -52,7 +52,7 @@ xdescribe('ListView', function () {
});
});

xit('should restore the list with filter when used from delete', function () {
it('should restore the list with filter when used from delete', function () {
browser.get(listUrl);
browser.executeScript('window.scrollTo(810, 481)').then(function () {

Expand All @@ -73,4 +73,69 @@ xdescribe('ListView', function () {
});
});
});

function selectItemAndGoToBatchDelete() {
return $$('ma-view-batch-actions button')
.then(function (elements) {
expect(elements.length).toBe(0);
return $$('ma-datagrid-item-selector');
})
.then(function (elements) {
// expect(elements.length).toBe(numComments);
elements[0].click();

return $$('ma-view-batch-actions button');
})
.then(function (elements) {
expect(elements.length).toBe(1);
elements[0].click();
return $$('ma-batch-delete-button');
})
.then(function (elements) {
expect(elements.length).toBe(1);
elements[0].click();
expect(browser.getCurrentUrl()).toMatch(browser.baseUrl + '/#/comments/batch-delete/');

return $$('button');
});
}

describe('ma-batch-delete-button', function () {
it('should show the batch delete button only when at least one line is selected', function () {
browser.get('/#/comments/list');
var numComments;
$$('tbody tr').then(function (elements) {
numComments = elements.length;
return selectItemAndGoToBatchDelete();
})
.then(function (elements) {
expect(elements[1].getText()).toBe('No');
elements[1].click();
expect(browser.getCurrentUrl()).toMatch(browser.baseUrl + '/#/comments/list');
return $$('tbody tr');
})
.then(function (elements) {
expect(elements.length).toBe(numComments);
});
});

// @TODO allow to delete item without broking other test
xit('should show the batch delete button only when at least one line is selected', function () {
browser.get('/#/comments/list');
var numComments;
$$('tbody tr').then(function (elements) {
numComments = elements.length;
return selectItemAndGoToBatchDelete();
})
.then(function (elements) {
expect(elements[0].getText()).toBe('Yes');
elements[0].click();
expect(browser.getCurrentUrl()).toMatch(browser.baseUrl + '/#/comments/list');
return $$('tbody tr');
})
.then(function (elements) {
expect(elements.length).toBe(numComments - 1);
});
});
});
});

0 comments on commit 4dfe7f5

Please sign in to comment.