This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/unit/models/user-drafts-test.js
Jarek Radosz 4f12fd0339
DEV: Modernize model tests (#19104)
Uses `module()` instead of `discourseModule()`, native getters instead of `.get()`, fixes some assertions, uses the store instead of creating models directly
2022-11-18 20:36:32 +01:00

44 lines
1.3 KiB
JavaScript

import { module, test } from "qunit";
import I18n from "I18n";
import { NEW_TOPIC_KEY } from "discourse/models/composer";
import { setupTest } from "ember-qunit";
import { getOwner } from "discourse-common/lib/get-owner";
module("Unit | Model | user-draft", function (hooks) {
setupTest(hooks);
test("stream", function (assert) {
const store = getOwner(this).lookup("service:store");
const user = store.createRecord("user", { id: 1, username: "eviltrout" });
const stream = user.userDraftsStream;
assert.present(stream, "a user has a drafts stream by default");
assert.strictEqual(
stream.content.length,
0,
"no items are loaded by default"
);
assert.blank(stream.content, "no content by default");
});
test("draft", function (assert) {
const store = getOwner(this).lookup("service:store");
const drafts = [
store.createRecord("user-draft", {
draft_key: "topic_1",
post_number: "10",
}),
store.createRecord("user-draft", {
draft_key: NEW_TOPIC_KEY,
}),
];
assert.strictEqual(drafts.length, 2, "drafts count is right");
assert.strictEqual(
drafts[1].draftType,
I18n.t("drafts.new_topic"),
"loads correct draftType label"
);
});
});