mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 04:53:51 +08:00
c2fd9d5116
This would need even more test which are being created in a separate branch.
291 lines
7.6 KiB
JavaScript
291 lines
7.6 KiB
JavaScript
import componentTest, {
|
|
setupRenderingTest,
|
|
} from "discourse/tests/helpers/component-test";
|
|
import hbs from "htmlbars-inline-precompile";
|
|
import fabricators from "../helpers/fabricators";
|
|
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
|
import pretender from "discourse/tests/helpers/create-pretender";
|
|
import { CHATABLE_TYPES } from "discourse/plugins/chat/discourse/models/chat-channel";
|
|
import { module } from "qunit";
|
|
|
|
function membershipFixture(id, options = {}) {
|
|
options = Object.assign(
|
|
{},
|
|
{
|
|
muted: false,
|
|
following: true,
|
|
},
|
|
options
|
|
);
|
|
|
|
return {
|
|
following: options.following,
|
|
muted: options.muted,
|
|
desktop_notification_level: "mention",
|
|
mobile_notification_level: "mention",
|
|
chat_channel_id: id,
|
|
chatable_type: "Category",
|
|
user_count: 2,
|
|
};
|
|
}
|
|
|
|
module(
|
|
"Discourse Chat | Component | chat-channel-settings-view | Public channel - regular user",
|
|
function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
componentTest("saving desktop notifications", {
|
|
template: hbs`{{chat-channel-settings-view channel=channel}}`,
|
|
|
|
beforeEach() {
|
|
this.set("channel", fabricators.chatChannel());
|
|
},
|
|
|
|
async test(assert) {
|
|
pretender.put(
|
|
`/chat/api/chat_channels/${this.channel.id}/notifications_settings.json`,
|
|
() => {
|
|
return [
|
|
200,
|
|
{ "Content-Type": "application/json" },
|
|
membershipFixture(this.channel.id),
|
|
];
|
|
}
|
|
);
|
|
|
|
const sk = selectKit(
|
|
".channel-settings-view__desktop-notification-level-selector"
|
|
);
|
|
await sk.expand();
|
|
await sk.selectRowByValue("mention");
|
|
|
|
assert.equal(sk.header().value(), "mention");
|
|
},
|
|
});
|
|
|
|
componentTest("saving mobile notifications", {
|
|
template: hbs`{{chat-channel-settings-view channel=channel}}`,
|
|
|
|
beforeEach() {
|
|
this.set("channel", fabricators.chatChannel());
|
|
},
|
|
|
|
async test(assert) {
|
|
pretender.put(
|
|
`/chat/api/chat_channels/${this.channel.id}/notifications_settings.json`,
|
|
() => {
|
|
return [
|
|
200,
|
|
{ "Content-Type": "application/json" },
|
|
membershipFixture(this.channel.id),
|
|
];
|
|
}
|
|
);
|
|
|
|
const sk = selectKit(
|
|
".channel-settings-view__mobile-notification-level-selector"
|
|
);
|
|
await sk.expand();
|
|
await sk.selectRowByValue("mention");
|
|
|
|
assert.equal(sk.header().value(), "mention");
|
|
},
|
|
});
|
|
|
|
componentTest("muted", {
|
|
template: hbs`{{chat-channel-settings-view channel=channel}}`,
|
|
|
|
beforeEach() {
|
|
this.set("channel", fabricators.chatChannel());
|
|
},
|
|
|
|
async test(assert) {
|
|
pretender.put(
|
|
`/chat/api/chat_channels/${this.channel.id}/notifications_settings.json`,
|
|
() => {
|
|
return [
|
|
200,
|
|
{ "Content-Type": "application/json" },
|
|
membershipFixture(this.channel.id, { muted: false }),
|
|
];
|
|
}
|
|
);
|
|
|
|
const sk = selectKit(".channel-settings-view__muted-selector");
|
|
await sk.expand();
|
|
await sk.selectRowByName("Off");
|
|
|
|
assert.equal(sk.header().value(), "false");
|
|
},
|
|
});
|
|
|
|
componentTest("hide channel wide mentions", {
|
|
template: hbs`{{chat-channel-settings-view channel=channel}}`,
|
|
|
|
beforeEach() {
|
|
this.set("channel", fabricators.chatChannel());
|
|
},
|
|
|
|
async test(assert) {
|
|
assert
|
|
.dom(".channel-settings-view__channel-wide-mentions-selector")
|
|
.doesNotExist();
|
|
},
|
|
});
|
|
|
|
componentTest("hide channel auto join", {
|
|
template: hbs`{{chat-channel-settings-view channel=channel}}`,
|
|
|
|
beforeEach() {
|
|
this.set("channel", fabricators.chatChannel());
|
|
},
|
|
|
|
async test(assert) {
|
|
assert.dom(".channel-settings-view__auto-join-selector").doesNotExist();
|
|
},
|
|
});
|
|
}
|
|
);
|
|
|
|
module(
|
|
"Discourse Chat | Component | chat-channel-settings-view | Direct Message channel - regular user",
|
|
function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
componentTest("saving desktop notifications", {
|
|
template: hbs`{{chat-channel-settings-view channel=channel}}`,
|
|
|
|
beforeEach() {
|
|
this.set(
|
|
"channel",
|
|
fabricators.chatChannel({
|
|
chatable_type: CHATABLE_TYPES.directMessageChannel,
|
|
})
|
|
);
|
|
},
|
|
|
|
async test(assert) {
|
|
pretender.put(
|
|
`/chat/api/chat_channels/${this.channel.id}/notifications_settings.json`,
|
|
() => {
|
|
return [
|
|
200,
|
|
{ "Content-Type": "application/json" },
|
|
membershipFixture(this.channel.id),
|
|
];
|
|
}
|
|
);
|
|
|
|
const sk = selectKit(
|
|
".channel-settings-view__desktop-notification-level-selector"
|
|
);
|
|
await sk.expand();
|
|
await sk.selectRowByValue("mention");
|
|
|
|
assert.equal(sk.header().value(), "mention");
|
|
},
|
|
});
|
|
|
|
componentTest("saving mobile notifications", {
|
|
template: hbs`{{chat-channel-settings-view channel=channel}}`,
|
|
|
|
beforeEach() {
|
|
this.set(
|
|
"channel",
|
|
fabricators.chatChannel({
|
|
chatable_type: CHATABLE_TYPES.directMessageChannel,
|
|
})
|
|
);
|
|
},
|
|
async test(assert) {
|
|
pretender.put(
|
|
`/chat/api/chat_channels/${this.channel.id}/notifications_settings.json`,
|
|
() => {
|
|
return [
|
|
200,
|
|
{ "Content-Type": "application/json" },
|
|
membershipFixture(this.channel.id),
|
|
];
|
|
}
|
|
);
|
|
|
|
const sk = selectKit(
|
|
".channel-settings-view__mobile-notification-level-selector"
|
|
);
|
|
await sk.expand();
|
|
await sk.selectRowByValue("mention");
|
|
|
|
assert.equal(sk.header().value(), "mention");
|
|
},
|
|
});
|
|
|
|
componentTest("muted", {
|
|
template: hbs`{{chat-channel-settings-view channel=channel}}`,
|
|
|
|
beforeEach() {
|
|
this.set(
|
|
"channel",
|
|
fabricators.chatChannel({
|
|
chatable_type: CHATABLE_TYPES.directMessageChannel,
|
|
})
|
|
);
|
|
},
|
|
|
|
async test(assert) {
|
|
pretender.put(
|
|
`/chat/api/chat_channels/${this.channel.id}/notifications_settings.json`,
|
|
() => {
|
|
return [
|
|
200,
|
|
{ "Content-Type": "application/json" },
|
|
membershipFixture(this.channel.id, { muted: false }),
|
|
];
|
|
}
|
|
);
|
|
|
|
const sk = selectKit(".channel-settings-view__muted-selector");
|
|
await sk.expand();
|
|
await sk.selectRowByName("Off");
|
|
|
|
assert.equal(sk.header().value(), "false");
|
|
},
|
|
});
|
|
|
|
componentTest("hide channel wide mentions", {
|
|
template: hbs`{{chat-channel-settings-view channel=channel}}`,
|
|
|
|
beforeEach() {
|
|
this.set(
|
|
"channel",
|
|
fabricators.chatChannel({
|
|
chatable_type: CHATABLE_TYPES.directMessageChannel,
|
|
})
|
|
);
|
|
},
|
|
|
|
async test(assert) {
|
|
assert
|
|
.dom(".channel-settings-view__channel-wide-mentions-selector")
|
|
.doesNotExist();
|
|
},
|
|
});
|
|
|
|
componentTest("hide channel auto join", {
|
|
template: hbs`{{chat-channel-settings-view channel=channel}}`,
|
|
|
|
beforeEach() {
|
|
this.set(
|
|
"channel",
|
|
fabricators.chatChannel({
|
|
chatable_type: CHATABLE_TYPES.directMessageChannel,
|
|
})
|
|
);
|
|
},
|
|
|
|
async test(assert) {
|
|
assert.dom(".channel-settings-view__auto-join-selector").doesNotExist();
|
|
},
|
|
});
|
|
}
|
|
);
|