2019-06-06 16:47:10 +08:00
|
|
|
import selectKit from "helpers/select-kit-helper";
|
2018-06-16 00:42:20 +08:00
|
|
|
import componentTest from "helpers/component-test";
|
|
|
|
import Topic from "discourse/models/topic";
|
2018-06-13 01:17:43 +08:00
|
|
|
|
|
|
|
const buildTopic = function(archetype) {
|
|
|
|
return Topic.create({
|
|
|
|
id: 4563,
|
|
|
|
title: "Qunit Test Topic",
|
|
|
|
details: {
|
|
|
|
notification_level: 1
|
|
|
|
},
|
2019-01-10 18:06:01 +08:00
|
|
|
archetype
|
2018-06-13 01:17:43 +08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
function extractDescs(rows) {
|
2018-06-16 00:42:20 +08:00
|
|
|
return Array.from(
|
|
|
|
rows.find(".desc").map(function() {
|
|
|
|
return this.textContent.trim();
|
|
|
|
})
|
|
|
|
);
|
2018-06-13 01:17:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function getTranslations(type = "") {
|
|
|
|
return ["watching", "tracking", "regular", "muted"].map(key => {
|
|
|
|
return I18n.t(`topic.notifications.${key}${type}.description`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-16 00:42:20 +08:00
|
|
|
moduleForComponent("topic-notifications-options", { integration: true });
|
2018-06-13 01:17:43 +08:00
|
|
|
|
2018-06-16 00:42:20 +08:00
|
|
|
componentTest("regular topic notification level descriptions", {
|
|
|
|
template:
|
|
|
|
"{{topic-notifications-options value=topic.details.notification_level topic=topic}}",
|
2018-06-13 01:17:43 +08:00
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
async test(assert) {
|
2018-07-30 04:51:32 +08:00
|
|
|
await selectKit().expand();
|
2018-07-25 02:12:09 +08:00
|
|
|
await this.set("topic", buildTopic("regular"));
|
2018-06-13 01:17:43 +08:00
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
const uiTexts = extractDescs(selectKit().rows());
|
|
|
|
const descriptions = getTranslations();
|
2018-06-13 01:17:43 +08:00
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
assert.equal(
|
|
|
|
uiTexts.length,
|
|
|
|
descriptions.length,
|
|
|
|
"it has the correct copy"
|
|
|
|
);
|
|
|
|
uiTexts.forEach((text, index) => {
|
2018-06-16 00:42:20 +08:00
|
|
|
assert.equal(
|
2018-07-25 02:12:09 +08:00
|
|
|
text.trim(),
|
|
|
|
descriptions[index].trim(),
|
2018-06-16 00:42:20 +08:00
|
|
|
"it has the correct copy"
|
|
|
|
);
|
2018-06-13 01:17:43 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-16 00:42:20 +08:00
|
|
|
componentTest("PM topic notification level descriptions", {
|
|
|
|
template:
|
|
|
|
"{{topic-notifications-options value=topic.details.notification_level topic=topic}}",
|
2018-06-13 01:17:43 +08:00
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
async test(assert) {
|
2018-07-30 04:51:32 +08:00
|
|
|
await selectKit().expand();
|
2018-07-25 02:12:09 +08:00
|
|
|
await this.set("topic", buildTopic("private_message"));
|
2018-06-13 01:17:43 +08:00
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
const uiTexts = extractDescs(selectKit().rows());
|
|
|
|
const descriptions = getTranslations("_pm");
|
2018-06-13 01:17:43 +08:00
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
assert.equal(
|
|
|
|
uiTexts.length,
|
|
|
|
descriptions.length,
|
|
|
|
"it has the correct copy"
|
|
|
|
);
|
2019-01-10 18:06:01 +08:00
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
uiTexts.forEach((text, index) => {
|
2018-06-16 00:42:20 +08:00
|
|
|
assert.equal(
|
2018-07-25 02:12:09 +08:00
|
|
|
text.trim(),
|
|
|
|
descriptions[index].trim(),
|
2018-06-16 00:42:20 +08:00
|
|
|
"it has the correct copy"
|
|
|
|
);
|
2018-06-13 01:17:43 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|