91 lines
4.7 KiB
JavaScript
91 lines
4.7 KiB
JavaScript
// Launch the compiled app with isolated data and capture its update panel without signing in.
|
|
const { app } = require('electron')
|
|
const { mkdirSync, writeFileSync } = require('node:fs')
|
|
const { join } = require('node:path')
|
|
const assert = require('node:assert/strict')
|
|
|
|
const profile = join(__dirname, '../dist/smoke-profile')
|
|
mkdirSync(profile, { recursive: true })
|
|
mkdirSync(join(__dirname, '../dist/local'), { recursive: true })
|
|
app.setName('capsule-local')
|
|
app.setVersion(require('../package.json').version)
|
|
app.setPath('appData', profile)
|
|
const timeout = setTimeout(() => {
|
|
console.error('Smoke test timed out.')
|
|
app.exit(1)
|
|
}, 30000)
|
|
app.on('browser-window-created', (_event, window) => {
|
|
window.show = () => {} // Exercise the real app without interrupting the user's desktop.
|
|
window.webContents.once('did-finish-load', async () => {
|
|
try {
|
|
const state = await window.webContents.executeJavaScript(`(async () => {
|
|
const state = await window.capsule.updateStatus()
|
|
await window.capsule.checkForUpdates()
|
|
await new Promise(resolve => setTimeout(resolve, 250))
|
|
return {
|
|
state,
|
|
panelVisible: !document.getElementById('capsule-updates').hidden,
|
|
checkHidden: document.getElementById('update-check').hidden,
|
|
restartHidden: document.getElementById('update-install').hidden,
|
|
label: document.getElementById('update-status').textContent
|
|
}
|
|
})()`)
|
|
assert.equal(state.state.status, 'disabled')
|
|
assert.equal(state.state.currentVersion, require('../package.json').version)
|
|
assert.equal(state.panelVisible, true)
|
|
assert.equal(state.checkHidden, true)
|
|
assert.equal(state.restartHidden, true)
|
|
assert.match(state.label, /automatic updates are disabled/)
|
|
assert.equal(app.getPath('userData'), join(profile, 'capsule-local'))
|
|
const chrome = await window.webContents.executeJavaScript(`(() => {
|
|
const cols = document.querySelector('.capsule-footer-cols').getBoundingClientRect()
|
|
const theme = document.querySelector('.capsule-footer-theme').getBoundingClientRect()
|
|
const logo = document.getElementById('header-logo')
|
|
return {
|
|
site: document.getElementById('login-site').value,
|
|
tokenSite: document.getElementById('token-site').value,
|
|
logo: logo.src,
|
|
contactBlank: getComputedStyle(document.getElementById('footer-contact-col')).visibility === 'hidden',
|
|
themeCentered: Math.abs((theme.left + theme.right) / 2 - (cols.left + cols.right) / 2) < 2
|
|
}
|
|
})()`)
|
|
assert.equal(chrome.site, chrome.tokenSite)
|
|
assert.ok(chrome.site.startsWith('http'))
|
|
assert.equal(chrome.logo, chrome.site + '/images/logoWhite.png')
|
|
assert.equal(chrome.contactBlank, true)
|
|
assert.equal(chrome.themeCentered, true)
|
|
const image = await window.webContents.capturePage()
|
|
writeFileSync(join(__dirname, '../dist/local/smoke.png'), image.toPNG())
|
|
window.webContents.send('capsule:updates:changed', {
|
|
status: 'available', currentVersion: app.getVersion(), version: '0.1.3', percent: 0
|
|
})
|
|
const offer = await window.webContents.executeJavaScript(`new Promise(resolve => setTimeout(() => {
|
|
const panel = document.getElementById('capsule-updates')
|
|
resolve({ blue: panel.classList.contains('is-update'),
|
|
download: !document.getElementById('update-download').hidden,
|
|
install: !document.getElementById('update-install').hidden })
|
|
}, 100))`)
|
|
assert.deepEqual(offer, { blue: true, download: true, install: false })
|
|
writeFileSync(join(__dirname, '../dist/local/smoke-available.png'), (await window.webContents.capturePage()).toPNG())
|
|
// Exercise the ready prompt with synthetic state; never invoke installation.
|
|
window.webContents.send('capsule:updates:changed', {
|
|
status: 'ready', currentVersion: app.getVersion(), version: '0.1.1', percent: 100
|
|
})
|
|
const readyVisible = await window.webContents.executeJavaScript(`new Promise(resolve => setTimeout(() => {
|
|
const button = document.getElementById('update-install')
|
|
resolve(!button.hidden && document.getElementById('update-status').textContent.includes('Save your work') &&
|
|
document.getElementById('capsule-updates').classList.contains('is-update') && document.getElementById('update-download').hidden)
|
|
}, 100))`)
|
|
assert.equal(readyVisible, true)
|
|
writeFileSync(join(__dirname, '../dist/local/smoke-ready.png'), (await window.webContents.capturePage()).toPNG())
|
|
console.log(JSON.stringify({ smoke: 'passed', ...state }))
|
|
clearTimeout(timeout)
|
|
app.exit(0)
|
|
} catch (error) {
|
|
console.error(error)
|
|
app.exit(1)
|
|
}
|
|
})
|
|
})
|
|
require('../out/main/index.js')
|