123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- /**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- var App = require('app');
- require('utils/db');
- require('views/common/filter_view');
- require('views/common/sort_view');
- require('mixins');
- require('mixins/common/userPref');
- require('views/common/table_view');
- describe('App.TableView', function () {
- var view;
- beforeEach(function() {
- App.db.cleanUp();
- });
- afterEach(function() {
- App.db.cleanUp();
- });
- describe('#init', function() {
- it('should set filterConditions on instance', function() {
- var tableView = App.TableView.create();
- expect(tableView.get('filterConditions') === App.TableView.prototype.filterConditions).to.be.false;
- });
- });
- describe('#updatePaging', function() {
- beforeEach(function() {
- view = App.TableView.create(App.UserPref, {
- controller: Em.Object.create({}),
- displayLength: 10,
- startIndex: 1,
- content: d3.range(1, 100),
- filteredContent: d3.range(1, 100),
- filtersUsedCalc: function() {},
- filter: function() {}
- });
- view.clearFilters();
- view.updateFilter();
- });
- it('should set "startIndex" to 0 if "filteredContent" is empty', function() {
- view.set('filteredContent', []);
- expect(view.get('startIndex')).to.equal(0);
- });
- it('should set "startIndex" to 1 if "filteredContent" is not empty', function() {
- view.set('filteredContent', d3.range(1, 10));
- expect(view.get('startIndex')).to.equal(1);
- });
- });
- describe('#endIndex', function() {
- beforeEach(function() {
- view = App.TableView.create(App.UserPref, {
- controller: Em.Object.create({}),
- displayLength: 10,
- startIndex: 1,
- content: d3.range(1, 100),
- filteredContent: d3.range(1, 100),
- filtersUsedCalc: function() {},
- filter: function() {}
- });
- view.clearFilters();
- view.updateFilter();
- });
- it('should be recalculated if "startIndex" was changed', function() {
- view.set('startIndex', 2);
- expect(view.get('endIndex')).to.equal(11);
- });
- it('should be recalculated if "displayLength" was changed', function() {
- view.set('displayLength', 5);
- expect(view.get('endIndex')).to.equal(5);
- });
- it('should be recalculated (but not changed) if "filteredContent" was changed (and "filterContent.length" is more than "startIndex + displayLength")', function() {
- var endIndexBefore = view.get('endIndex');
- view.set('filteredContent', d3.range(2,100));
- expect(view.get('endIndex')).to.equal(endIndexBefore);
- });
- it('should be recalculated (and changed) if "filteredContent" was changed (and "filterContent.length" is less than "startIndex + displayLength")', function() {
- var endIndexBefore = view.get('endIndex');
- var indx = 4;
- view.set('filteredContent', d3.range(1,indx));
- expect(view.get('endIndex')).to.not.equal(endIndexBefore);
- expect(view.get('endIndex')).to.equal(indx - 1);
- });
- });
- describe('#pageContent', function() {
- beforeEach(function() {
- view = App.TableView.create(App.UserPref, {
- controller: Em.Object.create({}),
- displayLength: 10,
- startIndex: 1,
- content: d3.range(1, 100),
- filteredContent: d3.range(1, 100),
- endIndex: 10,
- filtersUsedCalc: function() {},
- filter: function() {}
- });
- view.clearFilters();
- view.updateFilter();
- });
- it('should be recalculated if "startIndex" was changed', function() {
- view.set('startIndex', 2);
- expect(view.get('pageContent').length).to.equal(9);
- });
- it('should be recalculated if "endIndex" was changed', function() {
- view.set('endIndex', 5);
- expect(view.get('pageContent').length).to.equal(5);
- });
- it('should be recalculated if "filteredContent" was changed', function() {
- var pageContentBefore = view.get('pageContent');
- view.set('filteredContent', d3.range(2,100));
- expect(view.get('pageContent').length).to.equal(pageContentBefore.length);
- expect(view.get('pageContent')).to.not.eql(pageContentBefore);
- });
- });
- describe('#clearFilters', function() {
- it('should set "filterConditions" to empty array', function() {
- view.clearFilters();
- expect(view.get('filterConditions')).to.eql([]);
- });
- });
- describe('#filtersUsedCalc', function() {
- beforeEach(function() {
- view = App.TableView.create(App.UserPref, {
- controller: Em.Object.create({}),
- displayLength: 10,
- startIndex: 1,
- content: d3.range(1, 100),
- filteredContent: d3.range(1, 100),
- endIndex: 10,
- filter: function() {}
- });
- });
- it('should set "filtersUsed" to false if "filterConditions" is empty array', function() {
- view.set('filterConditions', []);
- view.filtersUsedCalc();
- expect(view.get('filtersUsed')).to.equal(false);
- });
- it('should set "filtersUsed" to false if each value in "filterConditions" is empty', function() {
- view.set('filterConditions', [{value:''}, {value:''}]);
- view.filtersUsedCalc();
- expect(view.get('filtersUsed')).to.equal(false);
- });
- it('should set "filtersUsed" to true if one or more values in "filterConditions" are not empty', function() {
- view.set('filterConditions', [{value:''}, {value:'lol'}]);
- view.filtersUsedCalc();
- expect(view.get('filtersUsed')).to.equal(true);
- });
- });
- describe('#nextPage', function() {
- beforeEach(function() {
- view = App.TableView.create(App.UserPref, {
- controller: Em.Object.create({}),
- displayLength: 10,
- startIndex: 1,
- content: d3.range(1, 100),
- filteredContent: d3.range(1, 100),
- endIndex: 10,
- filter: function() {}
- });
- });
- it('should set "startIndex" if "filteredContent.length is greater than "startIndex" + "displayLength"', function() {
- var oldStartIndex = view.get('startIndex');
- var displayLength = 50;
- view.set('displayLength', displayLength);
- view.nextPage();
- expect(view.get('startIndex')).to.equal(oldStartIndex + displayLength);
- });
- it('should not set "startIndex" if "filteredContent.length is equal to "startIndex" + "displayLength"', function() {
- var oldStartIndex = view.get('startIndex');
- var displayLength = 99;
- view.set('displayLength', displayLength);
- view.nextPage();
- expect(view.get('startIndex')).to.equal(oldStartIndex);
- });
- it('should not set "startIndex" if "filteredContent.length is less than "startIndex" + "displayLength"', function() {
- var oldStartIndex = view.get('startIndex');
- var displayLength = 100;
- view.set('displayLength', displayLength);
- view.nextPage();
- expect(view.get('startIndex')).to.equal(oldStartIndex);
- });
- });
- describe('#previousPage', function() {
- beforeEach(function() {
- view = App.TableView.create(App.UserPref, {
- controller: Em.Object.create({}),
- displayLength: 10,
- startIndex: 50,
- content: d3.range(1, 100),
- filteredContent: d3.range(1, 100),
- endIndex: 60,
- filter: function() {}
- });
- });
- it('should set "startIndex" to 1', function() {
- var displayLength = 50;
- view.set('displayLength', displayLength);
- view.previousPage();
- expect(view.get('startIndex')).to.equal(1);
- });
- it('should not set "startIndex" to 40', function() {
- view.set('startIndex', 50);
- var displayLength = 10;
- view.set('displayLength', displayLength);
- view.previousPage();
- expect(view.get('startIndex')).to.equal(40);
- });
- });
- describe("#showFilteredContent", function() {
- beforeEach(function() {
- view = App.TableView.create({});
- });
- it('hide clear filters link', function () {
- view.set('filterConditions', []);
- expect(view.get('showFilteredContent')).to.be.false;
- });
- it('shows clear filters link', function () {
- view.set('filterConditions', [{value: "1"}]);
- expect(view.get('showFilteredContent')).to.be.true;
- });
- it('shows clear filters link for array filter', function () {
- view.set('filterConditions', [{value: ["1", "2"]}]);
- expect(view.get('showFilteredContent')).to.be.true;
- });
- });
- describe('#filter', function () {
- var cases = [
- {
- filterConditions: [
- {
- iColumn: 1,
- type: 'string',
- value: 'v0'
- }
- ],
- content: [
- Em.Object.create({
- c0: 'v0'
- }),
- Em.Object.create({
- c1: 'v1'
- })
- ],
- filteredContent: [],
- title: 'no matches'
- },
- {
- filterConditions: [
- {
- iColumn: 0,
- type: 'string',
- value: 'v1'
- }
- ],
- content: [
- Em.Object.create({
- c0: 'v1'
- }),
- Em.Object.create({
- c0: 'v11'
- }),
- Em.Object.create({
- c1: 'v01'
- })
- ],
- filteredContent: [
- Em.Object.create({
- c0: 'v1'
- }),
- Em.Object.create({
- c0: 'v11'
- })
- ],
- title: 'matches present'
- },
- {
- filterConditions: [],
- content: [
- Em.Object.create({
- c0: 'v0'
- }),
- Em.Object.create({
- c1: 'v1'
- })
- ],
- filteredContent: [
- Em.Object.create({
- c0: 'v0'
- }),
- Em.Object.create({
- c1: 'v1'
- })
- ],
- title: 'no filter conditions'
- },
- {
- filterConditions: [],
- filteredContent: [],
- title: 'no filter conditions, no content'
- }
- ];
- beforeEach(function () {
- view = App.TableView.create({
- colPropAssoc: ['c0', 'c1']
- });
- });
- cases.forEach(function (item) {
- it(item.title, function () {
- view.setProperties({
- filterConditions: item.filterConditions,
- content: item.content
- });
- view.filter();
- expect(view.get('filteredContent')).to.eql(item.filteredContent);
- });
- });
- });
- });
|