mirror of
https://github.com/discourse/discourse.git
synced 2024-12-03 09:43:44 +08:00
66130dc8c1
- Note this is also tweaking the UI a little bit as we are now using links/buttons in the header as needed - It disables the find ideal channel in drawer mode, if loading `/chat` in drawer mode it will either reopen at the last position or just stay on index
222 lines
6.0 KiB
JavaScript
222 lines
6.0 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({}, options, { muted: false, following: true });
|
|
|
|
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: true }),
|
|
];
|
|
}
|
|
);
|
|
|
|
const sk = selectKit(".channel-settings-view__muted-selector");
|
|
await sk.expand();
|
|
await sk.selectRowByName("Off");
|
|
|
|
assert.equal(sk.header().value(), "false");
|
|
},
|
|
});
|
|
}
|
|
);
|
|
|
|
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: true }),
|
|
];
|
|
}
|
|
);
|
|
|
|
const sk = selectKit(".channel-settings-view__muted-selector");
|
|
await sk.expand();
|
|
await sk.selectRowByName("Off");
|
|
|
|
assert.equal(sk.header().value(), "false");
|
|
},
|
|
});
|
|
}
|
|
);
|