Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
thehitechpanky committed Jun 21, 2020
1 parent 67ccbdd commit c390d54
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 76 deletions.
19 changes: 11 additions & 8 deletions sample/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
let headData=[{text:"Name"}];
let dataRows=[];
for(i=0;i<300;i++){
let currentRow=[{text:"Hello World"}];
let headData = [{
text: "Name"
}];
let dataRows = [];
for (i = 0; i < 300; i++) {
let currentRow = [{
text: "Hello World"
}];
dataRows.push({
data: currentRow
data: currentRow
});
}
let newDynamicTable = new DynamicTable({
Expand All @@ -13,14 +17,13 @@ let newDynamicTable = new DynamicTable({
head2Row,
footRow,
functionArray,
addRowCount:true,
addHeadDataAtBottom:true,
addRowCount: true,
addHeadDataAtBottom: true,
addFilter: true,
addLimit: true,
addCheckboxes: true,
checkboxClass
});

let newDynamicTableNode = newDynamicTable.createTable();
let divNode = document.getElementById(`tableDiv`);
divNode.appendChild(newDynamicTableNode);
51 changes: 25 additions & 26 deletions src/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ class DynamicTable {
placeholder: `Type here to search...`
});
this.limitNode = this._getLimitNode();
this.loadMore = this._getNode('button',{
className:`btn btn-primary`,
text:`Load More`,
type:`button`
this.loadMore = this._getNode('button', {
className: `btn btn-primary`,
text: `Load More`,
type: `button`
});
this.countNode = this._getNode(`div`);
this.bodyNode = this._getNode(`tbody`, {
id: `tBody`
});
this.checkBoxArray = [];
this.isClicked=false;
this.extraRowsCount=0;
this.isClicked = false;
this.extraRowsCount = 0;
}
createTable() {
let {
Expand All @@ -47,7 +47,7 @@ class DynamicTable {
if (footData) {
this._addTableDivision(tableNode, `tfoot`, footData);
} else {
if(addHeadDataAtBottom){
if (addHeadDataAtBottom) {
this._addTableDivision(tableNode, `tfoot`, headData, head2Data);
}
}
Expand All @@ -66,12 +66,12 @@ class DynamicTable {
}
if (addLimit) {
this.limitNode.onchange = () => {
this.extraRowsCount=0;
this.extraRowsCount = 0;
this._addTableDataRows();
}
}
this.loadMore.onclick=()=>{
this.isClicked=true;
this.loadMore.onclick = () => {
this.isClicked = true;
this._addTableDataRows();
}
}
Expand Down Expand Up @@ -259,8 +259,8 @@ class DynamicTable {
let serialNumber = 0;
let limitNumber = 0;
let rowNode;
if(this.isClicked){
this.extraRowsCount+=parseInt(this.limitNode.value);
if (this.isClicked) {
this.extraRowsCount += parseInt(this.limitNode.value);
}
dataRows.forEach(currentRow => {
let {
Expand All @@ -282,29 +282,28 @@ class DynamicTable {
}
});
rowNode = this._getNode(`tr`);
let colspanForButton=(1+headData.length);
if(addCheckboxes){
colspanForButton+=1
let colspanForButton = (1 + headData.length);
if (addCheckboxes) {
colspanForButton += 1
}
let columnNode=this._getNode(`td`,{
colspan:colspanForButton
let columnNode = this._getNode(`td`, {
colspan: colspanForButton
});
let center=this._getNode(`center`);
let center = this._getNode(`center`);
center.appendChild(this.loadMore);
columnNode.appendChild(center);
rowNode.appendChild(columnNode);
this.bodyNode.appendChild(rowNode);
if(this.isClicked){
this.isClicked=false;
}
if(limitNumber===serialNumber){
this.loadMore.style.display=`none`;
if (this.isClicked) {
this.isClicked = false;
}
else{
this.loadMore.style.display=``;
if (limitNumber === serialNumber) {
this.loadMore.style.display = `none`;
} else {
this.loadMore.style.display = ``;
}
this._clearNode(this.countNode);
if(addRowCount){
if (addRowCount) {
let textNode = document.createTextNode(`Showing 1 to ${limitNumber} of ${serialNumber} entries`);
this.countNode.appendChild(textNode);
}
Expand Down
88 changes: 46 additions & 42 deletions tests/tableTest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const puppeteer = require('puppeteer');
const cheerio = require("cheerio");

async function autoScroll(page){
async function autoScroll(page) {
await page.evaluate(async () => {
await new Promise((resolve, reject) => {
var totalHeight = 0;
Expand All @@ -10,49 +9,38 @@ async function autoScroll(page){
var scrollHeight = document.body.scrollHeight;
window.scrollBy(0, distance);
totalHeight += distance;

if(totalHeight >= scrollHeight){
if (totalHeight >= scrollHeight) {
clearInterval(timer);
resolve();
}
}, 100);
});
});

}

function checkOption50($){
function checkOption50($) {
console.log($('#tableData tbody tr').length);
if($('#tableData tbody tr').length===51)
console.log("Test Passed for option whose value is 50");
else
console.log("Test Failed for option whose value is 50");
if ($('#tableData tbody tr').length === 51) console.log("Test Passed for option whose value is 50");
else console.log("Test Failed for option whose value is 50");
}

function checkOption100($){
function checkOption100($) {
console.log($('#tableData tbody tr').length);
if($('#tableData tbody tr').length===101)
console.log("Test Passed for option whose value is 100");
else
console.log("Test Failed for option whose value is 100");
if ($('#tableData tbody tr').length === 101) console.log("Test Passed for option whose value is 100");
else console.log("Test Failed for option whose value is 100");
}

function checkOption250($){
function checkOption250($) {
console.log($('#tableData tbody tr').length);
if($('#tableData tbody tr').length===251)
console.log("Test Passed for option whose value is 250");
else
console.log("Test Failed for option whose value is 250");
if ($('#tableData tbody tr').length === 251) console.log("Test Passed for option whose value is 250");
else console.log("Test Failed for option whose value is 250");
}

function checkOptionAll($){
function checkOptionAll($) {
console.log($('#tableData tbody tr').length);
if($('#tableData tbody tr').length===301)
console.log("Test Passed for option whose value is 300");
else
console.log("Test Failed for option whose value is 300");
if ($('#tableData tbody tr').length === 301) console.log("Test Passed for option whose value is 300");
else console.log("Test Failed for option whose value is 300");
}

(async () => {
const browser = await puppeteer.launch({
headless: false
Expand All @@ -66,41 +54,57 @@ function checkOptionAll($){
await page.goto('http://127.0.0.1:5500/index.html', {
waitUntil: 'domcontentloaded'
});

let response = await page.content();
let $=cheerio.load(response);

let $ = cheerio.load(response);
await page.type('#tableDiv > div > input', 'Vaibhav', {
delay: 100
}); // Types slower, like a user
await page.click("#tableDiv > div > div > div:nth-child(1) > form > select",{delay:20});
await page.click("#tableDiv > div > div > div:nth-child(1) > form > select", {
delay: 20
});
await page.select('#tableDiv > div > div > div:nth-child(1) > form > select', '50');
response = await page.content();
$=cheerio.load(response);
$ = cheerio.load(response);
checkOption50($);
await page.click("body",{delay:20});
await page.click("body", {
delay: 20
});
await autoScroll(page);
await page.click("#loadMore",{delay:20});
await page.click("#loadMore", {
delay: 20
});
await autoScroll(page);
await page.click("#loadMore",{delay:20});
await page.click("#loadMore", {
delay: 20
});
await autoScroll(page);
await page.click("#loadMore",{delay:20});
await page.click("#loadMore", {
delay: 20
});
await page.select('#tableDiv > div > div > div:nth-child(1) > form > select', '100');
response = await page.content();
$=cheerio.load(response);
$ = cheerio.load(response);
checkOption100($);
await page.click("body",{delay:20});
await page.click("body", {
delay: 20
});
await autoScroll(page);
await page.click("#loadMore",{delay:20});
await page.click("#loadMore", {
delay: 20
});
await page.select('#tableDiv > div > div > div:nth-child(1) > form > select', '250');
response = await page.content();
$=cheerio.load(response);
$ = cheerio.load(response);
checkOption250($);
await page.click("body",{delay:20});
await page.click("body", {
delay: 20
});
await autoScroll(page);
await page.select('#tableDiv > div > div > div:nth-child(1) > form > select', 'all');
response = await page.content();
$=cheerio.load(response);
$ = cheerio.load(response);
checkOptionAll($);
await page.click("body",{delay:20});
await page.click("body", {
delay: 20
});
})();

0 comments on commit c390d54

Please sign in to comment.