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/pending-post-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

55 lines
1.5 KiB
JavaScript

import { module, test } from "qunit";
import { setupTest } from "ember-qunit";
import { getOwner } from "discourse-common/lib/get-owner";
import { settled } from "@ember/test-helpers";
module("Unit | Model | pending-post", function (hooks) {
setupTest(hooks);
test("Properties", async function (assert) {
const store = getOwner(this).lookup("service:store");
const category = store.createRecord("category", { id: 2 });
const post = store.createRecord("pending-post", {
id: 1,
topic_url: "topic-url",
username: "USERNAME",
category_id: 2,
});
// pending-post initializer performs async operations
await settled();
assert.strictEqual(
post.postUrl,
"topic-url",
"topic_url is aliased to postUrl"
);
assert.false(post.truncated, "truncated is always false");
assert.strictEqual(
post.userUrl,
"/u/username",
"it returns user URL from the username"
);
assert.strictEqual(
post.category,
category,
"it returns the proper category object based on category_id"
);
});
test("it cooks raw_text", async function (assert) {
const store = getOwner(this).lookup("service:store");
const post = store.createRecord("pending-post", {
raw_text: "**bold text**",
});
// pending-post initializer performs async operations
await settled();
assert.strictEqual(
post.expandedExcerpt.string,
"<p><strong>bold text</strong></p>"
);
});
});