File: dt-zero_config.test.js

package info (click to toggle)
datatables.js 1.10.13%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,232 kB
  • ctags: 1,329
  • sloc: xml: 10,249; php: 4,387; sh: 492; makefile: 21
file content (260 lines) | stat: -rw-r--r-- 12,001 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
describe( "Basic Datatables Test", function() {
	dt.libs( {
		js:  [ 'jquery', 'datatables' ],
		css: [ 'datatables' ]
	} );



  doc = window.document;


  describe('Sanity Checks for Datatables with DOM data', function(){
    dt.html( 'basic' ); //Reload basic.html
    it('jQuery.dataTable function', function(){
      expect(jQuery().dataTable).toEqual(jasmine.any(Function));
    });
    it('jQuery.dataTableSettings storage array', function(){
      expect(jQuery().dataTableSettings).toEqual(jasmine.any(Object));
    });
    it('jQuery.dataTableExt Plugin Object', function(){
      expect(jQuery().dataTableExt).toEqual(jasmine.any(Object));
    });
  }); // End Sanity Checks




  describe('Basic checks', function(){
    dt.html( 'basic' ); //Reload basic.html
    it('Length changing div exists', function(){
      $('#example').DataTable();
      expect(doc.getElementById('example_length')).not.toBeNull();
    });

    it("Filtering div exists", function () {
      expect(doc.getElementById('example_filter')).not.toBeNull();
    });
    it("Information div exists", function () {
      expect(doc.getElementById('example_info')).not.toBeNull();
    });
    it("Pagination div exists", function () {
      expect(doc.getElementById('example_paginate')).not.toBeNull();
    });
    it("Processing div exists", function () {
      expect(doc.getElementById('example_processing')).toBeNull();
    });
    it("10 rows shown on the first page", function () {
      expect($('#example tbody tr').length == 10).toBeTruthy();
    });
    it("Initial sort occured //todo make sure this is correct", function () {
      expect($('#example tbody td:eq(0)').html() == "Airi Satou").toBeTruthy();
    });
    it("Sorting (first click) on second column", function () {
      $('#example thead th:eq(1)').click();
      expect($('#example tbody td:eq(1)').html() == "Accountant").toBeTruthy();
    });
    it("Sorting (second click) on second column", function () {
      $('#example thead th:eq(1)').click();
      expect($('#example tbody td:eq(1)').html() == "Technical Author").toBeTruthy();
    });
    it("Sorting (third click) on second column //todo", function () {
      // $('#example thead th:eq(1)').click();
      // $('#example thead th:eq(1)').click();
      // expect($('#example tbody td:eq(1)').html() == "Technical Author").toBeTruthy();
    });

    it("Sorting (first click) on numeric column", function () {
      $('#example thead th:eq(3)').click();
      expect($('#example tbody td:eq(3)').html() == "19").toBeTruthy();
    });
    it("Sorting (second click) on numeric column", function () {
      $('#example thead th:eq(3)').click();
      expect($('#example tbody td:eq(3)').html() == "66").toBeTruthy();
    });


    dt.html( 'basic' );
    it("Sorting multi-column (first click)", function () {
      $('#example').DataTable();
      $('#example thead th:eq(3)').click();
      $('#example thead th:eq(3)').click();
      var clickEvent = $.Event('click');
      clickEvent.shiftKey = true;
      $('#example thead th:eq(5)').trigger(clickEvent);

      expect($('#example tbody td:eq(5)').html() == "$86,000").toBeTruthy();
      expect($('#example tbody td:eq(3)').html() == "66").toBeTruthy();
    });
    dt.html( 'basic' ); //Reload basic.html

  }); //End Basic Tests


  describe("Changing Length", function () {
    dt.html( 'basic' ); //Reload basic.html
    it("Changing table length to 25 records", function () {
      $('#example').DataTable();
      $('select[name=example_length]').val('25').change();
      expect($('#example tbody tr').length == 25).toBeTruthy();
    });

    it("Changing table length to 50 records", function () {
      $('select[name=example_length]').val('50').change();
      expect($('#example tbody tr').length == 50).toBeTruthy();
    });
    it("Changing table length to 100 records", function () {
      $('select[name=example_length]').val('100').change();
      expect($('#example tbody tr').length == 57).toBeTruthy();
    });
    it("Changing table length to 10 records from 50 records", function () {
      $('select[name=example_length]').val('10').change();
      expect($('#example tbody tr').length == 10).toBeTruthy();
    });
  }); //End Changing length tests

  describe("Information element", function () {
    dt.html( 'basic' ); //Reload basic.html

    it("Information on zero config", function () {
      $('#example').DataTable();
      expect(doc.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries").toBeTruthy();
    });
    it("Information on second page", function () {
      $('#example_next').click();
      expect(doc.getElementById('example_info').innerHTML == "Showing 11 to 20 of 57 entries").toBeTruthy();
    });
    it("Information on third page", function () {
      $('#example_next').click();
      expect(doc.getElementById('example_info').innerHTML == "Showing 21 to 30 of 57 entries").toBeTruthy();
    });
    it("Information on last page", function () {
      $('#example_next').click();
      $('#example_next').click();
      $('#example_next').click();
      expect(doc.getElementById('example_info').innerHTML == "Showing 51 to 57 of 57 entries").toBeTruthy();
    });
    it("Information back on first page", function () {
      $('#example_previous').click();
      $('#example_previous').click();
      $('#example_previous').click();
      $('#example_previous').click();
      $('#example_previous').click();
      expect(doc.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries").toBeTruthy();
    });
    it("Information with 25 records", function () {
      $('select[name=example_length]').val('25').change();
      expect(doc.getElementById('example_info').innerHTML == "Showing 1 to 25 of 57 entries").toBeTruthy();
    });
    it("Information with 25 records- second page", function () {
      $('#example_next').click();
      expect(doc.getElementById('example_info').innerHTML == "Showing 26 to 50 of 57 entries").toBeTruthy();
    });
    it("Information with 100 records", function () {
      $('select[name=example_length]').val('100').change();
      expect(doc.getElementById('example_info').innerHTML == "Showing 1 to 57 of 57 entries").toBeTruthy();
    });
    it("Information back to 10 records", function () {
      $('select[name=example_length]').val('10').change();
      $('#example_previous').click();
      expect(doc.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries").toBeTruthy();
    });
    it("Information with filter 'London'", function () {
      $('#example_filter input').val("London").keyup();
      expect(doc.getElementById('example_info').innerHTML == "Showing 1 to 10 of 12 entries (filtered from 57 total entries)").toBeTruthy();
    });
    it("Information with filter 'London'- second page", function () {
      $('#example_next').click();
      expect(doc.getElementById('example_info').innerHTML == "Showing 11 to 12 of 12 entries (filtered from 57 total entries)").toBeTruthy();
    });
    it("Information with filter 'London' back to first page", function () {
      $('#example_previous').click();
      expect(doc.getElementById('example_info').innerHTML == "Showing 1 to 10 of 12 entries (filtered from 57 total entries)").toBeTruthy();
    });
    it("Information with filter 'London'- second page- second time", function () {
      $('#example_next').click();
      expect(doc.getElementById('example_info').innerHTML == "Showing 11 to 12 of 12 entries (filtered from 57 total entries)").toBeTruthy();
    });
    it("Information with filter increased to 'London 66'", function () {
      $('#example_filter input').val("London 66").keyup();
      expect(doc.getElementById('example_info').innerHTML == "Showing 1 to 1 of 1 entries (filtered from 57 total entries)").toBeTruthy();
    });
    it("Information with filter decreased to 'London'", function () {
      $('#example_filter input').val("London").keyup();
      expect(doc.getElementById('example_info').innerHTML == "Showing 1 to 10 of 12 entries (filtered from 57 total entries)").toBeTruthy();
    });
    it("Information with filter 'London'- second page- third time", function () {
      $('#example_next').click();
      expect(doc.getElementById('example_info').innerHTML == "Showing 11 to 12 of 12 entries (filtered from 57 total entries)").toBeTruthy();
    });
    it("Information with filter removed", function () {
      $('#example_filter input').val("").keyup();
      expect(doc.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries").toBeTruthy();
    });
  });


  describe("Filtering", function () {
    dt.html( 'basic' );
    it("Filter 'W'- rows", function () {
      $('#example').dataTable();
      $('#example_filter input').val("W").keyup();
      expect($('#example tbody tr:eq(0) td:eq(0)').html() == "Bradley Greer").toBeTruthy();
    });
    it("Filter 'W'- info", function () {
      expect(doc.getElementById('example_info').innerHTML == "Showing 1 to 10 of 20 entries (filtered from 57 total entries)").toBeTruthy();
    });
    it("Filter 'Lon'", function () {
      $('#example_filter input').val("Lon").keyup();
      expect(doc.getElementById('example_info').innerHTML == "Showing 1 to 10 of 12 entries (filtered from 57 total entries)").toBeTruthy();
    });
    it("Filter 'Lon'- sorting column 1", function () {
      $('#example thead th:eq(1)').click();
      expect($('#example tbody tr:eq(0) td:eq(1)').html() == "Chief Executive Officer (CEO)").toBeTruthy();
    });
    it("Filter 'Lon'- sorting column 1 reverse", function () {
      $('#example thead th:eq(1)').click();
      expect($('#example tbody tr:eq(0) td:eq(1)').html() == "Technical Author").toBeTruthy();
    });
    it("Filter 'London'- sorting column 1 reverse", function () {
      $('#example_filter input').val("London").keyup();
      expect($('#example tbody tr:eq(0) td:eq(1)').html() == "Technical Author").toBeTruthy();
    });
    it("Filter 'London'- sorting column 3", function () {
      $('#example thead th:eq(3)').click();
      expect($('#example tbody tr:eq(0) td:eq(3)').html() == "19").toBeTruthy();
    });
    it("Filter 'London'- sorting column 3", function () {
      $('#example thead th:eq(3)').click();
      expect($('#example tbody tr:eq(0) td:eq(3)').html() == "66").toBeTruthy();
    });
    it("Filter 'London'- sorting col 3- reversed info", function () {
      $('#example_filter input').val("Lon").keyup();
      expect(doc.getElementById('example_info').innerHTML == "Showing 1 to 10 of 12 entries (filtered from 57 total entries)").toBeTruthy();
    });
    it("Filter 'nothingishere'", function () {
      $('#example_filter input').val("nothingishere").keyup();
      expect($('#example tbody tr:eq(0) td:eq(0)').html() == "No matching records found").toBeTruthy();
    });
    it("Filter 'nothingishere' info", function () {
      expect(doc.getElementById('example_info').innerHTML == "Showing 0 to 0 of 0 entries (filtered from 57 total entries)").toBeTruthy();
    });
    it("Filter back to blank and 1st column sorting", function () {
      $('#example_filter input').val("").keyup();
			$('#example thead th:eq(0)').click();
      expect(doc.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries").toBeTruthy();
    });
    it("Prefixing a filter entry", function () {
      $('#example_filter input').val("Author").keyup();
      $('#example_filter input').val("TechnicalAuthor").keyup();
      expect(doc.getElementById('example_info').innerHTML == "Showing 0 to 0 of 0 entries (filtered from 57 total entries)").toBeTruthy();
    });
    it("Prefixing a filter entry with space", function () {
      $('#example_filter input').val("Author").keyup();
      $('#example_filter input').val("Technical Author").keyup();
      expect(doc.getElementById('example_info').innerHTML == "Showing 1 to 2 of 2 entries (filtered from 57 total entries)").toBeTruthy();
    });
    dt.clean();
  });

} );