* WIP: Add tauri e2e test for auth on Linux Fixes #968 * WIP * WIP * Working of through /tmp file for user code sharing * rust int * User code only in /tmp, fixes * Longer timeout for github actions * Remove timeout * Fmt * Fmt, 30sec timeout * Test BUILD_RELEASE true * Revert "Test BUILD_RELEASE true" This reverts commitd3b59d4a6c
. * Disable concurrency limit for faster iterations on this PR * Add logs for responses * Test manual tauri build before e2e * WIP * Catch error on tauri::api:🐚:open * Clean up * Clean up * timeout * Force BUILD_RELEASE: true * Back to debug, longer timeout * Print if url opens ok too * Check default browser in actions * Remote shell call on linux (aka e2e for now) * Fix fmt * Move to data-testid, clean up * Add log out section * Clean up * Fix typo * Fix text detection * Test AppImage * Revert "Test AppImage" This reverts commitcf126b1aa6
. * Add comments * Change to env var * Clean up * Fmt fix * Better package json name * Add import @wdio/globals * Back to require * Update wdio, fix globals * Move to typescript * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
63 lines
2.3 KiB
TypeScript
63 lines
2.3 KiB
TypeScript
import { browser, $, expect } from '@wdio/globals'
|
|
import fs from 'fs/promises'
|
|
|
|
describe('KCMA (Tauri, Linux)', () => {
|
|
it('opens the auth page, signs in, and signs out', async () => {
|
|
// Clean up previous tests
|
|
await new Promise((resolve) => setTimeout(resolve, 100))
|
|
await fs.rm('/tmp/kittycad_user_code', { force: true })
|
|
await browser.execute('window.localStorage.clear()')
|
|
|
|
const signInButton = await $('[data-testid="sign-in-button"]')
|
|
expect(await signInButton.getText()).toEqual('Sign in')
|
|
|
|
// Workaround for .click(), see https://github.com/tauri-apps/tauri/issues/6541
|
|
await signInButton.waitForClickable()
|
|
await browser.execute('arguments[0].click();', signInButton)
|
|
await new Promise((resolve) => setTimeout(resolve, 2000))
|
|
|
|
// Get from main.rs
|
|
const userCode = await (
|
|
await fs.readFile('/tmp/kittycad_user_code')
|
|
).toString()
|
|
console.log(`Found user code ${userCode}`)
|
|
|
|
// Device flow: verify
|
|
const token = process.env.KITTYCAD_API_TOKEN
|
|
const headers = {
|
|
Authorization: `Bearer ${token}`,
|
|
Accept: 'application/json',
|
|
'Content-Type': 'application/json',
|
|
}
|
|
const verifyUrl = `https://api.kittycad.io/oauth2/device/verify?user_code=${userCode}`
|
|
console.log(`GET ${verifyUrl}`)
|
|
const vr = await fetch(verifyUrl, { headers })
|
|
console.log(vr.status)
|
|
|
|
// Device flow: confirm
|
|
const confirmUrl = 'https://api.kittycad.io/oauth2/device/confirm'
|
|
const data = JSON.stringify({ user_code: userCode })
|
|
console.log(`POST ${confirmUrl} ${data}`)
|
|
const cr = await fetch(confirmUrl, {
|
|
headers,
|
|
method: 'POST',
|
|
body: data,
|
|
})
|
|
console.log(cr.status)
|
|
|
|
// Now should be signed in
|
|
const newFileButton = await $('[data-testid="home-new-file"]')
|
|
expect(await newFileButton.getText()).toEqual('New file')
|
|
|
|
// So let's sign out!
|
|
const menuButton = await $('[data-testid="user-sidebar-toggle"]')
|
|
await menuButton.waitForClickable()
|
|
await browser.execute('arguments[0].click();', menuButton)
|
|
const signoutButton = await $('[data-testid="user-sidebar-sign-out"]')
|
|
await signoutButton.waitForClickable()
|
|
await browser.execute('arguments[0].click();', signoutButton)
|
|
const newSignInButton = await $('[data-testid="sign-in-button"]')
|
|
expect(await newSignInButton.getText()).toEqual('Sign in')
|
|
})
|
|
})
|