Antonio-Maranhao closed pull request #1001: Fix table mode to show boolean 
values
URL: https://github.com/apache/couchdb-fauxton/pull/1001
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/app/addons/documents/__tests__/table-row.test.js 
b/app/addons/documents/__tests__/table-row.test.js
new file mode 100644
index 000000000..b2636c8f4
--- /dev/null
+++ b/app/addons/documents/__tests__/table-row.test.js
@@ -0,0 +1,58 @@
+// Licensed 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.
+import FauxtonAPI from "../../../core/api";
+import TableRow from "../index-results/components/results/TableRow";
+import utils from "../../../../test/mocha/testUtils";
+import React from "react";
+import ReactDOM from "react-dom";
+import sinon from "sinon";
+import { shallow } from 'enzyme';
+
+FauxtonAPI.router = new FauxtonAPI.Router([]);
+const { assert } = utils;
+
+describe('Docs Table Row', () => {
+
+  it('all types of value are converted to the appropriate text for display', 
() => {
+    const elem = {
+      content: {
+        _id: "123",
+        vBool: true,
+        vString: 'abc',
+        vFloat: 123.1234,
+        vInt: 123,
+        vObject: { f1: 1, f2: 'b'},
+      },
+      id: "123"
+    };
+
+    const data = {
+      selectedFields: ['vBool', 'vString', 'vFloat', 'vInt', 'vObject']
+    };
+    const wrapper = shallow(<TableRow
+      onClick={sinon.stub()}
+      docChecked={sinon.stub()}
+      isSelected={sinon.stub()}
+      el={elem}
+      data={data}
+      index={0}
+      docIdentifier={elem.id}
+      isSelected={false}
+    />);
+
+    assert.equal(wrapper.find('td').at(2).text(), 
JSON.stringify(elem.content.vBool));
+    assert.equal(wrapper.find('td').at(3).text(), elem.content.vString);
+    assert.equal(wrapper.find('td').at(4).text(), 
JSON.stringify(elem.content.vFloat));
+    assert.equal(wrapper.find('td').at(5).text(), 
JSON.stringify(elem.content.vInt));
+    assert.equal(wrapper.find('td').at(6).text().replace(/[\s]/g, ''), 
JSON.stringify(elem.content.vObject));
+  });
+});
diff --git a/app/addons/documents/index-results/components/results/TableRow.js 
b/app/addons/documents/index-results/components/results/TableRow.js
index 6728996d6..b983d86c1 100644
--- a/app/addons/documents/index-results/components/results/TableRow.js
+++ b/app/addons/documents/index-results/components/results/TableRow.js
@@ -37,7 +37,8 @@ export default class TableRow extends React.Component {
     const row = this.props.data.selectedFields.map(function (k, i) {
 
       const key = 'tableview-data-cell-' + rowNumber + k + i + el[k];
-      const stringified = typeof el[k] === 'object' ? JSON.stringify(el[k], 
null, '  ') : el[k];
+      const stringified = ['object', 'boolean'].includes(typeof el[k]) ?
+        JSON.stringify(el[k], null, '  ') : el[k];
 
       return (
         <td key={key} title={stringified} onClick={this.onClick.bind(this)}>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to