mirror of
https://github.com/discourse/discourse.git
synced 2025-04-16 19:31:29 +08:00
add JS tests
This commit is contained in:
parent
06777aa47d
commit
629a2fbc2b
@ -0,0 +1,65 @@
|
||||
import componentTest from 'helpers/component-test';
|
||||
import Topic from 'discourse/models/topic';
|
||||
|
||||
const buildTopic = function(archetype) {
|
||||
return Topic.create({
|
||||
id: 4563,
|
||||
title: "Qunit Test Topic",
|
||||
details: {
|
||||
notification_level: 1
|
||||
},
|
||||
archetype: archetype
|
||||
});
|
||||
};
|
||||
|
||||
function extractDescs(rows) {
|
||||
return Array.from(rows.find(".desc").map(function() {
|
||||
return this.textContent.trim();
|
||||
}));
|
||||
}
|
||||
|
||||
function getTranslations(type = "") {
|
||||
return ["watching", "tracking", "regular", "muted"].map(key => {
|
||||
return I18n.t(`topic.notifications.${key}${type}.description`);
|
||||
});
|
||||
}
|
||||
|
||||
moduleForComponent('topic-notifications-options', { integration: true });
|
||||
|
||||
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"));
|
||||
|
||||
andThen(() => {
|
||||
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(text.trim(), descriptions[index].trim(), "it has the correct copy");
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
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"));
|
||||
|
||||
andThen(() => {
|
||||
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(text.trim(), descriptions[index].trim(), "it has the correct copy");
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user