2020-11-24 16:19:52 -05:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
|
import { setupTest } from 'ember-qunit';
|
2021-03-19 12:08:32 -04:00
|
|
|
import sinon from 'sinon';
|
2020-11-24 16:19:52 -05:00
|
|
|
|
2021-03-05 17:49:47 -05:00
|
|
|
module('Unit | Service | origin', function (hooks) {
|
2020-11-24 16:19:52 -05:00
|
|
|
setupTest(hooks);
|
|
|
|
|
|
2021-03-19 12:08:32 -04:00
|
|
|
let service, ipcService;
|
|
|
|
|
|
|
|
|
|
hooks.beforeEach(function () {
|
|
|
|
|
service = this.owner.lookup('service:origin');
|
|
|
|
|
ipcService = this.owner.lookup('service:ipc');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('resets origin on error', async function (assert) {
|
|
|
|
|
assert.expect(4);
|
|
|
|
|
const ipcServiceStubbed = sinon.stub(ipcService, 'invoke');
|
|
|
|
|
await service.setOrigin(window.location.origin);
|
|
|
|
|
assert.equal(service.rendererOrigin, window.location.origin);
|
|
|
|
|
assert.equal(service.adapter.host, window.location.origin);
|
|
|
|
|
ipcServiceStubbed.withArgs('setOrigin').rejects();
|
|
|
|
|
service.setOrigin('invalid-origin').catch(() => {
|
|
|
|
|
assert.notOk(service.rendererOrigin);
|
|
|
|
|
assert.equal(service.adapter.host, window.location.origin);
|
|
|
|
|
});
|
2020-11-24 16:19:52 -05:00
|
|
|
});
|
2021-04-08 13:45:19 -04:00
|
|
|
|
|
|
|
|
test('drops trailing slashes from origin on setOrigin', async function (assert) {
|
|
|
|
|
assert.expect(4);
|
|
|
|
|
sinon.stub(ipcService, 'invoke');
|
|
|
|
|
await service.setOrigin(`${window.location.origin}/`);
|
|
|
|
|
assert.equal(service.rendererOrigin, window.location.origin);
|
|
|
|
|
assert.equal(service.adapter.host, window.location.origin);
|
|
|
|
|
await service.setOrigin(`${window.location.origin}//////`);
|
|
|
|
|
assert.equal(service.rendererOrigin, window.location.origin);
|
|
|
|
|
assert.equal(service.adapter.host, window.location.origin);
|
|
|
|
|
});
|
2021-04-13 14:34:30 -04:00
|
|
|
|
|
|
|
|
test('trim spaces from origin on setOrigin', async function (assert) {
|
|
|
|
|
assert.expect(4);
|
|
|
|
|
sinon.stub(ipcService, 'invoke');
|
2021-04-13 16:56:21 -04:00
|
|
|
await service.setOrigin(` ${window.location.origin}/ `);
|
2021-04-13 14:34:30 -04:00
|
|
|
assert.equal(service.rendererOrigin, window.location.origin);
|
|
|
|
|
assert.equal(service.adapter.host, window.location.origin);
|
|
|
|
|
await service.setOrigin(` ${window.location.origin} `);
|
|
|
|
|
assert.equal(service.rendererOrigin, window.location.origin);
|
|
|
|
|
assert.equal(service.adapter.host, window.location.origin);
|
|
|
|
|
});
|
2020-11-24 16:19:52 -05:00
|
|
|
});
|