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-action-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

37 lines
1.1 KiB
JavaScript

import { module, test } from "qunit";
import UserAction from "discourse/models/user-action";
import { setupTest } from "ember-qunit";
import { getOwner } from "discourse-common/lib/get-owner";
module("Unit | Model | user-action", function (hooks) {
setupTest(hooks);
test("collapsing likes", function (assert) {
const store = getOwner(this).lookup("service:store");
const actions = UserAction.collapseStream([
store.createRecord("user-action", {
action_type: UserAction.TYPES.likes_given,
topic_id: 1,
user_id: 1,
post_number: 1,
}),
store.createRecord("user-action", {
action_type: UserAction.TYPES.edits,
topic_id: 2,
user_id: 1,
post_number: 1,
}),
store.createRecord("user-action", {
action_type: UserAction.TYPES.likes_given,
topic_id: 1,
user_id: 2,
post_number: 1,
}),
]);
assert.strictEqual(actions.length, 2);
assert.strictEqual(actions[0].children.length, 1);
assert.strictEqual(actions[0].children[0].items.length, 2);
});
});