DEV: Make frontend tests work with ember-cli (#144)

This commit is contained in:
Jarek Radosz 2021-09-22 11:13:32 +02:00 committed by GitHub
parent 4626483514
commit 545fb426f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 98 additions and 84 deletions

View File

@ -6,6 +6,7 @@ import {
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer"; import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
import I18n from "I18n"; import I18n from "I18n";
import { test } from "qunit";
acceptance("Data Explorer Plugin | List Queries", function (needs) { acceptance("Data Explorer Plugin | List Queries", function (needs) {
needs.user(); needs.user();

View File

@ -7,6 +7,7 @@ import {
import { click, fillIn, visit } from "@ember/test-helpers"; import { click, fillIn, visit } from "@ember/test-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer"; import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
import I18n from "I18n"; import I18n from "I18n";
import { test } from "qunit";
acceptance("Data Explorer Plugin | Run Query", function (needs) { acceptance("Data Explorer Plugin | Run Query", function (needs) {
needs.user(); needs.user();

View File

@ -1,99 +1,111 @@
import { moduleFor } from "ember-qunit"; import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit"; import { test } from "qunit";
moduleFor("component:query-result"); 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: {} });
test("it transforms data for a chart", function (assert) { component.setProperties({
const results = { content: {
colrender: [], colrender: [],
result_count: 2, result_count: 2,
columns: ["user", "like_count"], columns: ["user", "like_count"],
rows: [ rows: [
["user1", 10], ["user1", 10],
["user2", 20], ["user2", 20],
], ],
}; },
this.subject().setProperties({ });
content: results,
assert.deepEqual(
component.chartLabels,
["user1", "user2"],
"labels are correct"
);
assert.deepEqual(component.chartValues, [10, 20], "values are correct");
assert.deepEqual(
component.chartDatasetName,
"like_count",
"the dataset name is correct"
);
}); });
assert.deepEqual( test("it uses descriptive chart labels instead of identifiers", function (assert) {
this.subject().chartLabels, const component = this.container
["user1", "user2"], .factoryFor("component:query-result")
"labels are correct" .create({ renderer: {} });
);
assert.deepEqual(this.subject().chartValues, [10, 20], "values are correct"); 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],
],
},
});
assert.deepEqual( assert.deepEqual(component.chartLabels, ["user1", "user2"]);
this.subject().chartDatasetName,
"like_count",
"the dataset name is correct"
);
});
test("it uses descriptive chart labels instead of identifiers", function (assert) {
const results = {
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],
],
};
this.subject().setProperties({
content: results,
}); });
assert.deepEqual(this.subject().chartLabels, ["user1", "user2"]); 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: {} });
test("it uses an identifier as a chart label if labelSelector doesn't exist", function (assert) { component.setProperties({
const results = { content: {
colrender: { 0: "unknown_entity" }, colrender: { 0: "unknown_entity" },
relations: { relations: {
unknown_entity: [ unknown_entity: [
{ id: 1, username: "user1" }, { id: 1, username: "user1" },
{ id: 2, username: "user2" }, { id: 2, username: "user2" },
], ],
}, },
result_count: 2, result_count: 2,
columns: ["user", "like_count"], columns: ["user", "like_count"],
rows: [ rows: [
[1, 10], [1, 10],
[2, 20], [2, 20],
], ],
}; },
this.subject().setProperties({ });
content: results,
assert.deepEqual(component.chartLabels, ["1", "2"]);
}); });
assert.deepEqual(this.subject().chartLabels, ["1", "2"]); test("it cuts too long chart labels", function (assert) {
}); const component = this.container
.factoryFor("component:query-result")
.create({ renderer: {} });
test("it cuts too long chart labels", function (assert) { component.setProperties({
const results = { content: {
colrender: [], colrender: [],
result_count: 2, result_count: 2,
columns: ["user", "like_count"], columns: ["user", "like_count"],
rows: [ 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", 10],
["This string is too long to be used as a label on a chart", 20], ["This string is too long to be used as a label on a chart", 20],
], ],
}; },
this.subject().setProperties({ });
content: results,
assert.deepEqual(component.chartLabels, [
"This string is too long t...",
"This string is too long t...",
]);
}); });
assert.deepEqual(this.subject().chartLabels, [
"This string is too long t...",
"This string is too long t...",
]);
}); });