Files
discourse/app/assets/javascripts/discourse/tests/unit/models/pending-post-test.js
Jarek Radosz c75b379d6f DEV: Future-proof htmlSafe interactions (#23596)
See https://github.com/discourse/discourse-encrypt/pull/282

> `cooked` was an Ember SafeString. The internal storage of the string changed from `.string` to `.__string` at some point between Ember 3.28 and Ember 5. Instead, we can use `toString()` which is guaranteed to work in all situations
2023-09-14 23:04:57 +02: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.toString(),
"<p><strong>bold text</strong></p>"
);
});
});