How to use dataView2 method in wpt

Best JavaScript code snippet using wpt

TableView.spec.js

Source:TableView.spec.js Github

copy

Full Screen

1/*!2* Copyright 2010 - 2017 Hitachi Vantara. All rights reserved.3*4* Licensed under the Apache License, Version 2.0 (the "License");5* you may not use this file except in compliance with the License.6* You may obtain a copy of the License at7*8* http://www.apache.org/licenses/LICENSE-2.09*10* Unless required by applicable law or agreed to in writing, software11* distributed under the License is distributed on an "AS IS" BASIS,12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13* See the License for the specific language governing permissions and14* limitations under the License.15*16*/17define([18 "pentaho/data/Table",19 "pentaho/data/TableView"20], function(DataTable, DataTableView) {21 var fooValue = {},22 barValue = {};23 function getDatasetDT1() {24 return {25 model: [26 {27 name: "country",28 type: "string",29 label: "Country",30 p: {31 foo: fooValue32 },33 members: [34 {35 v: "Portugal",36 f: "Portucale",37 p: {38 "geoAddress": {39 "continent": "Europe",40 "Country": "Portucale"41 }42 }43 }44 ],45 isKey: true,46 hierarchyName: "Foo",47 hierarchyOrdinal: 348 },49 {name: "sales", type: "number", label: "Sales", p: {bar: barValue}, isContinuous: true},50 {name: "euro", type: "boolean", label: "Euro"}51 ],52 rows: [53 {c: [ {v: "Portugal"}, {v: 12000, f: "1.2"}, true] },54 {c: [ {v: "Ireland" }, {v: 6000, f: "0.6"}, false] },55 {c: [ {v: "Italy" }, {v: 10000, f: "1.0"}, true] },56 {c: [ {v: "France" }, {v: 24000, f: "2.4"}, true] }57 ]58 };59 }60 describe("DataTableView -", function() {61 var dataTable;62 beforeEach(function() { dataTable = new DataTable(getDatasetDT1()); });63 it("should be a function", function() {64 expect(typeof DataTableView).toBe("function");65 });66 describe("#new() -", function() {67 describe("with no arguments -", function() {68 it("should throw", function() {69 expect(function() {70 new DataTableView();71 }).toThrow();72 });73 });74 it("should return an instance of DataTableView", function() {75 var dataView = new DataTableView(dataTable);76 expect(dataView instanceof DataTableView).toBe(true);77 });78 it("should return a data view with all source columns", function() {79 var dataView = new DataTableView(dataTable);80 expect(dataView.getNumberOfColumns()).toBe(dataTable.getNumberOfColumns());81 });82 it("should return a data view with all source rows", function() {83 var dataView = new DataTableView(dataTable);84 expect(dataView.getNumberOfRows()).toBe(dataTable.getNumberOfRows());85 });86 it("should return a data view whose source is the specified data table", function() {87 var dataView = new DataTableView(dataTable);88 expect(dataView._source).toBe(dataTable);89 });90 });91 describe("table -", function() {92 describe("#getSourceTable() -", function() {93 it("should return the view's source table", function() {94 var dataView = new DataTableView(dataTable);95 expect(dataView.getSourceTable()).toBe(dataTable);96 });97 });98 describe("#toDataTable() -", function() {99 it("should return a DataTable", function() {100 var dataView = new DataTableView(dataTable);101 expect(dataView.toDataTable() instanceof DataTable).toBe(true);102 });103 it("should not return the source data table", function() {104 var dataView = new DataTableView(dataTable);105 expect(dataView.toDataTable()).not.toBe(dataTable);106 });107 it("should return a data table having the same data", function() {108 var dataView = new DataTableView(dataTable);109 var dataTable2 = dataView.toDataTable();110 expect(dataTable2.toSpec()).toEqual(dataTable.toSpec());111 });112 it("should return a data table having only the view's visible columns", function() {113 var dataView = new DataTableView(dataTable);114 dataView.setSourceColumns([0, 1]);115 var dataTable2 = dataView.toDataTable();116 expect(dataTable2.getNumberOfColumns()).toBe(2);117 expect(dataTable2.getColumnId(0)).toBe('country');118 expect(dataTable2.getColumnId(1)).toBe('sales');119 expect(dataTable2.getNumberOfRows()).toBe(dataTable.getNumberOfRows());120 });121 it("should return a data table having only the view's visible rows", function() {122 var dataView = new DataTableView(dataTable);123 dataView.setSourceRows([0, 1]);124 var dataTable2 = dataView.toDataTable();125 expect(dataTable2.getNumberOfRows()).toBe(2);126 expect(dataTable2.getValue(0, 0)).toBe("Portugal");127 expect(dataTable2.getValue(1, 0)).toBe("Ireland");128 expect(dataTable2.getNumberOfColumns()).toBe(dataTable.getNumberOfColumns());129 });130 });131 });132 describe("columns -", function() {133 var dataView;134 beforeEach(function() {135 dataView = new DataTableView(dataTable);136 dataView.setSourceColumns([2, 0, 1]);137 });138 describe("#getNumberOfColumns() -", function() {139 it("should return 0 when there are no columns", function() {140 var dataView2 = new DataTableView(new DataTable());141 expect(dataView2.getNumberOfColumns()).toBe(0);142 });143 it("should return source column count when columns have not been set", function() {144 var dataView2 = new DataTableView(dataTable);145 expect(dataView2.getNumberOfColumns()).toBe(dataTable.getNumberOfColumns());146 });147 it("should return 2 when there are 2 visible columns", function() {148 var dataView2 = new DataTableView(dataTable);149 dataView2.setSourceColumns([2, 1]);150 expect(dataView2.getNumberOfColumns()).toBe(2);151 });152 it("should return 3 when there are 3 visible columns", function() {153 expect(dataView.getNumberOfColumns()).toBe(3);154 });155 });156 describe("#getSourceColumnIndex()", function() {157 it("should return the specified index when setSourceColumns was not called", function() {158 var dataView2 = new DataTableView(dataTable);159 expect(dataView2.getSourceColumnIndex(1)).toBe(1);160 });161 it("should return the mapped index when setSourceColumns was called", function() {162 expect(dataView.getSourceColumnIndex(0)).toBe(2);163 expect(dataView.getSourceColumnIndex(1)).toBe(0);164 expect(dataView.getSourceColumnIndex(2)).toBe(1);165 });166 });167 describe("#setSourceColumns()", function() {168 it("should set all columns visible when called with a nully value", function() {169 var dataView2 = new DataTableView(dataTable);170 dataView2.setSourceColumns([]);171 expect(dataView2.getNumberOfColumns()).toBe(0);172 dataView2.setSourceColumns();173 expect(dataView2.getNumberOfColumns()).toBe(dataTable.getNumberOfColumns());174 dataView2.setSourceColumns([]);175 dataView2.setSourceColumns(null);176 expect(dataView2.getNumberOfColumns()).toBe(dataTable.getNumberOfColumns());177 dataView2.setSourceColumns([]);178 dataView2.setSourceColumns(undefined);179 expect(dataView2.getNumberOfColumns()).toBe(dataTable.getNumberOfColumns());180 });181 it("should set only the specified columns visible", function() {182 var dataView2 = new DataTableView(dataTable);183 dataView2.setSourceColumns([0, 1]);184 expect(dataView2.getNumberOfColumns()).toBe(2);185 expect(dataView2.getColumnId(0)).toBe("country");186 expect(dataView2.getColumnId(1)).toBe("sales" );187 dataView2.setSourceColumns([1, 2, 1]);188 expect(dataView2.getNumberOfColumns()).toBe(3);189 expect(dataView2.getColumnId(0)).toBe("sales" );190 expect(dataView2.getColumnId(1)).toBe("euro");191 expect(dataView2.getColumnId(2)).toBe("sales" );192 });193 it("should return `this`", function() {194 var dataView2 = new DataTableView(dataTable);195 expect(dataView2.setSourceColumns([0, 1])).toBe(dataView2);196 });197 });198 describe("#hideColumns()", function() {199 it("should return `this`", function() {200 var dataView2 = new DataTableView(dataTable);201 expect(dataView2.hideColumns([0, 1])).toBe(dataView2);202 });203 it("should make sure the specified source column indexes are hidden", function() {204 dataView.hideColumns([0, 2]);205 expect(dataView.getNumberOfColumns()).toBe(1);206 expect(dataView.getColumnId(0)).toBe("sales");207 });208 it("should not throw if a specified column is already visible", function() {209 dataView.setSourceColumns([0, 2]);210 dataView.hideColumns([1, 0]);211 expect(dataView.getNumberOfColumns()).toBe(1);212 expect(dataView.getColumnId(0)).toBe("euro");213 });214 });215 describe("#getSourceColumns()", function() {216 it("should get all source column indexes, before setSourceColumns is called", function() {217 var dataView2 = new DataTableView(dataTable);218 expect(dataView2.getSourceColumns()).toEqual([0, 1, 2]);219 });220 it("should get the source column indexes currently visible", function() {221 expect(dataView.getSourceColumns()).toEqual([2, 0, 1]);222 dataView.setSourceColumns([1, 2]);223 expect(dataView.getSourceColumns()).toEqual([1, 2]);224 dataView.setSourceColumns([2, 2]);225 expect(dataView.getSourceColumns()).toEqual([2, 2]);226 });227 });228 describe("#getColumnType(j) -", function() {229 it("should return the column type of the given column index", function() {230 expect(dataView.getColumnType(0)).toBe("boolean");231 expect(dataView.getColumnType(1)).toBe("string");232 expect(dataView.getColumnType(2)).toBe("number");233 });234 });235 describe("#getColumnId(j) -", function() {236 it("should return the attribute name of the attribute of the given column index", function() {237 expect(dataView.getColumnId(0)).toBe("euro");238 expect(dataView.getColumnId(1)).toBe("country");239 expect(dataView.getColumnId(2)).toBe("sales");240 });241 });242 describe("#getColumnLabel(j) -", function() {243 it("should return the column label of the given column index", function() {244 expect(dataView.getColumnLabel(0)).toBe("Euro");245 expect(dataView.getColumnLabel(1)).toBe("Country");246 expect(dataView.getColumnLabel(2)).toBe("Sales");247 });248 });249 describe("#getColumnProperty(j, name) -", function() {250 it("should return the column property of the given column index and name", function() {251 expect(dataView.getColumnProperty(1, "foo")).toBe(fooValue);252 expect(dataView.getColumnProperty(2, "bar")).toBe(barValue);253 });254 });255 describe("#getColumnRange(j) -", function() {256 it("should return a range object with both min and max `undefined` when there is no data", function() {257 var dataView2 = new DataTableView(dataTable);258 dataView2.setSourceRows([]);259 expect(dataView2.getColumnRange(1)).toEqual({min: undefined, max: undefined});260 });261 it("should return a range object with the min and max values of the specified column", function() {262 expect(dataView.getColumnRange(0)).toEqual({min: false, max: true});263 expect(dataView.getColumnRange(1)).toEqual({min: "France", max: "Portugal"});264 expect(dataView.getColumnRange(2)).toEqual({min: 6000, max: 24000});265 });266 });267 describe("#getDistinctValues(j) -", function() {268 it("should return an empty array when there is no data", function() {269 var dataView2 = new DataTableView(dataTable);270 dataView2.setSourceRows([]);271 expect(dataView2.getDistinctValues(1)).toEqual([]);272 });273 it("should return an array containing the distinct values of the specified column", function() {274 var dataView2 = new DataTableView(dataTable);275 dataView2.setSourceColumns([2, 0, 1]);276 dataView2.setSourceRows([2, 1, 3, 0]);277 expect(dataView2.getDistinctValues(0)).toEqual([true, false]);278 expect(dataView2.getDistinctValues(1)).toEqual(["Italy", "Ireland", "France", "Portugal"]);279 expect(dataView2.getDistinctValues(2)).toEqual([10000, 6000, 24000, 12000]);280 });281 });282 describe("#getDistinctFormattedValues(j) -", function() {283 it("should return an empty array when there is no data", function() {284 var dataView2 = new DataTableView(dataTable);285 dataView2.setSourceRows([]);286 expect(dataView2.getDistinctFormattedValues(1)).toEqual([]);287 });288 it("should return an array containing the distinct formatted values of the specified column", function() {289 var dataView2 = new DataTableView(dataTable);290 dataView2.setSourceColumns([2, 0, 1]);291 dataView2.setSourceRows([2, 1, 3, 0]);292 expect(dataView2.getDistinctFormattedValues(0)).toEqual(["true", "false"]);293 expect(dataView2.getDistinctFormattedValues(1)).toEqual(["Italy", "Ireland", "France", "Portucale"]);294 expect(dataView2.getDistinctFormattedValues(2)).toEqual(["1.0", "0.6", "2.4", "1.2"]);295 });296 });297 describe("#isColumnKey(j) -", function() {298 it("should return the column isKey of the given column index", function() {299 expect(dataView.isColumnKey(0)).toBe(false);300 expect(dataView.isColumnKey(1)).toBe(true);301 expect(dataView.isColumnKey(2)).toBe(false);302 });303 });304 describe("#getColumnHierarchyName(j) -", function() {305 it("should return the attribute hierarchyName of the attribute of given column index", function() {306 expect(dataView.getColumnHierarchyName(0)).toBe(null);307 expect(dataView.getColumnHierarchyName(1)).toBe("Foo");308 expect(dataView.getColumnHierarchyName(2)).toBe(null);309 });310 });311 describe("#getColumnHierarchyOrdinal(j) -", function() {312 it("should return the attribute hierarchyOrdinal of the attribute of given column index", function() {313 expect(dataView.getColumnHierarchyOrdinal(0)).toBe(null);314 expect(dataView.getColumnHierarchyOrdinal(1)).toBe(3);315 expect(dataView.getColumnHierarchyOrdinal(2)).toBe(null);316 });317 });318 describe("#addColumn(colSpec)", function() {319 it("should add another column to the root table as last column", function() {320 var count = dataTable.getNumberOfColumns();321 dataTable.model.attributes.add({322 name: "A",323 type: "string",324 label: "A"325 });326 dataView.addColumn("A");327 expect(dataTable.getNumberOfColumns()).toBe(count + 1);328 expect(dataTable.getColumnId(count)).toBe("A");329 });330 it("should make the new column visible in the view", function() {331 var count = dataTable.getNumberOfColumns();332 var dataView2 = new DataTableView(dataTable);333 dataView2.setSourceColumns([0, 1]);334 dataTable.model.attributes.add({335 name: "A",336 type: "string",337 label: "A"338 });339 dataView2.addColumn("A");340 expect(dataTable.getColumnId(count)).toBe("A");341 expect(dataView2.getNumberOfColumns()).toBe(3);342 expect(dataView2.getColumnId(2)).toBe("A");343 });344 it("should return the index of the added view column", function() {345 var dataView2 = new DataTableView(dataTable);346 dataView2.setSourceColumns([0, 1]);347 dataTable.model.attributes.add({348 name: "A",349 type: "string",350 label: "A"351 });352 var index = dataView2.addColumn("A");353 expect(index).toBe(2);354 });355 });356 });357 describe("rows -", function() {358 describe("#getNumberOfRows() -", function() {359 it("should return 0 when there are no rows", function() {360 var dataView2 = new DataTableView(new DataTable());361 expect(dataView2.getNumberOfRows()).toBe(0);362 });363 it("should return source row count when rows have not been set", function() {364 var dataView2 = new DataTableView(dataTable);365 expect(dataView2.getNumberOfRows()).toBe(dataTable.getNumberOfRows());366 });367 it("should return 2 when there are 2 visible rows", function() {368 var dataView2 = new DataTableView(dataTable);369 dataView2.setSourceRows([1, 2]);370 expect(dataView2.getNumberOfRows()).toBe(2);371 });372 it("should return 3 when there are 3 visible rows", function() {373 var dataView2 = new DataTableView(dataTable);374 dataView2.setSourceRows([1, 2, 0]);375 expect(dataView2.getNumberOfRows()).toBe(3);376 });377 });378 describe("#getSourceRowIndex()", function() {379 it("should return the specified index when setRows was not called", function() {380 var dataView2 = new DataTableView(dataTable);381 expect(dataView2.getSourceRowIndex(1)).toBe(1);382 expect(dataView2.getSourceRowIndex(0)).toBe(0);383 });384 it("should return the mapped index when setRows was called", function() {385 var dataView2 = new DataTableView(dataTable);386 dataView2.setSourceRows([0, 2, 1]);387 expect(dataView2.getSourceRowIndex(0)).toBe(0);388 expect(dataView2.getSourceRowIndex(1)).toBe(2);389 expect(dataView2.getSourceRowIndex(2)).toBe(1);390 });391 });392 describe("#setSourceRows()", function() {393 it("should set all rows visible when called with a nully value", function() {394 var dataView2 = new DataTableView(dataTable);395 dataView2.setSourceRows([]);396 expect(dataView2.getNumberOfRows()).toBe(0);397 dataView2.setSourceRows();398 expect(dataView2.getNumberOfRows()).toBe(dataTable.getNumberOfRows());399 dataView2.setSourceRows([]);400 dataView2.setSourceRows(null);401 expect(dataView2.getNumberOfRows()).toBe(dataTable.getNumberOfRows());402 dataView2.setSourceRows([]);403 dataView2.setSourceRows(undefined);404 expect(dataView2.getNumberOfRows()).toBe(dataTable.getNumberOfRows());405 });406 it("should set only the specified rows visible", function() {407 var dataView2 = new DataTableView(dataTable);408 dataView2.setSourceRows([1, 0]);409 expect(dataView2.getNumberOfRows()).toBe(2);410 expect(dataView2.getValue(0, 0)).toBe("Ireland");411 expect(dataView2.getValue(1, 0)).toBe("Portugal");412 dataView2.setSourceRows([1, 2, 1]);413 expect(dataView2.getNumberOfRows()).toBe(3);414 expect(dataView2.getValue(0, 0)).toBe("Ireland");415 expect(dataView2.getValue(1, 0)).toBe("Italy");416 expect(dataView2.getValue(2, 0)).toBe("Ireland");417 });418 it("should return `this`", function() {419 var dataView2 = new DataTableView(dataTable);420 expect(dataView2.setSourceRows([0, 1])).toBe(dataView2);421 });422 });423 describe("#getSourceRows()", function() {424 var dataView;425 beforeEach(function() {426 dataView = new DataTableView(dataTable);427 });428 it("should return null before setSourceRows is called", function() {429 expect(dataView.getSourceRows()).toBe(null);430 });431 it("should get the source column indexes currently visible", function() {432 dataView.setSourceRows([1, 2]);433 expect(dataView.getSourceRows()).toEqual([1, 2]);434 dataView.setSourceRows([2, 2]);435 expect(dataView.getSourceRows()).toEqual([2, 2]);436 });437 });438 });439 describe("cells -", function() {440 var dataView;441 beforeEach(function() {442 dataView = new DataTableView(dataTable);443 dataView.setSourceColumns([2, 0, 1]);444 dataView.setSourceRows([3, 0, 1]);445 });446 describe("#getValue()", function() {447 it("should return the value of the specified row and column", function() {448 expect(dataView.getValue(0, 1)).toBe("France");449 expect(dataView.getValue(2, 0)).toBe(false);450 });451 });452 describe("#getFormattedValue()", function() {453 it("should return the formatted value of the specified row and column", function() {454 expect(dataView.getFormattedValue(0, 2)).toBe("2.4");455 expect(dataView.getFormattedValue(1, 0)).toBe("true");456 });457 });458 describe("#getLabel()", function() {459 it("should return the label of the specified row and column", function() {460 expect(dataView.getLabel(0, 2)).toBe("2.4");461 expect(dataView.getLabel(1, 0)).toBe(undefined);462 });463 });464 describe("#getCell()", function() {465 it("should return the cell of the specified row and column", function() {466 var cell = dataView.getCell(0, 2);467 expect(cell.v).toBe(24000);468 expect(cell.f).toBe("2.4");469 cell = dataView.getCell(1, 0);470 expect(cell.v).toBe(true);471 expect(cell.f).toBe(undefined);472 });473 });474 describe("getCellProperty(i, j, p)", function() {475 it("should return undefined if the property does not exist", function() {476 var geoAddress = dataView.getCellProperty(1, 1, "notExistingProperty");477 expect(geoAddress).toBe(undefined);478 });479 it("should return the value of the property if it exists", function() {480 var geoAddress = dataView.getCellProperty(1, 1, "geoAddress");481 expect(geoAddress).toEqual({482 "continent": "Europe",483 "Country": "Portucale"484 });485 });486 });487 });488 });...

Full Screen

Full Screen

DataViewSpec.js

Source:DataViewSpec.js Github

copy

Full Screen

1/*!2* Copyright 2010 - 2015 Pentaho Corporation. All rights reserved.3*4* Licensed under the Apache License, Version 2.0 (the "License");5* you may not use this file except in compliance with the License.6* You may obtain a copy of the License at7*8* http://www.apache.org/licenses/LICENSE-2.09*10* Unless required by applicable law or agreed to in writing, software11* distributed under the License is distributed on an "AS IS" BASIS,12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13* See the License for the specific language governing permissions and14* limitations under the License.15*16*/17define([18 "pentaho/visual/data/DataTable",19 "pentaho/visual/data/DataView"20], function(DataTable, DataView) {21 var fooValue = {},22 barValue = {};23 function getDatasetDT1() {24 return {25 cols: [26 {id: "country", type: "string", label: "Country", foo: fooValue},27 {id: "sales", type: "number", label: "Sales", bar: barValue},28 {id: "euro", type: "boolean", label: "Euro" }29 ],30 rows: [31 {c: [ {v: "Portugal"}, {v: 12000, f: "1.2"}, true] },32 {c: [ {v: "Ireland" }, {v: 6000, f: "0.6"}, false] },33 {c: [ {v: "Italy" }, {v: 10000, f: "1.0"}, true] },34 {c: [ {v: "France" }, {v: 24000, f: "2.4"}, true] }35 ]36 };37 }38 describe("DataView -", function() {39 var dataTable;40 beforeEach(function() { dataTable = new DataTable(getDatasetDT1()); });41 it("should be a function", function() {42 expect(typeof DataView).toBe("function");43 });44 describe("#new() -", function() {45 describe("with no arguments -", function() {46 it("should throw", function() {47 expect(function() {48 new DataView();49 }).toThrow();50 });51 });52 describe("with one argument, a plain JavaScript object in DataTable format -", function() {53 it("should return an instance of DataView", function() {54 var dataView = new DataView(dataTable);55 expect(dataView instanceof DataView).toBe(true);56 });57 it("should return a data view with all source columns", function() {58 var dataView = new DataView(dataTable);59 expect(dataView.getNumberOfColumns()).toBe(dataTable.getNumberOfColumns());60 });61 it("should return a data view with all source rows", function() {62 var dataView = new DataView(dataTable);63 expect(dataView.getNumberOfRows()).toBe(dataTable.getNumberOfRows());64 });65 it("should return a data view whose source is the specified data table", function() {66 var dataView = new DataView(dataTable);67 expect(dataView._source).toBe(dataTable);68 });69 });70 });71 describe("table -", function() {72 describe("#getSourceTable() -", function() {73 it("should return the view's source table", function() {74 var dataView = new DataView(dataTable);75 expect(dataView.getSourceTable()).toBe(dataTable);76 });77 });78 describe("#toDataTable() -", function() {79 it("should return a DataTable", function() {80 var dataView = new DataView(dataTable);81 expect(dataView.toDataTable() instanceof DataTable).toBe(true);82 });83 it("should not return the source data table", function() {84 var dataView = new DataView(dataTable);85 expect(dataView.toDataTable()).not.toBe(dataTable);86 });87 it("should return a data table having the same data", function() {88 var dataView = new DataView(dataTable);89 var dataTable2 = dataView.toDataTable();90 expect(dataTable2.toJSON()).toEqual(dataTable.toJSON());91 });92 it("should return a data table having only the view's visible columns", function() {93 var dataView = new DataView(dataTable);94 dataView.setColumns([0, 1]);95 var dataTable2 = dataView.toDataTable();96 expect(dataTable2.getNumberOfColumns()).toBe(2);97 expect(dataTable2.getColumnId(0)).toBe('country');98 expect(dataTable2.getColumnId(1)).toBe('sales');99 expect(dataTable2.getNumberOfRows()).toBe(dataTable.getNumberOfRows());100 });101 it("should return a data table having only the view's visible rows", function() {102 var dataView = new DataView(dataTable);103 dataView.setRows([0, 1]);104 var dataTable2 = dataView.toDataTable();105 expect(dataTable2.getNumberOfRows()).toBe(2);106 expect(dataTable2.getValue(0, 0)).toBe("Portugal");107 expect(dataTable2.getValue(1, 0)).toBe("Ireland");108 expect(dataTable2.getNumberOfColumns()).toBe(dataTable.getNumberOfColumns());109 });110 });111 });112 describe("columns -", function() {113 var dataView;114 beforeEach(function() {115 dataView = new DataView(dataTable);116 dataView.setColumns([2, 0, 1]);117 });118 describe("#getNumberOfColumns() -", function() {119 it("should return 0 when there are no columns", function() {120 var dataView2 = new DataView(new DataTable());121 expect(dataView2.getNumberOfColumns()).toBe(0);122 });123 it("should return source column count when columns have not been set", function() {124 var dataView2 = new DataView(dataTable);125 expect(dataView2.getNumberOfColumns()).toBe(dataTable.getNumberOfColumns());126 });127 it("should return 2 when there are 2 visible columns", function() {128 var dataView2 = new DataView(dataTable);129 dataView2.setColumns([2, 1]);130 expect(dataView2.getNumberOfColumns()).toBe(2);131 });132 it("should return 3 when there are 3 visible columns", function() {133 expect(dataView.getNumberOfColumns()).toBe(3);134 });135 });136 describe("#getTableColumnIndex()", function() {137 it("should return the specified index when setColumns was not called", function() {138 var dataView2 = new DataView(dataTable);139 expect(dataView2.getTableColumnIndex(1)).toBe(1);140 });141 it("should return the mapped index when setColumns was called", function() {142 expect(dataView.getTableColumnIndex(0)).toBe(2);143 expect(dataView.getTableColumnIndex(1)).toBe(0);144 expect(dataView.getTableColumnIndex(2)).toBe(1);145 });146 });147 describe("#setColumns()", function() {148 it("should set all columns visible when called with a nully value", function() {149 var dataView2 = new DataView(dataTable);150 dataView2.setColumns([]);151 expect(dataView2.getNumberOfColumns()).toBe(0);152 dataView2.setColumns();153 expect(dataView2.getNumberOfColumns()).toBe(dataTable.getNumberOfColumns());154 dataView2.setColumns([]);155 dataView2.setColumns(null);156 expect(dataView2.getNumberOfColumns()).toBe(dataTable.getNumberOfColumns());157 dataView2.setColumns([]);158 dataView2.setColumns(undefined);159 expect(dataView2.getNumberOfColumns()).toBe(dataTable.getNumberOfColumns());160 });161 it("should set only the specified columns visible", function() {162 var dataView2 = new DataView(dataTable);163 dataView2.setColumns([0, 1]);164 expect(dataView2.getNumberOfColumns()).toBe(2);165 expect(dataView2.getColumnId(0)).toBe("country");166 expect(dataView2.getColumnId(1)).toBe("sales" );167 dataView2.setColumns([1, 2, 1]);168 expect(dataView2.getNumberOfColumns()).toBe(3);169 expect(dataView2.getColumnId(0)).toBe("sales" );170 expect(dataView2.getColumnId(1)).toBe("euro");171 expect(dataView2.getColumnId(2)).toBe("sales" );172 });173 it("should return `this`", function() {174 var dataView2 = new DataView(dataTable);175 expect(dataView2.setColumns([0, 1])).toBe(dataView2);176 });177 });178 describe("#hideColumns()", function() {179 it("should return `this`", function() {180 var dataView2 = new DataView(dataTable);181 expect(dataView2.hideColumns([0, 1])).toBe(dataView2);182 });183 it("should make sure the specified source column indexes are hidden", function() {184 dataView.hideColumns([0, 2]);185 expect(dataView.getNumberOfColumns()).toBe(1);186 expect(dataView.getColumnId(0)).toBe("sales");187 });188 it("should not throw if a specified column is already visible", function() {189 dataView.setColumns([0, 2]);190 dataView.hideColumns([1, 0]);191 expect(dataView.getNumberOfColumns()).toBe(1);192 expect(dataView.getColumnId(0)).toBe("euro");193 });194 });195 describe("#getViewColumns()", function() {196 it("should get all source column indexes, before setColumns is called", function() {197 var dataView2 = new DataView(dataTable);198 expect(dataView2.getViewColumns()).toEqual([0, 1, 2]);199 });200 it("should get the source column indexes currently visible", function() {201 expect(dataView.getViewColumns()).toEqual([2, 0, 1]);202 dataView.setColumns([1, 2]);203 expect(dataView.getViewColumns()).toEqual([1, 2]);204 dataView.setColumns([2, 2]);205 expect(dataView.getViewColumns()).toEqual([2, 2]);206 });207 });208 describe("#getColumnType() -", function() {209 it("should return the column type of the given column index", function() {210 expect(dataView.getColumnType(0)).toBe("boolean");211 expect(dataView.getColumnType(1)).toBe("string");212 expect(dataView.getColumnType(2)).toBe("number");213 });214 });215 describe("#getColumnId() -", function() {216 it("should return the column id of the given column index", function() {217 expect(dataView.getColumnId(0)).toBe("euro");218 expect(dataView.getColumnId(1)).toBe("country");219 expect(dataView.getColumnId(2)).toBe("sales");220 });221 });222 describe("#getColumnLabel() -", function() {223 it("should return the column label of the given column index", function() {224 expect(dataView.getColumnLabel(0)).toBe("Euro");225 expect(dataView.getColumnLabel(1)).toBe("Country");226 expect(dataView.getColumnLabel(2)).toBe("Sales");227 });228 });229 describe("#getColumnProperty() -", function() {230 it("should return the value of the specified column property", function() {231 expect(dataView.getColumnProperty(1, "foo")).toBe(fooValue);232 expect(dataView.getColumnProperty(2, "bar")).toBe(barValue);233 });234 it("should return `undefined` for a column property which is not defined", function() {235 expect(dataView.getColumnProperty(0, "foo")).toBeUndefined();236 });237 });238 describe("#setColumnProperty() -", function() {239 it("should set the value of the specified column property", function() {240 var guru = {};241 dataView.setColumnProperty(0, "guru", guru);242 expect(dataView.getColumnProperty(0, "guru")).toBe(guru);243 expect(dataTable.getColumnProperty(2, "guru")).toBe(guru);244 });245 });246 describe("#getColumnRange() -", function() {247 it("should return a range object with both min and max `undefined` when there is no data", function() {248 var dataView2 = new DataView(dataTable);249 dataView2.setRows([]);250 expect(dataView2.getColumnRange(1)).toEqual({min: undefined, max: undefined});251 });252 it("should return a range object with the min and max values of the specified column", function() {253 expect(dataView.getColumnRange(0)).toEqual({min: false, max: true});254 expect(dataView.getColumnRange(1)).toEqual({min: "France", max: "Portugal"});255 expect(dataView.getColumnRange(2)).toEqual({min: 6000, max: 24000});256 });257 });258 describe("#getDistinctValues() -", function() {259 it("should return an empty array when there is no data", function() {260 var dataView2 = new DataView(dataTable);261 dataView2.setRows([]);262 expect(dataView2.getDistinctValues(1)).toEqual([]);263 });264 it("should return an array containing the distinct values of the specified column", function() {265 var dataView2 = new DataView(dataTable);266 dataView2.setColumns([2, 0, 1]);267 dataView2.setRows([2, 1, 3, 0]);268 expect(dataView2.getDistinctValues(0)).toEqual([true, false]);269 expect(dataView2.getDistinctValues(1)).toEqual(["Italy", "Ireland", "France", "Portugal"]);270 expect(dataView2.getDistinctValues(2)).toEqual([10000, 6000, 24000, 12000]);271 });272 });273 describe("#getDistinctFormattedValues() -", function() {274 it("should return an empty array when there is no data", function() {275 var dataView2 = new DataView(dataTable);276 dataView2.setRows([]);277 expect(dataView2.getDistinctFormattedValues(1)).toEqual([]);278 });279 it("should return an array containing the distinct formatted values of the specified column", function() {280 var dataView2 = new DataView(dataTable);281 dataView2.setColumns([2, 0, 1]);282 dataView2.setRows([2, 1, 3, 0]);283 expect(dataView2.getDistinctFormattedValues(0)).toEqual(["true", "false"]);284 expect(dataView2.getDistinctFormattedValues(1)).toEqual(["Italy", "Ireland", "France", "Portugal"]);285 expect(dataView2.getDistinctFormattedValues(2)).toEqual(["1.0", "0.6", "2.4", "1.2"]);286 });287 });288 describe("#addColumn()", function() {289 it("should add another column to the root table as last column", function() {290 var count = dataTable.getNumberOfColumns();291 dataView.addColumn({id: "A", type: "string", label: "A"});292 expect(dataTable.getNumberOfColumns()).toBe(count + 1);293 expect(dataTable.getColumnId(count)).toBe("A");294 });295 it("should make the new column visible in the view", function() {296 var count = dataTable.getNumberOfColumns();297 var dataView2 = new DataView(dataTable);298 dataView2.setColumns([0, 1]);299 dataView2.addColumn({id: "A", type: "string", label: "A"});300 expect(dataTable.getColumnId(count)).toBe("A");301 expect(dataView2.getNumberOfColumns()).toBe(3);302 expect(dataView2.getColumnId(2)).toBe("A");303 });304 it("should return the index of the added view column", function() {305 var dataView2 = new DataView(dataTable);306 dataView2.setColumns([0, 1]);307 var index = dataView2.addColumn({id: "A", type: "string", label: "A"});308 expect(index).toBe(2);309 });310 });311 });312 describe("rows -", function() {313 describe("#getNumberOfRows() -", function() {314 it("should return 0 when there are no rows", function() {315 var dataView2 = new DataView(new DataTable());316 expect(dataView2.getNumberOfRows()).toBe(0);317 });318 it("should return source row count when rows have not been set", function() {319 var dataView2 = new DataView(dataTable);320 expect(dataView2.getNumberOfRows()).toBe(dataTable.getNumberOfRows());321 });322 it("should return 2 when there are 2 visible rows", function() {323 var dataView2 = new DataView(dataTable);324 dataView2.setRows([1, 2]);325 expect(dataView2.getNumberOfRows()).toBe(2);326 });327 it("should return 3 when there are 3 visible rows", function() {328 var dataView2 = new DataView(dataTable);329 dataView2.setRows([1, 2, 0]);330 expect(dataView2.getNumberOfRows()).toBe(3);331 });332 });333 describe("#getTableRowIndex()", function() {334 it("should return the specified index when setRows was not called", function() {335 var dataView2 = new DataView(dataTable);336 expect(dataView2.getTableRowIndex(1)).toBe(1);337 expect(dataView2.getTableRowIndex(0)).toBe(0);338 });339 it("should return the mapped index when setRows was called", function() {340 var dataView2 = new DataView(dataTable);341 dataView2.setRows([0, 2, 1]);342 expect(dataView2.getTableRowIndex(0)).toBe(0);343 expect(dataView2.getTableRowIndex(1)).toBe(2);344 expect(dataView2.getTableRowIndex(2)).toBe(1);345 });346 });347 describe("#setRows()", function() {348 it("should set all rows visible when called with a nully value", function() {349 var dataView2 = new DataView(dataTable);350 dataView2.setRows([]);351 expect(dataView2.getNumberOfRows()).toBe(0);352 dataView2.setRows();353 expect(dataView2.getNumberOfRows()).toBe(dataTable.getNumberOfRows());354 dataView2.setRows([]);355 dataView2.setRows(null);356 expect(dataView2.getNumberOfRows()).toBe(dataTable.getNumberOfRows());357 dataView2.setRows([]);358 dataView2.setRows(undefined);359 expect(dataView2.getNumberOfRows()).toBe(dataTable.getNumberOfRows());360 });361 it("should set only the specified rows visible", function() {362 var dataView2 = new DataView(dataTable);363 dataView2.setRows([1, 0]);364 expect(dataView2.getNumberOfRows()).toBe(2);365 expect(dataView2.getValue(0, 0)).toBe("Ireland");366 expect(dataView2.getValue(1, 0)).toBe("Portugal");367 dataView2.setRows([1, 2, 1]);368 expect(dataView2.getNumberOfRows()).toBe(3);369 expect(dataView2.getValue(0, 0)).toBe("Ireland");370 expect(dataView2.getValue(1, 0)).toBe("Italy");371 expect(dataView2.getValue(2, 0)).toBe("Ireland");372 });373 it("should return `this`", function() {374 var dataView2 = new DataView(dataTable);375 expect(dataView2.setRows([0, 1])).toBe(dataView2);376 });377 });378 describe("#getViewRows()", function() {379 var dataView;380 beforeEach(function() {381 dataView = new DataView(dataTable);382 });383 it("should return null before setColumns is called", function() {384 expect(dataView.getViewRows()).toBe(null);385 });386 it("should get the source column indexes currently visible", function() {387 dataView.setRows([1, 2]);388 expect(dataView.getViewRows()).toEqual([1, 2]);389 dataView.setRows([2, 2]);390 expect(dataView.getViewRows()).toEqual([2, 2]);391 });392 });393 });394 describe("cells -", function() {395 var dataView;396 beforeEach(function() {397 dataView = new DataView(dataTable);398 dataView.setColumns([2, 0, 1]);399 dataView.setRows([3, 0, 1]);400 });401 describe("#getValue()", function() {402 it("should return the value of the specified row and column", function() {403 expect(dataView.getValue(0, 1)).toBe("France");404 expect(dataView.getValue(2, 0)).toBe(false);405 });406 });407 describe("#getFormattedValue()", function() {408 it("should return the formatted value of the specified row and column", function() {409 expect(dataView.getFormattedValue(0, 2)).toBe("2.4");410 expect(dataView.getFormattedValue(1, 0)).toBe("true");411 });412 });413 describe("#getLabel()", function() {414 it("should return the label of the specified row and column", function() {415 expect(dataView.getLabel(0, 2)).toBe("2.4");416 expect(dataView.getLabel(1, 0)).toBe(null);417 });418 });419 describe("#getCell()", function() {420 it("should return the cell of the specified row and column", function() {421 expect(dataView.getCell(0, 2)).toEqual({v: 24000, f: "2.4"});422 expect(dataView.getCell(1, 0)).toEqual({v: true, f: null});423 });424 });425 });426 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var dataView2 = require('wpt').dataView2;2 if(err) {3 console.log(err);4 }5 else {6 console.log(data);7 }8});9var dataView3 = require('wpt').dataView3;10 if(err) {11 console.log(err);12 }13 else {14 console.log(data);15 }16});17var dataView4 = require('wpt').dataView4;18 if(err) {19 console.log(err);20 }21 else {22 console.log(data);23 }24});25var dataView5 = require('wpt').dataView5;26 if(err) {27 console.log(err);28 }29 else {30 console.log(data);31 }32});33var dataView6 = require('wpt').dataView6;34 if(err) {35 console.log(err);36 }37 else {38 console.log(data);39 }40});41var dataView7 = require('wpt').dataView7;42 if(err) {43 console.log(err);44 }45 else {46 console.log(data);47 }48});

