Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add entries method for looping through table rows #413

Merged
merged 2 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"--init"
]
},
"version": "2.3.14",
"version": "2.3.15",
"gaugeVersionSupport": {
"minimum": "1.0.7",
"maximum": ""
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gauge-js",
"version": "2.3.14",
"version": "2.3.15",
"description": "JavaScript runner for Gauge",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion src/executor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var Q = require("q");
var Table = require("./table");

var factory = require("./response-factory"),
Test = require("./test"),
Expand Down Expand Up @@ -44,8 +45,9 @@ var executeStep = function (executeStepRequest) {
var parsedStepText = executeStepRequest.parsedStepText;

var parameters = executeStepRequest.parameters.map(function (item) {
return item.value ? item.value : item.table;
return item.value ? item.value : new Table(item.table);
});

var step = stepRegistry.get(parsedStepText);
new Test(step.fn, parameters, timeout).run().then(
function (result) {
Expand Down
34 changes: 10 additions & 24 deletions src/table.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
/**
{
headers: {
cells: [ 'Product', 'Description' ]
},
rows: [
{ cells: [ 'Gauge', 'Test automation with ease' ] },
{ cells: [ 'Mingle', 'Agile project management' ] },
{ cells: [ 'Snap', 'Hosted continuous integration' ] },
{ cells: [ 'Gocd', 'Continuous delivery platform' ] }
]
}
*/

var Table = function(protoTable) {
this.protoTable = protoTable;

this.headers = protoTable.headers.cells.map(function(header) {
return header;
});

this.rows = protoTable.rows.map(function(row) {
return row.cells;
});
var Table = function (protoTable) {
Object.assign(this, protoTable);

this.entries = function (callback) {
for (var row of this.rows) {
let entry = {};
row.cells.forEach((cell, index) => entry[this.headers.cells[index]] = cell);
callback(entry);
}
};
};

module.exports = Table;
30 changes: 24 additions & 6 deletions test/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,32 @@ describe("ProtoTable parsing", function() {
]
};

it("Should get headers", function() {
var table = new Table(protoTable);
expect(table.headers).to.deep.equal(["Product", "Description"]);
var table = new Table(protoTable);

it("Should get headers", function () {
expect(table.headers).to.deep.equal(protoTable.headers);
});

it("Should get rows", function () {
expect(table.rows).to.deep.equal(protoTable.rows);
});

it("Should get rows", function() {
var table = new Table(protoTable);
expect(table.rows[0]).to.deep.equal(["Gauge", "Test automation with ease"]);
describe("Table entries", function () {

it("Should have correct number of entries", function () {
var result = [];
table.entries(entry => result.push(entry));
expect(result.length).to.equal(4);
});

it("Should have correct entry object", function () {
var result = [];
table.entries(entry => result.push(entry));
expect(result[1]).to.deep.equal({
"Product": "Mingle",
"Description": "Agile project management"
});
});
});

});