From 55007c0621afd7eb6d6d0744eababfe68c968c87 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 10 Mar 2021 08:27:42 -0500 Subject: [PATCH] FIX: Flaky JS tests (#12331) If you were unlucky and tested a mobile raw template before a desktop raw template, it would keep using the mobile one resulting in failures. --- .../discourse-common/addon/resolver.js | 6 +++++- .../javascripts/discourse/app/models/topic.js | 17 ++++------------- .../discourse/tests/helpers/qunit-helpers.js | 3 ++- .../integration/components/topic-list-test.js | 1 + 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/discourse-common/addon/resolver.js b/app/assets/javascripts/discourse-common/addon/resolver.js index 51222877ff..057f173563 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.js index 621a680f4f..5298b2b59b 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.js index 81c2a1ae3a..0a6ddd5356 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.js index 24ff8b7acc..971e7488ba 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");