Full Screen

Using AI Code Generation

copy

Full Screen

1var test = new wptextpattern();2test.dataView2();3function wptextpattern() {4 this.dataView2 = function() {5 console.log("dataView2 method called");6 };7}

Full Screen

Using AI Code Generation

copy

Full Screen

1var data = wpt.dataView2();2for (var i = 0; i < data.length; i++) {3 console.log(data[i].name + " = " + data[i].value);4}5var data = wpt.dataView();6for (var i = 0; i < data.length; i++) {7 console.log(data[i].name + " = " + data[i].value);8}9var data = wpt.dataView();10for (var i = 0; i < data.length; i++) {11 console.log(data[i].name + " = " + data[i].value);12}13var data = wpt.dataView();14for (var i = 0

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var http = require('http');4var url = require('url');5var qs = require('querystring');6http.createServer(function (req, res) {7 var urlObj = url.parse(req.url);8 var query = qs.parse(urlObj.query);9 var page = query.page;10 var lang = query.lang;11 if (page == undefined) {12 page = 'Taj_Mahal';13 }14 if (lang == undefined) {15 lang = 'en';16 }17 var page = 'Taj_Mahal';18 var lang = 'en';19 var page = 'Chichen_Itza';20 var lang = 'es';21 var page = 'Kremlin';22 var lang = 'ru';23 var page = 'Great_Wall_of_China';24 var lang = 'zh';25 var page = 'Eiffel_Tower';26 var lang = 'fr';27 var page = 'Colosseum';28 var lang = 'it';

Full Screen

Using AI Code Generation

copy

Full Screen

1var codeToInject = function() {2 var mydata = {3 'description': document.querySelector('meta[name="description"]').getAttribute('content'),4 'keywords': document.querySelector('meta[name="keywords"]').getAttribute('content')5 };6 var data = JSON.stringify(mydata);7 window.webpagetest.addData('dataView2', data);8};9var codeToInject2 = function() {10 var mydata = {11 'description': document.querySelector('meta[name="description"]').getAttribute('content'),12 'keywords': document.querySelector('meta[name="keywords"]').getAttribute('content')13 };14 var data = JSON.stringify(mydata);15 window.webpagetest.addData('dataView3', data);16};17var codeToInject3 = function() {18 var mydata = {19 'description': document.querySelector('meta[name="description"]').getAttribute('content'),20 'keywords': document.querySelector('meta[name="keywords"]').getAttribute('content')21 };22 var data = JSON.stringify(mydata);23 window.webpagetest.addData('dataView4', data);24};25var codeToInject4 = function() {26 var mydata = {27 'description': document.querySelector('meta[name="description"]').getAttribute('content'),28 'keywords': document.querySelector('meta[name="keywords"]').getAttribute('content')29 };

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful