DEV: migrate components tests to async/await

This commit is contained in:
Maja Komel
2018-07-24 20:12:09 +02:00
parent c0992a4d31
commit d16a2c776a
10 changed files with 619 additions and 615 deletions

View File

@ -7,73 +7,69 @@ moduleForComponent("admin-report", {
componentTest("default", {
template: "{{admin-report dataSourceName='signups'}}",
test(assert) {
andThen(() => {
assert.ok(exists(".admin-report.signups"));
async test(assert) {
assert.ok(exists(".admin-report.signups"));
assert.ok(
exists(".admin-report.table.signups", "it defaults to table mode")
);
assert.ok(
exists(".admin-report.table.signups", "it defaults to table mode")
);
assert.equal(
find(".report-header .title")
.text()
.trim(),
"Signups",
"it has a title"
);
assert.equal(
find(".report-header .title")
.text()
.trim(),
"Signups",
"it has a title"
);
assert.equal(
find(".report-header .info").attr("data-tooltip"),
"New account registrations for this period",
"it has a description"
);
assert.equal(
find(".report-header .info").attr("data-tooltip"),
"New account registrations for this period",
"it has a description"
);
assert.equal(
find(".report-body .report-table thead tr th:first-child")
.text()
.trim(),
"Day",
"it has col headers"
);
assert.equal(
find(".report-body .report-table thead tr th:first-child")
.text()
.trim(),
"Day",
"it has col headers"
);
assert.equal(
find(".report-body .report-table thead tr th:nth-child(2)")
.text()
.trim(),
"Count",
"it has col headers"
);
assert.equal(
find(".report-body .report-table thead tr th:nth-child(2)")
.text()
.trim(),
"Count",
"it has col headers"
);
assert.equal(
find(".report-body .report-table tbody tr:nth-child(1) td:nth-child(1)")
.text()
.trim(),
"June 16, 2018",
"it has rows"
);
assert.equal(
find(".report-body .report-table tbody tr:nth-child(1) td:nth-child(1)")
.text()
.trim(),
"June 16, 2018",
"it has rows"
);
assert.equal(
find(".report-body .report-table tbody tr:nth-child(1) td:nth-child(2)")
.text()
.trim(),
"12",
"it has rows"
);
assert.equal(
find(".report-body .report-table tbody tr:nth-child(1) td:nth-child(2)")
.text()
.trim(),
"12",
"it has rows"
);
assert.ok(exists(".totals-sample-table"), "it has totals");
});
assert.ok(exists(".totals-sample-table"), "it has totals");
click(".admin-report-table-header.y .sort-button");
andThen(() => {
assert.equal(
find(".report-body .report-table tbody tr:nth-child(1) td:nth-child(2)")
.text()
.trim(),
"7",
"it can sort rows"
);
});
await click(".admin-report-table-header.y .sort-button");
assert.equal(
find(".report-body .report-table tbody tr:nth-child(1) td:nth-child(2)")
.text()
.trim(),
"7",
"it can sort rows"
);
}
});
@ -90,32 +86,25 @@ componentTest("options", {
},
test(assert) {
andThen(() => {
assert.ok(exists(".pagination"), "it paginates the results");
assert.equal(
find(".pagination button").length,
3,
"it creates the correct number of pages"
);
assert.ok(exists(".pagination"), "it paginates the results");
assert.equal(
find(".pagination button").length,
3,
"it creates the correct number of pages"
);
assert.notOk(exists(".totals-sample-table"), "it hides totals");
});
assert.notOk(exists(".totals-sample-table"), "it hides totals");
}
});
componentTest("switch modes", {
template: "{{admin-report dataSourceName='signups'}}",
test(assert) {
click(".mode-button.chart");
async test(assert) {
await click(".mode-button.chart");
andThen(() => {
assert.notOk(
exists(".admin-report.table.signups"),
"it removes the table"
);
assert.ok(exists(".admin-report.chart.signups"), "it shows the chart");
});
assert.notOk(exists(".admin-report.table.signups"), "it removes the table");
assert.ok(exists(".admin-report.chart.signups"), "it shows the chart");
}
});
@ -123,8 +112,6 @@ componentTest("timeout", {
template: "{{admin-report dataSourceName='signups_timeout'}}",
test(assert) {
andThen(() => {
assert.ok(exists(".alert-error"), "it displays a timeout error");
});
assert.ok(exists(".alert-error"), "it displays a timeout error");
}
});

View File

@ -4,16 +4,14 @@ moduleForComponent("categories-admin-dropdown", { integration: true });
componentTest("default", {
template: "{{categories-admin-dropdown}}",
test(assert) {
async test(assert) {
const subject = selectKit();
assert.equal(subject.el().find(".d-icon-bars").length, 1);
assert.equal(subject.el().find(".d-icon-caret-down").length, 1);
subject.expand();
await subject.expandAwait();
andThen(() => {
assert.equal(subject.rowByValue("create").name(), "New Category");
});
assert.equal(subject.rowByValue("create").name(), "New Category");
}
});

View File

@ -11,35 +11,31 @@ componentTest("with value", {
template: "{{category-chooser value=2}}",
test(assert) {
andThen(() => {
assert.equal(
this.get("subject")
.header()
.value(),
2
);
assert.equal(
this.get("subject")
.header()
.title(),
"feature"
);
});
assert.equal(
this.get("subject")
.header()
.value(),
2
);
assert.equal(
this.get("subject")
.header()
.title(),
"feature"
);
}
});
componentTest("with excludeCategoryId", {
template: "{{category-chooser excludeCategoryId=2}}",
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expandAwait();
andThen(() =>
assert.notOk(
this.get("subject")
.rowByValue(2)
.exists()
)
assert.notOk(
this.get("subject")
.rowByValue(2)
.exists()
);
}
});
@ -47,36 +43,34 @@ componentTest("with excludeCategoryId", {
componentTest("with scopedCategoryId", {
template: "{{category-chooser scopedCategoryId=2}}",
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expandAwait();
andThen(() => {
assert.equal(
this.get("subject")
.rowByIndex(0)
.title(),
"Discussion about features or potential features of Discourse: how they work, why they work, etc."
);
assert.equal(
this.get("subject")
.rowByIndex(0)
.value(),
2
);
assert.equal(
this.get("subject")
.rowByIndex(1)
.title(),
"My idea here is to have mini specs for features we would like built but have no bandwidth to build"
);
assert.equal(
this.get("subject")
.rowByIndex(1)
.value(),
26
);
assert.equal(this.get("subject").rows().length, 2);
});
assert.equal(
this.get("subject")
.rowByIndex(0)
.title(),
"Discussion about features or potential features of Discourse: how they work, why they work, etc."
);
assert.equal(
this.get("subject")
.rowByIndex(0)
.value(),
2
);
assert.equal(
this.get("subject")
.rowByIndex(1)
.title(),
"My idea here is to have mini specs for features we would like built but have no bandwidth to build"
);
assert.equal(
this.get("subject")
.rowByIndex(1)
.value(),
26
);
assert.equal(this.get("subject").rows().length, 2);
}
});
@ -88,20 +82,18 @@ componentTest("with allowUncategorized=null", {
},
test(assert) {
andThen(() => {
assert.equal(
this.get("subject")
.header()
.value(),
null
);
assert.equal(
this.get("subject")
.header()
.title(),
"category"
);
});
assert.equal(
this.get("subject")
.header()
.value(),
null
);
assert.equal(
this.get("subject")
.header()
.title(),
"category"
);
}
});
@ -113,20 +105,18 @@ componentTest("with allowUncategorized=null rootNone=true", {
},
test(assert) {
andThen(() => {
assert.equal(
this.get("subject")
.header()
.value(),
null
);
assert.equal(
this.get("subject")
.header()
.title(),
"category"
);
});
assert.equal(
this.get("subject")
.header()
.value(),
null
);
assert.equal(
this.get("subject")
.header()
.title(),
"category"
);
}
});
@ -140,20 +130,18 @@ componentTest("with disallowed uncategorized, rootNone and rootNoneLabel", {
},
test(assert) {
andThen(() => {
assert.equal(
this.get("subject")
.header()
.value(),
null
);
assert.equal(
this.get("subject")
.header()
.title(),
"category"
);
});
assert.equal(
this.get("subject")
.header()
.value(),
null
);
assert.equal(
this.get("subject")
.header()
.title(),
"category"
);
}
});
@ -165,20 +153,18 @@ componentTest("with allowed uncategorized", {
},
test(assert) {
andThen(() => {
assert.equal(
this.get("subject")
.header()
.value(),
null
);
assert.equal(
this.get("subject")
.header()
.title(),
"uncategorized"
);
});
assert.equal(
this.get("subject")
.header()
.value(),
null
);
assert.equal(
this.get("subject")
.header()
.title(),
"uncategorized"
);
}
});
@ -190,20 +176,18 @@ componentTest("with allowed uncategorized and rootNone", {
},
test(assert) {
andThen(() => {
assert.equal(
this.get("subject")
.header()
.value(),
null
);
assert.equal(
this.get("subject")
.header()
.title(),
"(no category)"
);
});
assert.equal(
this.get("subject")
.header()
.value(),
null
);
assert.equal(
this.get("subject")
.header()
.title(),
"(no category)"
);
}
});
@ -217,19 +201,17 @@ componentTest("with allowed uncategorized rootNone and rootNoneLabel", {
},
test(assert) {
andThen(() => {
assert.equal(
this.get("subject")
.header()
.value(),
null
);
assert.equal(
this.get("subject")
.header()
.title(),
"root none label"
);
});
assert.equal(
this.get("subject")
.header()
.value(),
null
);
assert.equal(
this.get("subject")
.header()
.title(),
"root none label"
);
}
});

View File

@ -12,29 +12,27 @@ componentTest("default", {
this.set("items", [{ id: 1, name: "hello" }, { id: 2, name: "world" }]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expandAwait();
andThen(() => {
assert.equal(
this.get("subject")
.header()
.name(),
"hello"
);
assert.equal(
this.get("subject")
.rowByValue(1)
.name(),
"hello"
);
assert.equal(
this.get("subject")
.rowByValue(2)
.name(),
"world"
);
});
assert.equal(
this.get("subject")
.header()
.name(),
"hello"
);
assert.equal(
this.get("subject")
.rowByValue(1)
.name(),
"hello"
);
assert.equal(
this.get("subject")
.rowByValue(2)
.name(),
"world"
);
}
});
@ -47,23 +45,21 @@ componentTest("with valueAttribute", {
]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expandAwait();
andThen(() => {
assert.equal(
this.get("subject")
.rowByValue(0)
.name(),
"hello"
);
assert.equal(
this.get("subject")
.rowByValue(1)
.name(),
"world"
);
});
assert.equal(
this.get("subject")
.rowByValue(0)
.name(),
"hello"
);
assert.equal(
this.get("subject")
.rowByValue(1)
.name(),
"world"
);
}
});
@ -73,23 +69,21 @@ componentTest("with nameProperty", {
this.set("items", [{ id: 0, text: "hello" }, { id: 1, text: "world" }]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expandAwait();
andThen(() => {
assert.equal(
this.get("subject")
.rowByValue(0)
.name(),
"hello"
);
assert.equal(
this.get("subject")
.rowByValue(1)
.name(),
"world"
);
});
assert.equal(
this.get("subject")
.rowByValue(0)
.name(),
"hello"
);
assert.equal(
this.get("subject")
.rowByValue(1)
.name(),
"world"
);
}
});
@ -99,23 +93,21 @@ componentTest("with an array as content", {
this.set("items", ["evil", "trout", "hat"]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expandAwait();
andThen(() => {
assert.equal(
this.get("subject")
.rowByValue("evil")
.name(),
"evil"
);
assert.equal(
this.get("subject")
.rowByValue("trout")
.name(),
"trout"
);
});
assert.equal(
this.get("subject")
.rowByValue("evil")
.name(),
"evil"
);
assert.equal(
this.get("subject")
.rowByValue("trout")
.name(),
"trout"
);
}
});
@ -127,42 +119,38 @@ componentTest("with value and none as a string", {
this.set("value", "trout");
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expandAwait();
andThen(() => {
assert.equal(
this.get("subject")
.noneRow()
.name(),
"none"
);
assert.equal(
this.get("subject")
.rowByValue("evil")
.name(),
"evil"
);
assert.equal(
this.get("subject")
.rowByValue("trout")
.name(),
"trout"
);
assert.equal(
this.get("subject")
.header()
.name(),
"trout"
);
assert.equal(this.get("value"), "trout");
});
assert.equal(
this.get("subject")
.noneRow()
.name(),
"none"
);
assert.equal(
this.get("subject")
.rowByValue("evil")
.name(),
"evil"
);
assert.equal(
this.get("subject")
.rowByValue("trout")
.name(),
"trout"
);
assert.equal(
this.get("subject")
.header()
.name(),
"trout"
);
assert.equal(this.get("value"), "trout");
this.get("subject").selectNoneRow();
await this.get("subject").selectNoneRowAwait();
andThen(() => {
assert.equal(this.get("value"), null);
});
assert.equal(this.get("value"), null);
}
});
@ -174,42 +162,38 @@ componentTest("with value and none as an object", {
this.set("value", "evil");
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() => {
assert.equal(
this.get("subject")
.noneRow()
.name(),
"none"
);
assert.equal(
this.get("subject")
.rowByValue("evil")
.name(),
"evil"
);
assert.equal(
this.get("subject")
.rowByValue("trout")
.name(),
"trout"
);
assert.equal(
this.get("subject")
.header()
.name(),
"evil"
);
assert.equal(this.get("value"), "evil");
});
assert.equal(
this.get("subject")
.noneRow()
.name(),
"none"
);
assert.equal(
this.get("subject")
.rowByValue("evil")
.name(),
"evil"
);
assert.equal(
this.get("subject")
.rowByValue("trout")
.name(),
"trout"
);
assert.equal(
this.get("subject")
.header()
.name(),
"evil"
);
assert.equal(this.get("value"), "evil");
this.get("subject").selectNoneRow();
await this.get("subject").selectNoneRowAwait();
andThen(() => {
assert.equal(this.get("value"), null);
});
assert.equal(this.get("value"), null);
}
});
@ -222,17 +206,15 @@ componentTest("with no value and none as an object", {
this.set("value", null);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expandAwait();
andThen(() => {
assert.equal(
this.get("subject")
.header()
.name(),
"none"
);
});
assert.equal(
this.get("subject")
.header()
.name(),
"none"
);
}
});
@ -245,17 +227,15 @@ componentTest("with no value and none string", {
this.set("value", null);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expandAwait();
andThen(() => {
assert.equal(
this.get("subject")
.header()
.name(),
"none"
);
});
assert.equal(
this.get("subject")
.header()
.name(),
"none"
);
}
});
@ -266,18 +246,16 @@ componentTest("with no value and no none", {
this.set("value", null);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expandAwait();
andThen(() => {
assert.equal(
this.get("subject")
.header()
.name(),
"evil",
"it sets the first row as value"
);
});
assert.equal(
this.get("subject")
.header()
.name(),
"evil",
"it sets the first row as value"
);
}
});
@ -288,18 +266,16 @@ componentTest("with empty string as value", {
this.set("value", "");
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() => {
assert.equal(
this.get("subject")
.header()
.name(),
"evil",
"it sets the first row as value"
);
});
assert.equal(
this.get("subject")
.header()
.name(),
"evil",
"it sets the first row as value"
);
}
});
@ -312,17 +288,15 @@ componentTest("with noneLabel", {
this.set("noneLabel", "test.none");
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expandAwait();
andThen(() => {
assert.equal(
this.get("subject")
.header()
.name(),
"none",
"it displays noneLabel as the header name"
);
});
assert.equal(
this.get("subject")
.header()
.name(),
"none",
"it displays noneLabel as the header name"
);
}
});

View File

@ -26,25 +26,21 @@ componentTest("updating the content refreshes the list", {
this.set("pinned", true);
},
test(assert) {
andThen(() => {
assert.equal(
this.get("subject")
.header()
.name(),
"pinned"
);
});
async test(assert) {
assert.equal(
this.get("subject")
.header()
.name(),
"pinned"
);
andThen(() => this.set("pinned", false));
await this.set("pinned", false);
andThen(() => {
assert.equal(
this.get("subject")
.header()
.name(),
"unpinned"
);
});
assert.equal(
this.get("subject")
.header()
.name(),
"unpinned"
);
}
});

View File

@ -21,46 +21,42 @@ componentTest("default", {
this.set("topic", buildTopic());
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expandAwait();
andThen(() => {
assert.equal(
this.get("subject")
.header()
.title(),
"Topic Controls"
);
assert.equal(
this.get("subject")
.header()
.value(),
null
);
assert.equal(
this.get("subject")
.rowByIndex(0)
.name(),
"Bookmark"
);
assert.equal(
this.get("subject")
.rowByIndex(1)
.name(),
"Share"
);
assert.notOk(
this.get("subject")
.selectedRow()
.exists(),
"it doesn’t preselect first row"
);
});
assert.equal(
this.get("subject")
.header()
.title(),
"Topic Controls"
);
assert.equal(
this.get("subject")
.header()
.value(),
null
);
assert.equal(
this.get("subject")
.rowByIndex(0)
.name(),
"Bookmark"
);
assert.equal(
this.get("subject")
.rowByIndex(1)
.name(),
"Share"
);
assert.notOk(
this.get("subject")
.selectedRow()
.exists(),
"it doesn’t preselect first row"
);
this.get("subject").selectRowByValue("share");
await this.get("subject").selectRowByValueAwait("share");
andThen(() => {
assert.equal(this.get("value"), null, "it resets the value");
});
assert.equal(this.get("value"), null, "it resets the value");
}
});

View File

@ -31,28 +31,24 @@ componentTest("the header has a localized title", {
this.set("topic", buildTopic(1));
},
test(assert) {
andThen(() => {
assert.equal(
selectKit()
.header()
.name(),
"Normal",
"it has the correct title"
);
});
async test(assert) {
assert.equal(
selectKit()
.header()
.name(),
"Normal",
"it has the correct title"
);
this.set("topic", buildTopic(2));
await this.set("topic", buildTopic(2));
andThen(() => {
assert.equal(
selectKit()
.header()
.name(),
"Tracking",
"it correctly changes the title"
);
});
assert.equal(
selectKit()
.header()
.name(),
"Tracking",
"it correctly changes the title"
);
}
});
@ -66,14 +62,12 @@ componentTest("the header has a localized title", {
},
test(assert) {
andThen(() => {
assert.equal(
selectKit()
.header()
.name(),
`${originalTranslation} PM`,
"it has the correct title for PMs"
);
});
assert.equal(
selectKit()
.header()
.name(),
`${originalTranslation} PM`,
"it has the correct title for PMs"
);
}
});

View File

@ -32,26 +32,24 @@ componentTest("regular topic notification level descriptions", {
template:
"{{topic-notifications-options value=topic.details.notification_level topic=topic}}",
test(assert) {
selectKit().expand();
this.set("topic", buildTopic("regular"));
async test(assert) {
await selectKit().expandAwait();
await this.set("topic", buildTopic("regular"));
andThen(() => {
const uiTexts = extractDescs(selectKit().rows());
const descriptions = getTranslations();
const uiTexts = extractDescs(selectKit().rows());
const descriptions = getTranslations();
assert.equal(
uiTexts.length,
descriptions.length,
"it has the correct copy"
);
uiTexts.forEach((text, index) => {
assert.equal(
uiTexts.length,
descriptions.length,
text.trim(),
descriptions[index].trim(),
"it has the correct copy"
);
uiTexts.forEach((text, index) => {
assert.equal(
text.trim(),
descriptions[index].trim(),
"it has the correct copy"
);
});
});
}
});
@ -60,26 +58,24 @@ componentTest("PM topic notification level descriptions", {
template:
"{{topic-notifications-options value=topic.details.notification_level topic=topic}}",
test(assert) {
selectKit().expand();
this.set("topic", buildTopic("private_message"));
async test(assert) {
await selectKit().expandAwait();
await this.set("topic", buildTopic("private_message"));
andThen(() => {
const uiTexts = extractDescs(selectKit().rows());
const descriptions = getTranslations("_pm");
const uiTexts = extractDescs(selectKit().rows());
const descriptions = getTranslations("_pm");
assert.equal(
uiTexts.length,
descriptions.length,
"it has the correct copy"
);
uiTexts.forEach((text, index) => {
assert.equal(
uiTexts.length,
descriptions.length,
text.trim(),
descriptions[index].trim(),
"it has the correct copy"
);
uiTexts.forEach((text, index) => {
assert.equal(
text.trim(),
descriptions[index].trim(),
"it has the correct copy"
);
});
});
}
});

View File

@ -3,7 +3,7 @@ moduleForComponent("value-list", { integration: true });
componentTest("functionality", {
template: '{{value-list values=values inputType="array"}}',
test(assert) {
async test(assert) {
assert.ok(this.$(".values .value").length === 0, "it has no values");
assert.ok(this.$("input").length, "it renders the input");
assert.ok(
@ -11,29 +11,20 @@ componentTest("functionality", {
"it is disabled with no value"
);
fillIn("input", "eviltrout");
andThen(() => {
assert.ok(
!this.$(".btn-primary[disabled]").length,
"it isn't disabled anymore"
);
});
await fillIn("input", "eviltrout");
assert.ok(
!this.$(".btn-primary[disabled]").length,
"it isn't disabled anymore"
);
click(".btn-primary");
andThen(() => {
assert.equal(this.$(".values .value").length, 1, "it adds the value");
assert.equal(this.$("input").val(), "", "it clears the input");
assert.ok(
this.$(".btn-primary[disabled]").length,
"it is disabled again"
);
assert.equal(this.get("values"), "eviltrout", "it appends the value");
});
await click(".btn-primary");
assert.equal(this.$(".values .value").length, 1, "it adds the value");
assert.equal(this.$("input").val(), "", "it clears the input");
assert.ok(this.$(".btn-primary[disabled]").length, "it is disabled again");
assert.equal(this.get("values"), "eviltrout", "it appends the value");
click(".value .btn-small");
andThen(() => {
assert.ok(this.$(".values .value").length === 0, "it removes the value");
});
await click(".value .btn-small");
assert.ok(this.$(".values .value").length === 0, "it removes the value");
}
});
@ -43,16 +34,14 @@ componentTest("with string delimited values", {
this.set("valueString", "hello\nworld");
},
test(assert) {
async test(assert) {
assert.equal(this.$(".values .value").length, 2);
fillIn("input", "eviltrout");
click(".btn-primary");
await fillIn("input", "eviltrout");
await click(".btn-primary");
andThen(() => {
assert.equal(this.$(".values .value").length, 3);
assert.equal(this.get("valueString"), "hello\nworld\neviltrout");
});
assert.equal(this.$(".values .value").length, 3);
assert.equal(this.get("valueString"), "hello\nworld\neviltrout");
}
});
@ -62,15 +51,13 @@ componentTest("with array values", {
this.set("valueArray", ["abc", "def"]);
},
test(assert) {
async test(assert) {
assert.equal(this.$(".values .value").length, 2);
fillIn("input", "eviltrout");
click(".btn-primary");
await fillIn("input", "eviltrout");
await click(".btn-primary");
andThen(() => {
assert.equal(this.$(".values .value").length, 3);
assert.deepEqual(this.get("valueArray"), ["abc", "def", "eviltrout"]);
});
assert.equal(this.$(".values .value").length, 3);
assert.deepEqual(this.get("valueArray"), ["abc", "def", "eviltrout"]);
}
});