DEV: use sinon for safer stubbing (#624)
Follow up to https://github.com/discourse/discourse-ai/pull/622#discussion_r1601199538
This commit is contained in:
parent
1e6d9ed634
commit
d64cff7692
|
@ -1,5 +1,6 @@
|
|||
import { setupTest } from "ember-qunit";
|
||||
import { module, test } from "qunit";
|
||||
import sinon from "sinon";
|
||||
|
||||
module(
|
||||
"Unit | Route | discourse-ai-shared-conversation-show",
|
||||
|
@ -18,47 +19,43 @@ module(
|
|||
"route:discourse-ai-shared-conversation-show"
|
||||
);
|
||||
|
||||
const originalOpen = window.open;
|
||||
const originalRedirect = route.redirect;
|
||||
const windowOpenStub = sinon.stub(window, "open");
|
||||
const routeRedirectStub = sinon.stub(route, "redirect");
|
||||
|
||||
// Test when external_links_in_new_tab is true
|
||||
// external_links_in_new_tab = true
|
||||
route.set("currentUser", {
|
||||
user_option: {
|
||||
external_links_in_new_tab: true,
|
||||
},
|
||||
});
|
||||
|
||||
window.open = (url, target) => {
|
||||
windowOpenStub.callsFake((url, target) => {
|
||||
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"');
|
||||
};
|
||||
});
|
||||
|
||||
route.beforeModel(transition);
|
||||
|
||||
// Test when external_links_in_new_tab is false
|
||||
// external_links_in_new_tab = false
|
||||
route.set("currentUser", {
|
||||
user_option: {
|
||||
external_links_in_new_tab: false,
|
||||
},
|
||||
});
|
||||
|
||||
route.redirect = (url) => {
|
||||
routeRedirectStub.callsFake((url) => {
|
||||
assert.equal(
|
||||
url,
|
||||
"https://www.discourse.org",
|
||||
"redirect was called with the correct URL"
|
||||
);
|
||||
};
|
||||
});
|
||||
|
||||
route.beforeModel(transition);
|
||||
|
||||
// Reset
|
||||
window.open = originalOpen;
|
||||
route.redirect = originalRedirect;
|
||||
});
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue