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/acceptance/assets-version-test.js
David Taylor ecce3c81f2
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. -->
2022-11-21 10:45:19 +00:00

52 lines
1.4 KiB
JavaScript

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"
);
});
});