UX: Do not automatically refresh page while composer is open (#19112)

We automatically refresh the page 'on the next navigation' whenever a
new version of the JS client is available. If the composer is open when
this happens then it will be closed and you'll have to reopen the draft.
In some circumstances, this refresh can also cause some composer content
to be lost.

This commit updates the auto-refresh logic so that it doesn't trigger
while the composer is open, and adds an acceptance test for the
behaviour.

<!-- NOTE: All pull requests should have tests (rspec in Ruby, qunit in
JavaScript). If your code does not include test coverage, please include
an explanation of why it was omitted. -->
This commit is contained in:
David Taylor 2022-11-21 10:45:19 +00:00 committed by GitHub
parent 59e02bd210
commit ecce3c81f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 1 deletions

View File

@ -196,7 +196,7 @@ const DiscourseURL = EmberObject.extend({
return;
}
if (Session.currentProp("requiresRefresh")) {
if (Session.currentProp("requiresRefresh") && !this.isComposerOpen) {
return this.redirectTo(path);
}
@ -409,6 +409,10 @@ const DiscourseURL = EmberObject.extend({
return window.location.origin + (prefix === "/" ? "" : prefix);
},
get isComposerOpen() {
return this.controllerFor("composer")?.visible;
},
get router() {
return this.container.lookup("router:main");
},

View File

@ -0,0 +1,51 @@
import {
acceptance,
publishToMessageBus,
} from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import { click, visit } from "@ember/test-helpers";
import DiscourseURL from "discourse/lib/url";
import Sinon from "sinon";
acceptance("Software update refresh", function (needs) {
needs.user();
test("Refreshes page on next navigation", async function (assert) {
const redirectStub = Sinon.stub(DiscourseURL, "redirectTo");
await visit("/");
await click(".nav-item_top a");
assert.true(
redirectStub.notCalled,
"redirect was not triggered by default"
);
await publishToMessageBus("/global/asset-version", "somenewversion");
redirectStub.resetHistory();
await visit("/");
await click(".nav-item_top a");
assert.true(
redirectStub.calledWith("/top"),
"redirect was triggered after asset change"
);
redirectStub.resetHistory();
await visit("/");
await click("#create-topic");
await click(".nav-item_top a");
assert.true(
redirectStub.notCalled,
"redirect is not triggered while composer is open"
);
redirectStub.resetHistory();
await visit("/");
await click(".save-or-cancel .cancel");
await click(".nav-item_top a");
assert.true(
redirectStub.calledWith("/top"),
"redirect is triggered on next navigation after composer closed"
);
});
});