import { remote } from 'webdriverio'
import { test_navigation_integrated } from './navigation-control.mjs'
import { test_navigation_unit } from './unit-control.mjs';

const args = process.argv.slice(2)
const headfull = args.includes('--headfull')

if (headfull) {
	process.env.XDG_RUNTIME_DIR = '/tmp'
	process.env.WAYLAND_DISPLAY = 'wayland-0'
}


const browser = await remote({
	capabilities: {
		browserName: 'firefox',
		'moz:firefoxOptions': {
			binary: '/usr/bin/firefox',
			args: headfull ? [] : ['-headless'],
		},
	},
	automationProtocol: 'webdriver',
	logLevel: 'warn',
})


try {
	await test_navigation_unit(browser, headfull)
	await test_navigation_integrated(browser)
	console.log('\x1b[32mALL GOOD\x1b[0m')
} catch (error) {
	console.error('Test failed:', error.message)
	process.exit(1)
} finally {
	await browser.deleteSession()
}
