2023-09-27 01:05:34 +08:00
|
|
|
import { getOwner } from "@ember/application";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { setupTest } from "ember-qunit";
|
|
|
|
import { module, test } from "qunit";
|
2024-04-09 03:00:09 +08:00
|
|
|
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
2023-05-24 21:36:46 +08:00
|
|
|
|
|
|
|
module(
|
|
|
|
"Discourse Chat | Unit | Service | chat-drafts-manager",
|
|
|
|
function (hooks) {
|
|
|
|
setupTest(hooks);
|
|
|
|
|
|
|
|
hooks.beforeEach(function () {
|
|
|
|
this.subject = getOwner(this).lookup("service:chat-drafts-manager");
|
|
|
|
});
|
|
|
|
|
2023-11-22 18:54:23 +08:00
|
|
|
test("storing and retrieving message", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
const message1 = new ChatFabricators(getOwner(this)).message();
|
2023-05-24 21:36:46 +08:00
|
|
|
|
2023-11-22 18:54:23 +08:00
|
|
|
await this.subject.add(message1, message1.channel.id);
|
|
|
|
|
|
|
|
assert.strictEqual(this.subject.get(message1.channel.id), message1);
|
2023-05-24 21:36:46 +08:00
|
|
|
|
2024-04-09 03:00:09 +08:00
|
|
|
const message2 = new ChatFabricators(getOwner(this)).message();
|
2023-05-24 21:36:46 +08:00
|
|
|
|
2023-11-22 18:54:23 +08:00
|
|
|
await this.subject.add(message2, message2.channel.id);
|
2023-05-24 21:36:46 +08:00
|
|
|
|
2023-11-22 18:54:23 +08:00
|
|
|
assert.strictEqual(this.subject.get(message2.channel.id), message2);
|
2023-05-24 21:36:46 +08:00
|
|
|
});
|
|
|
|
|
2023-11-22 18:54:23 +08:00
|
|
|
test("#reset", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
const message = new ChatFabricators(getOwner(this)).message();
|
2023-11-22 18:54:23 +08:00
|
|
|
|
|
|
|
await this.subject.add(message, message.channel.id);
|
2023-05-24 21:36:46 +08:00
|
|
|
|
|
|
|
assert.strictEqual(Object.keys(this.subject.drafts).length, 1);
|
|
|
|
|
|
|
|
this.subject.reset();
|
|
|
|
|
|
|
|
assert.strictEqual(Object.keys(this.subject.drafts).length, 0);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|