Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gui/js/onboarding.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ module.exports = class OnboardingWM extends WindowManager {
const code = deeplink.searchParams.get('code')
const fqdn = deeplink.searchParams.get('fqdn')

this.focus()

if (!code || !fqdn) {
log.error('invalid OAuth callback', { url })
this.win.webContents.send(
Expand Down
6 changes: 5 additions & 1 deletion gui/js/window_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ module.exports = class WindowManager {
}

focus() {
return this.win && this.win.focus()
if (!this.win) return

if (this.win.isMinimized()) this.win.restore()

return this.win.focus()
}

reload() {
Expand Down
41 changes: 41 additions & 0 deletions test/unit/gui/onboarding.window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const sinon = require('sinon')

const autoLaunch = require('../../../gui/js/autolaunch')
const OnboardingWM = require('../../../gui/js/onboarding.window')

describe('onboarding.window', () => {
describe('handleDeepLink', () => {
const sandbox = sinon.createSandbox()
let onboardingWindow

beforeEach(() => {
onboardingWindow = Object.create(OnboardingWM.prototype)
onboardingWindow.focus = sandbox.spy()
onboardingWindow.desktop = {
registerWithDelegationCode: sandbox.stub().resolves()
}
onboardingWindow.sendSyncConfig = sandbox.stub().resolves()
sandbox.stub(autoLaunch, 'setEnabled')
})

afterEach(() => sandbox.restore())

it('focuses the window before registering the OAuth credentials', async () => {
await onboardingWindow.handleDeepLink(
'cozy://?fqdn=example.mycozy.cloud&code=delegation-code'
)

sinon.assert.callOrder(
onboardingWindow.focus,
onboardingWindow.desktop.registerWithDelegationCode,
onboardingWindow.sendSyncConfig
)
sinon.assert.calledWithExactly(
onboardingWindow.desktop.registerWithDelegationCode,
'example.mycozy.cloud',
'delegation-code'
)
sinon.assert.calledOnce(onboardingWindow.sendSyncConfig)
})
})
})
52 changes: 52 additions & 0 deletions test/unit/gui/window_manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const sinon = require('sinon')

const WindowManager = require('../../../gui/js/window_manager')

describe('window_manager', () => {
describe('focus', () => {
const sandbox = sinon.createSandbox()
let windowManager
let win

beforeEach(() => {
win = {
isMinimized: sandbox.stub(),
restore: sandbox.spy(),
focus: sandbox.spy()
}
windowManager = Object.create(WindowManager.prototype)
windowManager.win = win
})

afterEach(() => sandbox.restore())

it('does nothing when the window is closed', () => {
windowManager.win = null

windowManager.focus()

sinon.assert.notCalled(win.isMinimized)
sinon.assert.notCalled(win.restore)
sinon.assert.notCalled(win.focus)
})
Comment thread
taratatach marked this conversation as resolved.

it('focuses an existing window', () => {
win.isMinimized.returns(false)

windowManager.focus()

sinon.assert.notCalled(win.restore)
sinon.assert.calledOnce(win.focus)
})

it('restores a minimized window before focusing it', () => {
win.isMinimized.returns(true)

windowManager.focus()

sinon.assert.callOrder(win.restore, win.focus)
sinon.assert.calledOnce(win.restore)
sinon.assert.calledOnce(win.focus)
})
})
})
Loading