From 2144e7b3bafcca1af7f8f7992982e84c199d97b5 Mon Sep 17 00:00:00 2001 From: Jan Cernik <66427541+jancernik@users.noreply.github.com> Date: Thu, 4 May 2023 19:45:43 -0300 Subject: [PATCH] FIX: Show "false" and "0" in query result (#244) --- .../discourse/components/query-row-content.js | 2 +- test/javascripts/acceptance/run-query-test.js | 62 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/components/query-row-content.js b/assets/javascripts/discourse/components/query-row-content.js index 0f95bef..ac5133f 100644 --- a/assets/javascripts/discourse/components/query-row-content.js +++ b/assets/javascripts/discourse/components/query-row-content.js @@ -26,7 +26,7 @@ export default class QueryRowContent extends Component { } else if (t.name === "text") { return { component: TextViewComponent, - textValue: escapeExpression(this.args.row[idx]), + textValue: escapeExpression(this.args.row[idx].toString()), }; } diff --git a/test/javascripts/acceptance/run-query-test.js b/test/javascripts/acceptance/run-query-test.js index 84750b4..23a20cc 100644 --- a/test/javascripts/acceptance/run-query-test.js +++ b/test/javascripts/acceptance/run-query-test.js @@ -116,6 +116,19 @@ acceptance("Data Explorer Plugin | Run Query", function (needs) { hidden: false, user_id: -1, }, + { + id: 2, + sql: 'SELECT 0 zero, null "null", false "false"', + name: "What about 0?", + description: "", + param_info: [], + created_at: "2023-05-04T22:16:06.007Z", + username: "system", + group_ids: [], + last_run_at: "2023-05-04T22:16:23.858Z", + hidden: false, + user_id: 1, + }, ], }); }); @@ -155,6 +168,21 @@ acceptance("Data Explorer Plugin | Run Query", function (needs) { ], }); }); + + server.post("/admin/plugins/explorer/queries/2/run", () => { + return helper.response({ + success: true, + errors: [], + duration: 1.0, + result_count: 1, + params: {}, + columns: ["zero", "null", "false"], + default_limit: 1000, + relations: {}, + colrender: {}, + rows: [[0, null, false]], + }); + }); }); test("it runs query and renders data and a chart", async function (assert) { @@ -190,4 +218,38 @@ acceptance("Data Explorer Plugin | Run Query", function (needs) { assert.ok(exists("canvas"), "the chart was rendered"); }); + + test("it runs query and renders 0, false, and NULL values correctly", async function (assert) { + await visit("admin/plugins/explorer?id=2"); + + assert.ok( + query("div.name h1").innerText.trim() === "What about 0?", + "the query name was rendered" + ); + + assert.ok( + query("form.query-run button span").innerText.trim() === + I18n.t("explorer.run"), + "the run button was rendered" + ); + + await click("form.query-run button"); + + assert.ok( + query("div.query-results tbody td:nth-child(1)").innerText.trim() === "0", + "renders '0' values" + ); + + assert.ok( + query("div.query-results tbody td:nth-child(2)").innerText.trim() === + "NULL", + "renders 'NULL' values" + ); + + assert.ok( + query("div.query-results tbody td:nth-child(3)").innerText.trim() === + "false", + "renders 'false' values" + ); + }); });