test: 💍 dedupe window.location.origin

This commit is contained in:
Randall Morey committed 2021-04-01 10:26:59 -04:00
1 parent 838567c2d2
commit d7f090f348
1 file changed
+12 -14
+12 -14
View File
@@ -25,6 +25,7 @@ module('Acceptance | origin', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const currentOrigin = window.location.origin;
let mockIPC;
let messageHandler;
@@ -124,7 +125,7 @@ module('Acceptance | origin', function (hooks) {
mockIPC = new MockIPC();
messageHandler = async function (event) {
if (event.origin !== window.location.origin) return;
if (event.origin !== currentOrigin) return;
const { method, payload } = event.data;
if (method) {
const response = await mockIPC.invoke(method, payload);
@@ -159,20 +160,20 @@ module('Acceptance | origin', function (hooks) {
assert.expect(3);
assert.notOk(mockIPC.origin);
await visit(urls.origin);
await fillIn('[name="host"]', window.location.origin);
await fillIn('[name="host"]', currentOrigin);
await click('[type="submit"]');
assert.equal(currentURL(), urls.authenticate.methods.global);
assert.equal(mockIPC.origin, window.location.origin);
assert.equal(mockIPC.origin, currentOrigin);
});
test('can reset origin before authentication', async function (assert) {
assert.expect(4);
assert.notOk(mockIPC.origin);
await visit(urls.origin);
await fillIn('[name="host"]', window.location.origin);
await fillIn('[name="host"]', currentOrigin);
await click('[type="submit"]');
assert.equal(currentURL(), urls.authenticate.methods.global);
assert.equal(mockIPC.origin, window.location.origin);
assert.equal(mockIPC.origin, currentOrigin);
await click('.change-origin a');
assert.equal(currentURL(), urls.origin);
});
@@ -182,7 +183,7 @@ module('Acceptance | origin', function (hooks) {
assert.notOk(mockIPC.origin);
sinon.stub(this.owner.lookup('service:origin'), 'setOrigin').throws();
await visit(urls.origin);
await fillIn('[name="host"]', window.location.origin);
await fillIn('[name="host"]', currentOrigin);
await click('[type="submit"]');
assert.ok(find('.rose-notification.is-error'));
});
@@ -191,12 +192,9 @@ module('Acceptance | origin', function (hooks) {
assert.expect(1);
config.autoOrigin = true;
await visit(urls.origin);
await fillIn('[name="host"]', window.location.origin);
await fillIn('[name="host"]', currentOrigin);
await click('[type="submit"]');
assert.equal(
this.owner.lookup('controller:origin').origin,
window.location.origin
);
assert.equal(this.owner.lookup('controller:origin').origin, currentOrigin);
config.autoOrigin = false;
});
@@ -204,9 +202,9 @@ module('Acceptance | origin', function (hooks) {
assert.expect(4);
this.server.get('/targets', () => new Response(500));
await visit(urls.origin);
await fillIn('[name="host"]', window.location.origin);
await click('[type="submit"]');
await click('[type="submit"]');
await fillIn('[name="host"]', currentOrigin);
await click('[type="submit"]', 'Set origin');
await click('[type="submit"]', 'Authenticate');
assert.ok(currentSession().isAuthenticated);
assert.equal(find('main section button').textContent.trim(), 'Disconnect');
await click('main section button');