2024-05-15 04:06:38 -04:00
|
|
|
import { setupTest } from "ember-qunit";
|
|
|
|
import { module, test } from "qunit";
|
2024-05-15 05:54:19 -04:00
|
|
|
import sinon from "sinon";
|
2024-05-15 04:06:38 -04:00
|
|
|
|
|
|
|
module(
|
|
|
|
"Unit | Route | discourse-ai-shared-conversation-show",
|
|
|
|
function (hooks) {
|
|
|
|
setupTest(hooks);
|
|
|
|
|
|
|
|
test("it redirects based on currentUser preference", function (assert) {
|
|
|
|
const transition = {
|
|
|
|
intent: { url: "https://www.discourse.org" },
|
|
|
|
abort() {
|
|
|
|
assert.ok(true, "transition.abort() was called");
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const route = this.owner.lookup(
|
|
|
|
"route:discourse-ai-shared-conversation-show"
|
|
|
|
);
|
|
|
|
|
2024-05-15 05:54:19 -04:00
|
|
|
const windowOpenStub = sinon.stub(window, "open");
|
|
|
|
const routeRedirectStub = sinon.stub(route, "redirect");
|
2024-05-15 04:06:38 -04:00
|
|
|
|
2024-05-15 05:54:19 -04:00
|
|
|
// external_links_in_new_tab = true
|
2024-05-15 04:06:38 -04:00
|
|
|
route.set("currentUser", {
|
|
|
|
user_option: {
|
|
|
|
external_links_in_new_tab: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-05-15 05:54:19 -04:00
|
|
|
windowOpenStub.callsFake((url, target) => {
|
2024-05-15 04:06:38 -04:00
|
|
|
assert.equal(
|
|
|
|
url,
|
|
|
|
"https://www.discourse.org",
|
|
|
|
"window.open was called with the correct URL"
|
|
|
|
);
|
|
|
|
assert.equal(target, "_blank", 'window.open was called with "_blank"');
|
2024-05-15 05:54:19 -04:00
|
|
|
});
|
2024-05-15 04:06:38 -04:00
|
|
|
|
|
|
|
route.beforeModel(transition);
|
|
|
|
|
2024-05-15 05:54:19 -04:00
|
|
|
// external_links_in_new_tab = false
|
2024-05-15 04:06:38 -04:00
|
|
|
route.set("currentUser", {
|
|
|
|
user_option: {
|
|
|
|
external_links_in_new_tab: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-05-15 05:54:19 -04:00
|
|
|
routeRedirectStub.callsFake((url) => {
|
2024-05-15 04:06:38 -04:00
|
|
|
assert.equal(
|
|
|
|
url,
|
|
|
|
"https://www.discourse.org",
|
|
|
|
"redirect was called with the correct URL"
|
|
|
|
);
|
2024-05-15 05:54:19 -04:00
|
|
|
});
|
2024-05-15 04:06:38 -04:00
|
|
|
|
|
|
|
route.beforeModel(transition);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|