Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto committed Jun 27, 2015
1 parent 9e12033 commit e976e8b
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 86 deletions.
11 changes: 0 additions & 11 deletions examples/blog/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,6 @@
nga.field('created_at', 'date')
.label('Posted')
.attributes({'placeholder': 'Filter by date'}),
nga.field('today', 'boolean').map(function() {
var now = new Date(),
year = now.getFullYear(),
month = now.getMonth() + 1,
day = now.getDate();
month = month < 10 ? '0' + month : month;
day = day < 10 ? '0' + day : day;
return {
created_at: [year, month, day].join('-') // ?created_at=... will be appended to the API call
};
}),
nga.field('post_id', 'reference')
.label('Post')
.targetEntity(post)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"npm": "^2.10.0"
},
"devDependencies": {
"admin-config": "^0.2.1",
"admin-config": "^0.2.3",
"angular": "~1.3.15",
"angular-bootstrap": "^0.12.0",
"angular-mocks": "^1.3.15",
Expand Down Expand Up @@ -59,7 +59,7 @@
"jsonlint": "^1.6.2",
"karma": "~0.12.14",
"karma-babel-preprocessor": "^4.0.0",
"karma-chrome-launcher": "^0.1.4",
"karma-chrome-launcher": "^0.2.0",
"karma-jasmine": "~0.3.3",
"karma-ng-html2js-preprocessor": "~0.1.0",
"karma-ng-scenario": "~0.1.0",
Expand Down
200 changes: 129 additions & 71 deletions src/javascripts/test/e2e/filterViewSpec.js
Original file line number Diff line number Diff line change
@@ -1,99 +1,157 @@
/*global describe,it,expect,$$,element,browser,by*/
describe('Global filter', function () {
describe('List filter', function () {
'use strict';

var hasToLoad = true;
beforeEach(function() {
browser.get(browser.baseUrl + '#/comments/list');
if (hasToLoad) {
browser.get(browser.baseUrl + '#/comments/list');
}
hasToLoad = true;
});

it('should display filters uppon the listview', function () {
$$('.filters .filter input').then(function (inputs) {
expect(inputs.length).toBe(4); // 2 for text filters, 2 for ui-select filter

expect(inputs[0].getAttribute('placeholder')).toBe('Global Search');
expect(inputs[1].getAttribute('placeholder')).toBe('Filter by date');
describe('layout', function() {
it('should display pinned filters by default in the listview', function() {
$$('.filters .filter input').then(function(inputs) {
expect(inputs.length).toBe(1); // Only text filter is pinned
expect(inputs[0].getAttribute('placeholder')).toBe('Search');
});
hasToLoad = false;
});
it('should display a filter button for adding new filters', function() {
return $$('ma-view-actions button').then(function(buttons) {
expect(buttons[0].getText()).toBe(' Add filter');
});
});
});

it('should filter globally', function () {
// Filter globally for 'rabbit'
$$('.filters .filter:nth-child(1) input').sendKeys('rabbit');
$$('.filters button[type="submit"]').click();
$$('.grid tr td:nth-child(4)').then(function (tdElements) {
expect(tdElements.length).toBe(1);
expect(tdElements[0].getText()).toBe('White Rabbit: it was indeed: she was out of the gr...');
describe('filter button', function() {
it('should display a list of filters when clicked', function() {
element(by.css('ma-filter-button button')).click();
$$('ma-filter-button ul').then(function(element) {
expect(element[0].getCssValue('display')).toBe('block');
});
$$('ma-filter-button ul li').then(function(elements) {
expect(elements.length).toBe(2);
expect(elements[0].getText()).toBe('Posted');
expect(elements[1].getText()).toBe('Post');
});
hasToLoad = false;
});
});

it('should update the pagination total', function () {
// Filter globally for 'rabbit'
$$('.filters .filter:nth-child(1) input').sendKeys('rabbit');
$$('.filters button[type="submit"]').click();
$$('ma-datagrid-pagination .total').then(function (totalElements) {
expect(totalElements[0].getText()).toBe('1 - 1 on 1');
it('should add a filter when filter name is clicked', function() {
$$('ma-filter-button ul li:nth-child(1) a').click();
$$('.filters .filter input').then(function(inputs) {
expect(inputs.length).toBe(2);
expect(inputs[1].getAttribute('placeholder')).toBe('Filter by date');
});
hasToLoad = false;
});
it('should hide the list of filters once clicked', function() {
$$('ma-filter-button ul').then(function(element) {
expect(element[0].getCssValue('display')).toBe('none');
});
hasToLoad = false;
});
it('should reduce the number of filters in the dropdown once clicked', function() {
element(by.css('ma-filter-button button')).click();
$$('ma-filter-button ul').then(function(element) {
expect(element[0].getCssValue('display')).toBe('block');
});
$$('ma-filter-button ul li').then(function(elements) {
expect(elements.length).toBe(1);
expect(elements[0].getText()).toBe('Post');
});
hasToLoad = false;
});
it('should disappear if all filters were added', function() {
element(by.css('ma-filter-button ul li:nth-child(1) a')).click();
$$('.filters .filter input').then(function(inputs) {
expect(inputs.length).toBe(4); // Post is autocomplete, so it has 2 inputs
});
$$('ma-filter-button ul').then(function(elements) {
expect(elements.length).toBe(0);
});
hasToLoad = false;
});
it('should reappear once an unpinned filter is removed', function() {
element(by.css('.filters .filter:nth-child(3) .remove_filter a')).click();
$$('ma-filter-button ul').then(function(elements) {
expect(elements.length).not.toBe(0);
});
element(by.css('ma-filter-button button')).click();
$$('ma-filter-button ul li').then(function(elements) {
expect(elements.length).toBe(1);
expect(elements[0].getText()).toBe('Post');
});
});
});

it('should reset all filters', function () {
// Filter globally for 'rabbit'
$$('.filters .filter:nth-child(1) input').sendKeys('rabbit');
$$('.filters button[type="submit"]').click();

browser.wait(function () {
return $('.filters > button[type="button"]').isDisplayed().then(function (result) {
return result;
describe('text filter', function() {
it('should filter globally', function () {
// Filter globally for 'rabbit'
$$('.filters .filter:nth-child(1) input').sendKeys('rabbit');
$$('.grid tr td:nth-child(4)').then(function (tdElements) {
expect(tdElements.length).toBe(1);
expect(tdElements[0].getText()).toBe('White Rabbit: it was indeed: she was out of the gr...');
});
hasToLoad = false;
});
$('.filters > button[type="button"]').click();

$$('ma-datagrid-pagination .total').then(function (totalElements) {
expect(totalElements[0].getText()).toBe('1 - 10 on 11');
it('should update the pagination total', function () {
$$('ma-datagrid-pagination .total').then(function (totalElements) {
expect(totalElements[0].getText()).toBe('1 - 1 on 1');
});
hasToLoad = false;
});
});

it('should filter on reference', function () {
// Filter on post_id '3' (Perspiciatis adipisci vero qui ipsam iure porro)
element(by.css('.filters .ui-select-placeholder')).click();
element(by.css('.filters .ui-select-search')).sendKeys('Perspi');
element(by.css('#ui-select-choices-row-0-0')).click();

$$('.filters button[type="submit"]').click();
$$('.grid tr td:nth-child(4)').then(function (tdElements) {
expect(tdElements.length).toBe(2);
expect(tdElements[0].getText()).toBe('I\'d been the whiting,\' said the Hatter, it woke up...');
expect(tdElements[1].getText()).toBe('I\'m not Ada,\' she said, \'and see whether it\'s mark...');
it('should not filter when empty', function () {
$$('.filters .filter:nth-child(1) input').clear();
$$('.grid tr td:nth-child(4)').then(function (tdElements) {
expect(tdElements.length).toBe(10);
});
});
});

it('should update the pagination total', function () {
// Filter on post id '3' (Perspiciatis adipisci vero qui ipsam iure porro)
element(by.css('.filters .ui-select-placeholder')).click();
element(by.css('.filters .ui-select-search')).sendKeys('Perspi');
element(by.css('#ui-select-choices-row-0-0')).click();
describe('reference filter', function() {
it('should filter on reference', function () {
element(by.css('ma-filter-button button')).click();
$$('ma-filter-button ul li:nth-child(2) a').click();
// Filter on post_id '3' (Perspiciatis adipisci vero qui ipsam iure porro)
element(by.css('.filters .ui-select-placeholder')).click();
element(by.css('.filters .ui-select-search')).sendKeys('Perspi');
element(by.css('#ui-select-choices-row-0-0')).click();
$$('.grid tr td:nth-child(4)').then(function (tdElements) {
expect(tdElements.length).toBe(2);
expect(tdElements[0].getText()).toBe('I\'d been the whiting,\' said the Hatter, it woke up...');
expect(tdElements[1].getText()).toBe('I\'m not Ada,\' she said, \'and see whether it\'s mark...');
});
hasToLoad = false;
});

$$('.filters button[type="submit"]').click();
$$('ma-datagrid-pagination .total').then(function (totalElements) {
expect(totalElements[0].getText()).toBe('1 - 2 on 2');
it('should update the pagination total', function () {
$$('ma-datagrid-pagination .total').then(function (totalElements) {
expect(totalElements[0].getText()).toBe('1 - 2 on 2');
});
});
});

it('should reset page number', function () {
// Filter globally for 'I'
$$('.filters .filter:nth-child(1) input').sendKeys('I');
$$('.filters button[type="submit"]').click();
$$('ma-datagrid-pagination .total').then(function (totalElements) {
expect(totalElements[0].getText()).toBe('1 - 10 on 11');
});
$$('ma-datagrid-pagination li:nth-child(3) a').click();
$$('ma-datagrid-pagination .total').then(function (totalElements) {
expect(totalElements[0].getText()).toBe('11 - 11 on 11');
});
// Filter globally for 'be'
$$('.filters .filter:nth-child(1) input').clear();
$$('.filters .filter:nth-child(1) input').sendKeys('be');
$$('.filters button[type="submit"]').click();
$$('ma-datagrid-pagination .total').then(function (totalElements) {
expect(totalElements[0].getText()).toBe('1 - 5 on 5');
describe('interaction with pagination', function() {
it('should reset page number', function () {
// Filter globally for 'I'
$$('.filters .filter:nth-child(1) input').sendKeys('I');
$$('ma-datagrid-pagination .total').then(function (totalElements) {
expect(totalElements[0].getText()).toBe('1 - 10 on 11');
});
$$('ma-datagrid-pagination li:nth-child(3) a').click();
$$('ma-datagrid-pagination .total').then(function (totalElements) {
expect(totalElements[0].getText()).toBe('11 - 11 on 11');
});
// Filter globally for 'be'
$$('.filters .filter:nth-child(1) input').clear();
$$('.filters .filter:nth-child(1) input').sendKeys('be');
$$('ma-datagrid-pagination .total').then(function (totalElements) {
expect(totalElements[0].getText()).toBe('1 - 5 on 5');
});
});
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*global describe,it,expect,beforeEach*/
describe('controller: ma-datagrid', function () {
var DataGridController = require('../../../../ng-admin/Crud/list/DatagridController'),
var DataGridController = require('../../../../ng-admin/Crud/list/maDatagridController'),
Entity = require('admin-config/lib/Entity/Entity'),
Entry = require('admin-config/lib/Entry');

Expand Down
2 changes: 1 addition & 1 deletion src/javascripts/test/unit/Crud/list/maDatagridSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('directive: ma-datagrid', function () {
scope.$digest();

expect(element[0].querySelector('thead th:nth-child(2)').innerHTML).toContain('Actions');
expect(element[0].querySelector('tbody tr td:nth-child(2) list-actions').nodeName).toContain('LIST-ACTIONS');
expect(element[0].querySelector('tbody tr td:nth-child(2) ma-list-actions').nodeName).toContain('MA-LIST-ACTIONS');
});


Expand Down

0 comments on commit e976e8b

Please sign in to comment.