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