2021-09-22 05:13:32 -04:00
|
|
|
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
2021-02-18 06:06:22 -05:00
|
|
|
import { test } from "qunit";
|
|
|
|
|
2021-09-22 05:13:32 -04:00
|
|
|
discourseModule("Unit | Component | query-result", function () {
|
|
|
|
test("it transforms data for a chart", function (assert) {
|
|
|
|
const component = this.container
|
|
|
|
.factoryFor("component:query-result")
|
|
|
|
.create({ renderer: {} });
|
2021-02-18 06:06:22 -05:00
|
|
|
|
2021-09-22 05:13:32 -04:00
|
|
|
component.setProperties({
|
|
|
|
content: {
|
|
|
|
colrender: [],
|
|
|
|
result_count: 2,
|
|
|
|
columns: ["user", "like_count"],
|
|
|
|
rows: [
|
|
|
|
["user1", 10],
|
|
|
|
["user2", 20],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
2021-02-18 06:06:22 -05:00
|
|
|
|
2021-09-22 05:13:32 -04:00
|
|
|
assert.deepEqual(
|
|
|
|
component.chartLabels,
|
|
|
|
["user1", "user2"],
|
|
|
|
"labels are correct"
|
|
|
|
);
|
2021-02-18 06:06:22 -05:00
|
|
|
|
2021-09-22 05:13:32 -04:00
|
|
|
assert.deepEqual(component.chartValues, [10, 20], "values are correct");
|
2021-02-18 06:06:22 -05:00
|
|
|
|
2021-09-22 05:13:32 -04:00
|
|
|
assert.deepEqual(
|
|
|
|
component.chartDatasetName,
|
|
|
|
"like_count",
|
|
|
|
"the dataset name is correct"
|
|
|
|
);
|
2021-02-18 06:06:22 -05:00
|
|
|
});
|
|
|
|
|
2021-09-22 05:13:32 -04:00
|
|
|
test("it uses descriptive chart labels instead of identifiers", function (assert) {
|
|
|
|
const component = this.container
|
|
|
|
.factoryFor("component:query-result")
|
|
|
|
.create({ renderer: {} });
|
|
|
|
|
|
|
|
component.setProperties({
|
|
|
|
content: {
|
|
|
|
colrender: { 0: "user" },
|
|
|
|
relations: {
|
|
|
|
user: [
|
|
|
|
{ id: 1, username: "user1" },
|
|
|
|
{ id: 2, username: "user2" },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
result_count: 2,
|
|
|
|
columns: ["user", "like_count"],
|
|
|
|
rows: [
|
|
|
|
[1, 10],
|
|
|
|
[2, 20],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
2021-02-18 06:06:22 -05:00
|
|
|
|
2021-09-22 05:13:32 -04:00
|
|
|
assert.deepEqual(component.chartLabels, ["user1", "user2"]);
|
2021-02-18 06:06:22 -05:00
|
|
|
});
|
|
|
|
|
2021-09-22 05:13:32 -04:00
|
|
|
test("it uses an identifier as a chart label if labelSelector doesn't exist", function (assert) {
|
|
|
|
const component = this.container
|
|
|
|
.factoryFor("component:query-result")
|
|
|
|
.create({ renderer: {} });
|
|
|
|
|
|
|
|
component.setProperties({
|
|
|
|
content: {
|
|
|
|
colrender: { 0: "unknown_entity" },
|
|
|
|
relations: {
|
|
|
|
unknown_entity: [
|
|
|
|
{ id: 1, username: "user1" },
|
|
|
|
{ id: 2, username: "user2" },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
result_count: 2,
|
|
|
|
columns: ["user", "like_count"],
|
|
|
|
rows: [
|
|
|
|
[1, 10],
|
|
|
|
[2, 20],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
2021-02-18 06:06:22 -05:00
|
|
|
|
2021-09-22 05:13:32 -04:00
|
|
|
assert.deepEqual(component.chartLabels, ["1", "2"]);
|
2021-02-18 06:06:22 -05:00
|
|
|
});
|
|
|
|
|
2021-09-22 05:13:32 -04:00
|
|
|
test("it cuts too long chart labels", function (assert) {
|
|
|
|
const component = this.container
|
|
|
|
.factoryFor("component:query-result")
|
|
|
|
.create({ renderer: {} });
|
|
|
|
|
|
|
|
component.setProperties({
|
|
|
|
content: {
|
|
|
|
colrender: [],
|
|
|
|
result_count: 2,
|
|
|
|
columns: ["user", "like_count"],
|
|
|
|
rows: [
|
|
|
|
["This string is too long to be used as a label on a chart", 10],
|
|
|
|
["This string is too long to be used as a label on a chart", 20],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.deepEqual(component.chartLabels, [
|
|
|
|
"This string is too long t...",
|
|
|
|
"This string is too long t...",
|
|
|
|
]);
|
|
|
|
});
|
2021-02-18 06:06:22 -05:00
|
|
|
});
|