A platform for community discussion. Free, open, simple.
FIX: Flaky JS tests (#12331)
Robin Ward55007c0621af
diff --git a/app/assets/javascripts/discourse-common/addon/resolver.js b/app/assets/javascripts/discourse-common/addon/resolver.jsindex 51222877ffd..057f173563b 100644--- a/app/assets/javascripts/discourse-common/addon/resolver.js+++ b/app/assets/javascripts/discourse-common/addon/resolver.js@@ -3,7 +3,7 @@ import deprecated from "discourse-common/lib/deprecated";import { findHelper } from "discourse-common/lib/helpers";import { get } from "@ember/object";-const _options = {};+let _options = {};export function setResolverOption(name, value) {_options[name] = value;@@ -13,6 +13,10 @@ export function getResolverOption(name) {return _options[name];}+export function clearResolverOptions() {+ _options = {};+}+function parseName(fullName) {const nameParts = fullName.split(":");const type = nameParts[0];diff --git a/app/assets/javascripts/discourse/app/models/topic.js b/app/assets/javascripts/discourse/app/models/topic.jsindex 621a680f4fe..5298b2b59b8 100644--- a/app/assets/javascripts/discourse/app/models/topic.js+++ b/app/assets/javascripts/discourse/app/models/topic.js@@ -1,4 +1,4 @@-import { and, equal, notEmpty, or } from "@ember/object/computed";+import { alias, and, equal, notEmpty, or } from "@ember/object/computed";import { fmt, propertyEqual } from "discourse/lib/computed";import ActionSummary from "discourse/models/action-summary";import Category from "discourse/models/category";@@ -58,25 +58,16 @@ const Topic = RestModel.extend({@discourseComputed("posters.[]")lastPoster(posters) {- let user;if (posters && posters.length > 0) {const latest = posters.filter((p) => p.extras && p.extras.indexOf("latest") >= 0)[0];- user = latest;+ return latest || posters.firstObject;}- return user || posters.firstObject;},- @discourseComputed("lastPoster")- lastPosterUser(poster) {- return poster.user;- },-- @discourseComputed("lastPoster")- lastPosterGroup(poster) {- return poster.primary_group;- },+ lastPosterUser: alias("lastPoster.user"),+ lastPosterGroup: alias("lastPoster.primary_group"),@discourseComputed("posters.[]", "participants.[]", "allowed_user_count")featuredUsers(posters, participants, allowedUserCount) {diff --git a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.jsindex 81c2a1ae3a5..0a6ddd53565 100644--- a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js+++ b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js@@ -37,6 +37,7 @@ import sessionFixtures from "discourse/tests/fixtures/session-fixtures";import { setTopicList } from "discourse/lib/topic-list-tracker";import sinon from "sinon";import siteFixtures from "discourse/tests/fixtures/site-fixtures";+import { clearResolverOptions } from "discourse-common/resolver";const LEGACY_ENV = !setupApplicationTest;@@ -109,9 +110,9 @@ export function discourseModule(name, options) {hooks.beforeEach(function () {this.container = getOwner(this);this.registry = this.container.registry;-this.owner = this.container;this.siteSettings = currentSettings();+ clearResolverOptions();});this.getController = function (controllerName, properties) {diff --git a/app/assets/javascripts/discourse/tests/integration/components/topic-list-test.js b/app/assets/javascripts/discourse/tests/integration/components/topic-list-test.jsindex 24ff8b7acc2..971e7488baf 100644--- a/app/assets/javascripts/discourse/tests/integration/components/topic-list-test.js+++ b/app/assets/javascripts/discourse/tests/integration/components/topic-list-test.js@@ -40,6 +40,7 @@ discourseModule("Integration | Component | topic-list", function (hooks) {},async test(assert) {+ assert.equal(this.selected.length, 0, "defaults to 0");await click("button.bulk-select");assert.ok(this.bulkSelectEnabled, "bulk select is enabled");