snapshot of https://github.com/tauri-apps/tauri.git (dev, 2026-09-23; blobs > 131072B omitted)
Some checks failed
Audit / audit-js (push) Failing after 0s
bench / bench (map[os:ubuntu-latest runner:xvfb-run --auto-servernum target:x86_64-unknown-linux-gnu], nightly) (push) Failing after 0s
covector version or publish / run-integration-tests (ubuntu-latest) (push) Failing after 0s
Audit / audit-rust (push) Failing after 0s
test `@tauri-apps/cli` / test (ubuntu-latest) (push) Failing after 0s
test `tauri-cli` / test (map[os:ubuntu-latest target:x86_64-unknown-linux-gnu]) (push) Failing after 0s
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:ubuntu-latest target:x86_64-unknown-linux-gnu toolchain:1.90]) (push) Failing after 0s
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:ubuntu-latest target:x86_64-unknown-linux-gnu toolchain:1.90]) (push) Failing after 0s
test core / test (map[args:--no-default-features key:no-default], map[cargo:cross command:build os:ubuntu-latest target:aarch64-linux-android toolchain:1.90]) (push) Failing after 0s
deploy schema worker / deploy (push) Failing after 0s
lint rust / clippy (map[cargo:cargo include: os:ubuntu-latest target:x86_64-unknown-linux-gnu]) (push) Failing after 0s
lint rust / clippy (map[cargo:cross include:--package api os:ubuntu-latest target:aarch64-linux-android]) (push) Failing after 0s
supply chain health status / check rust dependencies with cargo vet (push) Failing after 0s
test `@tauri-apps/api` e2e (mobile) / android (push) Failing after 0s
test `@tauri-apps/api` e2e / test (map[name:Linux os:ubuntu-latest]) (push) Failing after 0s
test core / test (map[args:--all-features key:all], map[cargo:cross command:build os:ubuntu-latest target:aarch64-linux-android toolchain:1.90]) (push) Failing after 0s
Udeps / changes (push) Failing after 0s
Udeps / setup (push) Has been skipped
Udeps / udeps (push) Has been skipped
bench / bench (map[os:macos-latest runner: target:aarch64-apple-darwin], nightly) (push) Has been cancelled
bench / bench (map[os:windows-latest runner: target:x86_64-pc-windows-msvc], nightly) (push) Has been cancelled
covector version or publish / run-integration-tests (macos-latest) (push) Has been cancelled
covector version or publish / run-integration-tests (windows-latest) (push) Has been cancelled
covector version or publish / version-or-publish (push) Has been cancelled
test `@tauri-apps/cli` / test (macos-latest) (push) Has been cancelled
test `tauri-cli` / test (map[args:--no-default-features --features native-tls-vendored os:windows-latest restore-only:true target:aarch64-pc-windows-msvc]) (push) Has been cancelled
test `tauri-cli` / test (map[os:macos-latest target:x86_64-apple-darwin]) (push) Has been cancelled
test `tauri-cli` / test (map[os:windows-latest target:x86_64-pc-windows-msvc]) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:build os:macos-latest target:aarch64-apple-ios toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:macos-14 target:aarch64-apple-darwin toolchain:1.90]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include: os:macos-latest target:aarch64-apple-darwin]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include: os:windows-latest target:x86_64-pc-windows-msvc]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include:--package api os:macos-latest target:aarch64-apple-ios]) (push) Has been cancelled
test `@tauri-apps/api` e2e (mobile) / ios (push) Has been cancelled
test `@tauri-apps/api` e2e / test (map[name:Windows os:windows-latest]) (push) Has been cancelled
test `@tauri-apps/api` e2e / test (map[name:macOS os:macos-latest]) (push) Has been cancelled
test `@tauri-apps/cli` / test (windows-latest) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:windows-latest target:x86_64-pc-windows-msvc toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:build os:macos-latest target:aarch64-apple-ios toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:macos-14 target:aarch64-apple-darwin toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:windows-latest target:x86_64-pc-windows-msvc toolchain:1.90]) (push) Has been cancelled
Some checks failed
Audit / audit-js (push) Failing after 0s
bench / bench (map[os:ubuntu-latest runner:xvfb-run --auto-servernum target:x86_64-unknown-linux-gnu], nightly) (push) Failing after 0s
covector version or publish / run-integration-tests (ubuntu-latest) (push) Failing after 0s
Audit / audit-rust (push) Failing after 0s
test `@tauri-apps/cli` / test (ubuntu-latest) (push) Failing after 0s
test `tauri-cli` / test (map[os:ubuntu-latest target:x86_64-unknown-linux-gnu]) (push) Failing after 0s
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:ubuntu-latest target:x86_64-unknown-linux-gnu toolchain:1.90]) (push) Failing after 0s
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:ubuntu-latest target:x86_64-unknown-linux-gnu toolchain:1.90]) (push) Failing after 0s
test core / test (map[args:--no-default-features key:no-default], map[cargo:cross command:build os:ubuntu-latest target:aarch64-linux-android toolchain:1.90]) (push) Failing after 0s
deploy schema worker / deploy (push) Failing after 0s
lint rust / clippy (map[cargo:cargo include: os:ubuntu-latest target:x86_64-unknown-linux-gnu]) (push) Failing after 0s
lint rust / clippy (map[cargo:cross include:--package api os:ubuntu-latest target:aarch64-linux-android]) (push) Failing after 0s
supply chain health status / check rust dependencies with cargo vet (push) Failing after 0s
test `@tauri-apps/api` e2e (mobile) / android (push) Failing after 0s
test `@tauri-apps/api` e2e / test (map[name:Linux os:ubuntu-latest]) (push) Failing after 0s
test core / test (map[args:--all-features key:all], map[cargo:cross command:build os:ubuntu-latest target:aarch64-linux-android toolchain:1.90]) (push) Failing after 0s
Udeps / changes (push) Failing after 0s
Udeps / setup (push) Has been skipped
Udeps / udeps (push) Has been skipped
bench / bench (map[os:macos-latest runner: target:aarch64-apple-darwin], nightly) (push) Has been cancelled
bench / bench (map[os:windows-latest runner: target:x86_64-pc-windows-msvc], nightly) (push) Has been cancelled
covector version or publish / run-integration-tests (macos-latest) (push) Has been cancelled
covector version or publish / run-integration-tests (windows-latest) (push) Has been cancelled
covector version or publish / version-or-publish (push) Has been cancelled
test `@tauri-apps/cli` / test (macos-latest) (push) Has been cancelled
test `tauri-cli` / test (map[args:--no-default-features --features native-tls-vendored os:windows-latest restore-only:true target:aarch64-pc-windows-msvc]) (push) Has been cancelled
test `tauri-cli` / test (map[os:macos-latest target:x86_64-apple-darwin]) (push) Has been cancelled
test `tauri-cli` / test (map[os:windows-latest target:x86_64-pc-windows-msvc]) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:build os:macos-latest target:aarch64-apple-ios toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:macos-14 target:aarch64-apple-darwin toolchain:1.90]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include: os:macos-latest target:aarch64-apple-darwin]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include: os:windows-latest target:x86_64-pc-windows-msvc]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include:--package api os:macos-latest target:aarch64-apple-ios]) (push) Has been cancelled
test `@tauri-apps/api` e2e (mobile) / ios (push) Has been cancelled
test `@tauri-apps/api` e2e / test (map[name:Windows os:windows-latest]) (push) Has been cancelled
test `@tauri-apps/api` e2e / test (map[name:macOS os:macos-latest]) (push) Has been cancelled
test `@tauri-apps/cli` / test (windows-latest) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:windows-latest target:x86_64-pc-windows-msvc toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:build os:macos-latest target:aarch64-apple-ios toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:macos-14 target:aarch64-apple-darwin toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:windows-latest target:x86_64-pc-windows-msvc toolchain:1.90]) (push) Has been cancelled
This commit is contained in:
64
packages/api-e2e/test/specs/app.spec.ts
Normal file
64
packages/api-e2e/test/specs/app.spec.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { expect } from '@wdio/globals'
|
||||
import {
|
||||
tauri,
|
||||
eventually,
|
||||
describeApi,
|
||||
platform,
|
||||
isMobile
|
||||
} from '../helpers/index.js'
|
||||
|
||||
describeApi('app', () => {
|
||||
it('getName returns the configured product name', async () => {
|
||||
expect(await tauri((api) => api.app.getName())).toBe('Tauri API')
|
||||
})
|
||||
|
||||
it('getVersion returns the configured version', async () => {
|
||||
expect(await tauri((api) => api.app.getVersion())).toBe('1.0.0')
|
||||
})
|
||||
|
||||
it('getTauriVersion returns a semver string', async () => {
|
||||
expect(await tauri((api) => api.app.getTauriVersion())).toMatch(
|
||||
/^\d+\.\d+\.\d+/
|
||||
)
|
||||
})
|
||||
|
||||
it('getIdentifier returns the bundle identifier', async () => {
|
||||
expect(await tauri((api) => api.app.getIdentifier())).toBe('com.tauri.api')
|
||||
})
|
||||
|
||||
it('defaultWindowIcon returns an image with a positive size', async () => {
|
||||
const size = await tauri(async (api) => {
|
||||
const icon = await api.app.defaultWindowIcon()
|
||||
return icon ? await icon.size() : null
|
||||
})
|
||||
expect(size).not.toBeNull()
|
||||
expect(size!.width).toBeGreaterThan(0)
|
||||
expect(size!.height).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('setTheme applies a theme and can be reset to the system default', async () => {
|
||||
await tauri((api) => api.app.setTheme('dark'))
|
||||
// On Linux the app-level theme is not observable through `window.theme()`:
|
||||
// tao's event-loop `set_theme` only flips the GTK `prefer-dark` setting and
|
||||
// never updates the window's stored theme, so `theme()` keeps reporting the
|
||||
// portal/system value (and blocks on a 5s dbus timeout when no portal runs,
|
||||
// as in headless CI). On mobile `set_theme` is a no-op and `theme()` always
|
||||
// reports `light`. Elsewhere the change is reflected on the window.
|
||||
if (platform !== 'linux' && !isMobile) {
|
||||
await eventually(async () => {
|
||||
const theme = await tauri((api) =>
|
||||
api.window.getCurrentWindow().theme()
|
||||
)
|
||||
if (theme !== 'dark') {
|
||||
throw new Error(`expected theme "dark", got "${theme}"`)
|
||||
}
|
||||
})
|
||||
}
|
||||
// restore
|
||||
await tauri((api) => api.app.setTheme(null))
|
||||
})
|
||||
})
|
||||
109
packages/api-e2e/test/specs/core.spec.ts
Normal file
109
packages/api-e2e/test/specs/core.spec.ts
Normal file
@@ -0,0 +1,109 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { expect } from '@wdio/globals'
|
||||
import { tauri, tauriError, describeApi, itOn } from '../helpers/index.js'
|
||||
|
||||
describeApi('core', () => {
|
||||
it('isTauri reports true inside the app', async () => {
|
||||
expect(await tauri((api) => api.core.isTauri())).toBe(true)
|
||||
})
|
||||
|
||||
it('invoke round-trips a raw request through the echo command', async () => {
|
||||
const echoed = await tauri((api) =>
|
||||
api.core.invoke('echo', { some: 'payload', n: 42 })
|
||||
)
|
||||
expect(echoed).toEqual({ some: 'payload', n: 42 })
|
||||
})
|
||||
|
||||
it('invoke rejects for a command that is not registered', async () => {
|
||||
// `removeUnusedCommands` strips ungranted commands from the app entirely.
|
||||
const message = await tauriError((api) =>
|
||||
api.core.invoke('this_command_does_not_exist')
|
||||
)
|
||||
expect(message).toMatch(/not found|not allowed|denied/i)
|
||||
})
|
||||
|
||||
it('command scopes gate log_operation by event', async () => {
|
||||
// The run-app capability scopes `log_operation` to the `tauri-click` event.
|
||||
await tauri((api) =>
|
||||
api.core.invoke('log_operation', {
|
||||
event: 'tauri-click',
|
||||
payload: 'from e2e'
|
||||
})
|
||||
)
|
||||
const message = await tauriError((api) =>
|
||||
api.core.invoke('log_operation', { event: 'out-of-scope-event' })
|
||||
)
|
||||
expect(message).toMatch(/not allowed|denied/i)
|
||||
})
|
||||
|
||||
it('Channel receives every message streamed from the backend in order', async () => {
|
||||
// `spam` sends 1..=1000 over the channel.
|
||||
const result = await tauri(
|
||||
(api, count) =>
|
||||
new Promise<{ length: number; ordered: boolean; last: number }>(
|
||||
(resolve, reject) => {
|
||||
const received: number[] = []
|
||||
const channel = new api.core.Channel<number>()
|
||||
channel.onmessage = (value: number) => {
|
||||
received.push(value)
|
||||
if (received.length === count) {
|
||||
let ordered = true
|
||||
for (let i = 0; i < received.length; i++) {
|
||||
if (received[i] !== i + 1) {
|
||||
ordered = false
|
||||
break
|
||||
}
|
||||
}
|
||||
resolve({
|
||||
length: received.length,
|
||||
ordered,
|
||||
last: received[received.length - 1]
|
||||
})
|
||||
}
|
||||
}
|
||||
api.core.invoke('spam', { channel }).catch(reject)
|
||||
setTimeout(
|
||||
() =>
|
||||
reject(
|
||||
new Error(
|
||||
`only received ${received.length} of ${count} messages`
|
||||
)
|
||||
),
|
||||
15000
|
||||
)
|
||||
}
|
||||
),
|
||||
1000
|
||||
)
|
||||
expect(result.length).toBe(1000)
|
||||
expect(result.ordered).toBe(true)
|
||||
expect(result.last).toBe(1000)
|
||||
})
|
||||
|
||||
itOn(
|
||||
['android', 'ios'],
|
||||
'a mobile plugin resolves JSArray and JSObject values as JSON arrays and objects',
|
||||
async () => {
|
||||
// On Android, the sample plugin's `jsValues` goes through
|
||||
// `Invoke.resolveObject`, i.e. the plugin JSON mapper rather than
|
||||
// org.json's own `toString`.
|
||||
const values = await tauri((api) =>
|
||||
api.core.invoke('plugin:sample|js_values')
|
||||
)
|
||||
expect(values).toEqual({
|
||||
array: ['a', 1, true],
|
||||
obj: { kind: 'object', nested: [1, 2] }
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
it('convertFileSrc builds a platform-appropriate asset URL', async () => {
|
||||
const url = await tauri((api) =>
|
||||
api.core.convertFileSrc('/path/to/file.png')
|
||||
)
|
||||
expect(url).toMatch(/(asset:\/\/localhost\/|https?:\/\/asset\.localhost\/)/)
|
||||
})
|
||||
})
|
||||
54
packages/api-e2e/test/specs/dpi.spec.ts
Normal file
54
packages/api-e2e/test/specs/dpi.spec.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { expect } from '@wdio/globals'
|
||||
import { tauri, describeApi } from '../helpers/index.js'
|
||||
|
||||
describeApi('dpi', () => {
|
||||
it('LogicalSize.toPhysical scales up by the factor', async () => {
|
||||
const physical = await tauri((api) => {
|
||||
const size = new api.dpi.LogicalSize(100, 50).toPhysical(2)
|
||||
return { width: size.width, height: size.height }
|
||||
})
|
||||
expect(physical).toEqual({ width: 200, height: 100 })
|
||||
})
|
||||
|
||||
it('PhysicalSize.toLogical scales down by the factor', async () => {
|
||||
const logical = await tauri((api) => {
|
||||
const size = new api.dpi.PhysicalSize(200, 100).toLogical(2)
|
||||
return { width: size.width, height: size.height }
|
||||
})
|
||||
expect(logical).toEqual({ width: 100, height: 50 })
|
||||
})
|
||||
|
||||
it('LogicalPosition.toPhysical and PhysicalPosition.toLogical round-trip', async () => {
|
||||
const result = await tauri((api) => {
|
||||
const physical = new api.dpi.LogicalPosition(10, 20).toPhysical(2)
|
||||
const logical = new api.dpi.PhysicalPosition(10, 20).toLogical(2)
|
||||
return {
|
||||
physical: { x: physical.x, y: physical.y },
|
||||
logical: { x: logical.x, y: logical.y }
|
||||
}
|
||||
})
|
||||
expect(result.physical).toEqual({ x: 20, y: 40 })
|
||||
expect(result.logical).toEqual({ x: 5, y: 10 })
|
||||
})
|
||||
|
||||
it('Size and Position wrappers delegate conversions', async () => {
|
||||
const result = await tauri((api) => {
|
||||
const size = new api.dpi.Size(
|
||||
new api.dpi.LogicalSize(100, 50)
|
||||
).toPhysical(2)
|
||||
const position = new api.dpi.Position(
|
||||
new api.dpi.PhysicalPosition(20, 40)
|
||||
).toLogical(2)
|
||||
return {
|
||||
size: { width: size.width, height: size.height },
|
||||
position: { x: position.x, y: position.y }
|
||||
}
|
||||
})
|
||||
expect(result.size).toEqual({ width: 200, height: 100 })
|
||||
expect(result.position).toEqual({ x: 10, y: 20 })
|
||||
})
|
||||
})
|
||||
125
packages/api-e2e/test/specs/event.spec.ts
Normal file
125
packages/api-e2e/test/specs/event.spec.ts
Normal file
@@ -0,0 +1,125 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { expect } from '@wdio/globals'
|
||||
import { tauri, describeApi } from '../helpers/index.js'
|
||||
|
||||
describeApi('event', () => {
|
||||
it('listen receives an emitted payload', async () => {
|
||||
const payload = await tauri(
|
||||
(api) =>
|
||||
new Promise<{ hello: string }>((resolve, reject) => {
|
||||
api.event
|
||||
.listen<{ hello: string }>('e2e://ping', (event) =>
|
||||
resolve(event.payload)
|
||||
)
|
||||
.then((unlisten) => {
|
||||
api.event.emit('e2e://ping', { hello: 'world' }).catch(reject)
|
||||
setTimeout(() => {
|
||||
unlisten()
|
||||
reject(new Error('event was not received'))
|
||||
}, 5000)
|
||||
})
|
||||
.catch(reject)
|
||||
})
|
||||
)
|
||||
expect(payload).toEqual({ hello: 'world' })
|
||||
})
|
||||
|
||||
it('once fires exactly once even if the event is emitted twice', async () => {
|
||||
const count = await tauri(
|
||||
(api) =>
|
||||
new Promise<number>((resolve, reject) => {
|
||||
let calls = 0
|
||||
api.event
|
||||
.once('e2e://once', () => {
|
||||
calls++
|
||||
})
|
||||
.then(async () => {
|
||||
await api.event.emit('e2e://once')
|
||||
await api.event.emit('e2e://once')
|
||||
setTimeout(() => resolve(calls), 1000)
|
||||
})
|
||||
.catch(reject)
|
||||
})
|
||||
)
|
||||
expect(count).toBe(1)
|
||||
})
|
||||
|
||||
it('unlisten stops further delivery', async () => {
|
||||
const count = await tauri(
|
||||
(api) =>
|
||||
new Promise<number>((resolve, reject) => {
|
||||
let calls = 0
|
||||
api.event
|
||||
.listen('e2e://off', () => {
|
||||
calls++
|
||||
})
|
||||
.then(async (unlisten) => {
|
||||
await api.event.emit('e2e://off')
|
||||
setTimeout(async () => {
|
||||
await unlisten()
|
||||
await api.event.emit('e2e://off')
|
||||
setTimeout(() => resolve(calls), 500)
|
||||
}, 500)
|
||||
})
|
||||
.catch(reject)
|
||||
})
|
||||
)
|
||||
expect(count).toBe(1)
|
||||
})
|
||||
|
||||
it('emitTo delivers only to the targeted label', async () => {
|
||||
const result = await tauri(
|
||||
(api) =>
|
||||
new Promise<{ mainCount: number }>((resolve, reject) => {
|
||||
let mainCount = 0
|
||||
api.event
|
||||
// The listener must be scoped to the `main` label: a default
|
||||
// `listen()` registers the `Any` target, a catch-all that receives
|
||||
// every emit regardless of the `emitTo` label (so it would also see
|
||||
// the `does-not-exist` emit).
|
||||
.listen(
|
||||
'e2e://target',
|
||||
() => {
|
||||
mainCount++
|
||||
},
|
||||
{ target: 'main' }
|
||||
)
|
||||
.then(async (unlisten) => {
|
||||
await api.event.emitTo('main', 'e2e://target') // delivered
|
||||
await api.event.emitTo('does-not-exist', 'e2e://target') // dropped
|
||||
setTimeout(async () => {
|
||||
await unlisten()
|
||||
resolve({ mainCount })
|
||||
}, 800)
|
||||
})
|
||||
.catch(reject)
|
||||
})
|
||||
)
|
||||
expect(result.mainCount).toBe(1)
|
||||
})
|
||||
|
||||
it('bridges events to and from the Rust backend', async () => {
|
||||
// examples/api listens for `js-event` and replies with `rust-event { data }`.
|
||||
const reply = await tauri(
|
||||
(api) =>
|
||||
new Promise<{ data: string }>((resolve, reject) => {
|
||||
api.event
|
||||
.listen<{ data: string }>('rust-event', (event) =>
|
||||
resolve(event.payload)
|
||||
)
|
||||
.then((unlisten) => {
|
||||
api.event.emit('js-event', 'hello from e2e').catch(reject)
|
||||
setTimeout(() => {
|
||||
unlisten()
|
||||
reject(new Error('no rust-event reply received'))
|
||||
}, 5000)
|
||||
})
|
||||
.catch(reject)
|
||||
})
|
||||
)
|
||||
expect(reply).toEqual({ data: 'something else' })
|
||||
})
|
||||
})
|
||||
31
packages/api-e2e/test/specs/image.spec.ts
Normal file
31
packages/api-e2e/test/specs/image.spec.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { expect } from '@wdio/globals'
|
||||
import { tauri, describeApi } from '../helpers/index.js'
|
||||
|
||||
describeApi('image', () => {
|
||||
it('Image.new round-trips raw rgba pixels', async () => {
|
||||
// 2x1 image: red pixel, green pixel.
|
||||
const rgba = [255, 0, 0, 255, 0, 255, 0, 255]
|
||||
const result = await tauri(
|
||||
async (api, pixels, width, height) => {
|
||||
const image = await api.image.Image.new(pixels, width, height)
|
||||
const size = await image.size()
|
||||
const bytes = await image.rgba()
|
||||
return {
|
||||
width: size.width,
|
||||
height: size.height,
|
||||
byteLength: bytes.length
|
||||
}
|
||||
},
|
||||
rgba,
|
||||
2,
|
||||
1
|
||||
)
|
||||
expect(result.width).toBe(2)
|
||||
expect(result.height).toBe(1)
|
||||
expect(result.byteLength).toBe(rgba.length)
|
||||
})
|
||||
})
|
||||
88
packages/api-e2e/test/specs/menu.spec.ts
Normal file
88
packages/api-e2e/test/specs/menu.spec.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { expect } from '@wdio/globals'
|
||||
import { tauri, describeApi } from '../helpers/index.js'
|
||||
|
||||
// The menu commands are all allowed by default. These tests only build and
|
||||
// inspect menu resources; they deliberately do not attach the menu to the app
|
||||
// or window, to avoid disturbing the live example app. The menu plugin is
|
||||
// desktop-only, so the whole module is skipped on mobile.
|
||||
describeApi('menu', { desktopOnly: true }, () => {
|
||||
it('Menu.new builds a menu with the given items', async () => {
|
||||
const result = await tauri(async (api) => {
|
||||
const item = await api.menu.MenuItem.new({ text: 'Item A' })
|
||||
const check = await api.menu.CheckMenuItem.new({
|
||||
text: 'Item B',
|
||||
checked: true
|
||||
})
|
||||
const separator = await api.menu.PredefinedMenuItem.new({
|
||||
item: 'Separator'
|
||||
})
|
||||
const submenu = await api.menu.Submenu.new({
|
||||
text: 'More',
|
||||
items: [await api.menu.MenuItem.new({ text: 'Nested' })]
|
||||
})
|
||||
const menu = await api.menu.Menu.new({
|
||||
items: [item, check, separator, submenu]
|
||||
})
|
||||
const items = await menu.items()
|
||||
return { count: items.length }
|
||||
})
|
||||
expect(result.count).toBe(4)
|
||||
})
|
||||
|
||||
it('MenuItem text and enabled state can be read and updated', async () => {
|
||||
const result = await tauri(async (api) => {
|
||||
const item = await api.menu.MenuItem.new({
|
||||
text: 'Original',
|
||||
enabled: true
|
||||
})
|
||||
const before = await item.text()
|
||||
await item.setText('Updated')
|
||||
const after = await item.text()
|
||||
const enabledBefore = await item.isEnabled()
|
||||
await item.setEnabled(false)
|
||||
const enabledAfter = await item.isEnabled()
|
||||
return { before, after, enabledBefore, enabledAfter }
|
||||
})
|
||||
expect(result.before).toBe('Original')
|
||||
expect(result.after).toBe('Updated')
|
||||
expect(result.enabledBefore).toBe(true)
|
||||
expect(result.enabledAfter).toBe(false)
|
||||
})
|
||||
|
||||
it('CheckMenuItem tracks its checked state', async () => {
|
||||
const result = await tauri(async (api) => {
|
||||
const item = await api.menu.CheckMenuItem.new({
|
||||
text: 'Toggle',
|
||||
checked: false
|
||||
})
|
||||
// On Windows the checked state lives in the native menu the item belongs
|
||||
// to, so it must be attached to a menu to be readable.
|
||||
await api.menu.Menu.new({ items: [item] })
|
||||
const before = await item.isChecked()
|
||||
await item.setChecked(true)
|
||||
const after = await item.isChecked()
|
||||
return { before, after }
|
||||
})
|
||||
expect(result.before).toBe(false)
|
||||
expect(result.after).toBe(true)
|
||||
})
|
||||
|
||||
it('append and removeAt mutate the item list', async () => {
|
||||
const result = await tauri(async (api) => {
|
||||
const menu = await api.menu.Menu.new({
|
||||
items: [await api.menu.MenuItem.new({ text: 'First' })]
|
||||
})
|
||||
await menu.append(await api.menu.MenuItem.new({ text: 'Second' }))
|
||||
const afterAppend = (await menu.items()).length
|
||||
await menu.removeAt(0)
|
||||
const afterRemove = (await menu.items()).length
|
||||
return { afterAppend, afterRemove }
|
||||
})
|
||||
expect(result.afterAppend).toBe(2)
|
||||
expect(result.afterRemove).toBe(1)
|
||||
})
|
||||
})
|
||||
62
packages/api-e2e/test/specs/path.spec.ts
Normal file
62
packages/api-e2e/test/specs/path.spec.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import nodePath from 'node:path'
|
||||
import { expect } from '@wdio/globals'
|
||||
import { tauri, describeApi, platform } from '../helpers/index.js'
|
||||
|
||||
// Node's path module for the platform the *app* runs on. That is the host for
|
||||
// the desktop suite, but the mobile suites drive an Android/iOS app (POSIX
|
||||
// paths) from whatever OS hosts the emulator/simulator.
|
||||
const path = platform === 'win32' ? nodePath.win32 : nodePath.posix
|
||||
|
||||
describeApi('path', () => {
|
||||
it('sep and delimiter match the target platform', async () => {
|
||||
const separators = await tauri((api) => ({
|
||||
sep: api.path.sep(),
|
||||
delimiter: api.path.delimiter()
|
||||
}))
|
||||
expect(separators.sep).toBe(path.sep)
|
||||
expect(separators.delimiter).toBe(path.delimiter)
|
||||
})
|
||||
|
||||
it('join, dirname, basename and extname behave like the platform', async () => {
|
||||
const result = await tauri(async (api) => ({
|
||||
joined: await api.path.join('a', 'b', 'c.txt'),
|
||||
dir: await api.path.dirname(await api.path.join('a', 'b', 'c.txt')),
|
||||
base: await api.path.basename(await api.path.join('a', 'b', 'c.txt')),
|
||||
ext: await api.path.extname(await api.path.join('a', 'b', 'c.txt'))
|
||||
}))
|
||||
expect(result.joined).toBe(path.join('a', 'b', 'c.txt'))
|
||||
expect(result.base).toBe('c.txt')
|
||||
expect(result.ext).toBe('txt')
|
||||
expect(result.dir.endsWith(path.join('a', 'b'))).toBe(true)
|
||||
})
|
||||
|
||||
it('normalize and isAbsolute work', async () => {
|
||||
const result = await tauri(async (api) => ({
|
||||
normalized: await api.path.normalize('a/b/../c'),
|
||||
absoluteIsAbsolute: await api.path.isAbsolute(
|
||||
await api.path.resolve('x')
|
||||
),
|
||||
relativeIsAbsolute: await api.path.isAbsolute('a/b')
|
||||
}))
|
||||
expect(result.normalized).toContain('c')
|
||||
expect(result.absoluteIsAbsolute).toBe(true)
|
||||
expect(result.relativeIsAbsolute).toBe(false)
|
||||
})
|
||||
|
||||
it('app directories are absolute and scoped to the identifier', async () => {
|
||||
const dirs = await tauri(async (api) => ({
|
||||
appData: await api.path.appDataDir(),
|
||||
appConfig: await api.path.appConfigDir(),
|
||||
home: await api.path.homeDir(),
|
||||
temp: await api.path.tempDir()
|
||||
}))
|
||||
expect(dirs.appData).toContain('com.tauri.api')
|
||||
expect(dirs.appConfig.length).toBeGreaterThan(0)
|
||||
expect(dirs.home.length).toBeGreaterThan(0)
|
||||
expect(dirs.temp.length).toBeGreaterThan(0)
|
||||
})
|
||||
})
|
||||
43
packages/api-e2e/test/specs/tray.spec.ts
Normal file
43
packages/api-e2e/test/specs/tray.spec.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { expect } from '@wdio/globals'
|
||||
import { tauri, describeApi } from '../helpers/index.js'
|
||||
|
||||
// Tray commands are allowed by default, but a tray host is not always available
|
||||
// in headless environments — set `E2E_SKIP=tray` there. The tray plugin is
|
||||
// desktop-only, so the whole module is skipped on mobile.
|
||||
describeApi('tray', { desktopOnly: true }, () => {
|
||||
it('creates a tray icon, looks it up and removes it', async () => {
|
||||
const created = await tauri(async (api) => {
|
||||
const icon = await api.app.defaultWindowIcon()
|
||||
const tray = await api.tray.TrayIcon.new({
|
||||
id: 'e2e-tray',
|
||||
icon: icon ?? undefined,
|
||||
tooltip: 'e2e tray'
|
||||
})
|
||||
return tray.id
|
||||
})
|
||||
expect(created).toBe('e2e-tray')
|
||||
|
||||
const foundById = await tauri(async (api) => {
|
||||
const tray = await api.tray.TrayIcon.getById('e2e-tray')
|
||||
return tray !== null
|
||||
})
|
||||
expect(foundById).toBe(true)
|
||||
|
||||
await tauri(async (api) => {
|
||||
const tray = await api.tray.TrayIcon.getById('e2e-tray')
|
||||
await tray?.setVisible(true)
|
||||
return null
|
||||
})
|
||||
|
||||
const removed = await tauri(async (api) => {
|
||||
await api.tray.TrayIcon.removeById('e2e-tray')
|
||||
const tray = await api.tray.TrayIcon.getById('e2e-tray')
|
||||
return tray === null
|
||||
})
|
||||
expect(removed).toBe(true)
|
||||
})
|
||||
})
|
||||
44
packages/api-e2e/test/specs/webview.spec.ts
Normal file
44
packages/api-e2e/test/specs/webview.spec.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { expect } from '@wdio/globals'
|
||||
import { tauri, describeApi, itDesktop } from '../helpers/index.js'
|
||||
|
||||
describeApi('webview', () => {
|
||||
it('getCurrentWebview reports the main label', async () => {
|
||||
expect(await tauri((api) => api.webview.getCurrentWebview().label)).toBe(
|
||||
'main'
|
||||
)
|
||||
})
|
||||
|
||||
it('getAllWebviews includes the main webview', async () => {
|
||||
const labels = await tauri(async (api) =>
|
||||
(await api.webview.getAllWebviews()).map((w) => w.label)
|
||||
)
|
||||
expect(labels).toContain('main')
|
||||
})
|
||||
|
||||
// `webview_position`/`webview_size` are desktop-only commands: on mobile the
|
||||
// webview always fills the window.
|
||||
itDesktop('exposes a physical position and size', async () => {
|
||||
const rect = await tauri(async (api) => {
|
||||
const wv = api.webview.getCurrentWebview()
|
||||
const pos = await wv.position()
|
||||
const size = await wv.size()
|
||||
return { x: pos.x, y: pos.y, width: size.width, height: size.height }
|
||||
})
|
||||
expect(rect.width).toBeGreaterThan(0)
|
||||
expect(rect.height).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
itDesktop('setZoom adjusts and restores the zoom level', async () => {
|
||||
// Requires `core:webview:allow-set-webview-zoom` in the run-app capability.
|
||||
await tauri(async (api) => {
|
||||
const wv = api.webview.getCurrentWebview()
|
||||
await wv.setZoom(1.5)
|
||||
await wv.setZoom(1)
|
||||
return null
|
||||
})
|
||||
})
|
||||
})
|
||||
64
packages/api-e2e/test/specs/webviewWindow.spec.ts
Normal file
64
packages/api-e2e/test/specs/webviewWindow.spec.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { expect } from '@wdio/globals'
|
||||
import { tauri, eventually, describeApi, itDesktop } from '../helpers/index.js'
|
||||
|
||||
describeApi('webviewWindow', () => {
|
||||
it('getCurrentWebviewWindow reports the main label', async () => {
|
||||
expect(
|
||||
await tauri((api) => api.webviewWindow.getCurrentWebviewWindow().label)
|
||||
).toBe('main')
|
||||
})
|
||||
|
||||
// On mobile a new window is a new Android activity / iOS scene that takes
|
||||
// over the foreground (and the automation session's webview context), so
|
||||
// this is only exercised on desktop.
|
||||
itDesktop('creates, finds and closes a new webview window', async () => {
|
||||
// The label must match `main-*` to inherit the run-app capability.
|
||||
const created = await tauri(
|
||||
(api) =>
|
||||
new Promise<boolean>((resolve, reject) => {
|
||||
const w = new api.webviewWindow.WebviewWindow('main-e2e', {
|
||||
width: 400,
|
||||
height: 300
|
||||
})
|
||||
w.once('tauri://created', () => resolve(true)).catch(reject)
|
||||
w.once('tauri://error', (event) =>
|
||||
reject(
|
||||
new Error(`window creation failed: ${String(event.payload)}`)
|
||||
)
|
||||
).catch(reject)
|
||||
setTimeout(() => reject(new Error('window creation timed out')), 8000)
|
||||
})
|
||||
)
|
||||
expect(created).toBe(true)
|
||||
|
||||
const found = await tauri(async (api) => {
|
||||
const byLabel =
|
||||
await api.webviewWindow.WebviewWindow.getByLabel('main-e2e')
|
||||
const all = (await api.webviewWindow.getAllWebviewWindows()).map(
|
||||
(w) => w.label
|
||||
)
|
||||
return { exists: byLabel !== null, all }
|
||||
})
|
||||
expect(found.exists).toBe(true)
|
||||
expect(found.all).toContain('main-e2e')
|
||||
|
||||
await tauri(async (api) => {
|
||||
const w = await api.webviewWindow.WebviewWindow.getByLabel('main-e2e')
|
||||
await w?.close()
|
||||
return null
|
||||
})
|
||||
|
||||
await eventually(async () => {
|
||||
const labels = await tauri(async (api) =>
|
||||
(await api.webviewWindow.getAllWebviewWindows()).map((w) => w.label)
|
||||
)
|
||||
if (labels.includes('main-e2e')) {
|
||||
throw new Error('window is still present after close')
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
295
packages/api-e2e/test/specs/window.spec.ts
Normal file
295
packages/api-e2e/test/specs/window.spec.ts
Normal file
@@ -0,0 +1,295 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { expect } from '@wdio/globals'
|
||||
import {
|
||||
tauri,
|
||||
eventually,
|
||||
describeApi,
|
||||
itWm,
|
||||
itDesktop,
|
||||
itOn
|
||||
} from '../helpers/index.js'
|
||||
|
||||
describeApi('window', () => {
|
||||
it('getCurrentWindow reports the main label', async () => {
|
||||
expect(await tauri((api) => api.window.getCurrentWindow().label)).toBe(
|
||||
'main'
|
||||
)
|
||||
})
|
||||
|
||||
it('getAllWindows includes the main window', async () => {
|
||||
const labels = await tauri(async (api) =>
|
||||
(await api.window.getAllWindows()).map((w) => w.label)
|
||||
)
|
||||
expect(labels).toContain('main')
|
||||
})
|
||||
|
||||
// Mobile windows have no title bar: `title()` is always empty and
|
||||
// `setTitle` a no-op there.
|
||||
itDesktop('title can be read and set', async () => {
|
||||
const original = await tauri((api) => api.window.getCurrentWindow().title())
|
||||
await tauri((api) => api.window.getCurrentWindow().setTitle('e2e title'))
|
||||
expect(await tauri((api) => api.window.getCurrentWindow().title())).toBe(
|
||||
'e2e title'
|
||||
)
|
||||
// restore
|
||||
await tauri(
|
||||
(api, title) => api.window.getCurrentWindow().setTitle(title),
|
||||
original
|
||||
)
|
||||
})
|
||||
|
||||
it('reports a positive scale factor and sizes', async () => {
|
||||
const metrics = await tauri(async (api) => {
|
||||
const w = api.window.getCurrentWindow()
|
||||
const scale = await w.scaleFactor()
|
||||
const inner = await w.innerSize()
|
||||
const outer = await w.outerSize()
|
||||
return {
|
||||
scale,
|
||||
inner: { width: inner.width, height: inner.height },
|
||||
outer: { width: outer.width, height: outer.height }
|
||||
}
|
||||
})
|
||||
expect(metrics.scale).toBeGreaterThan(0)
|
||||
expect(metrics.inner.width).toBeGreaterThan(0)
|
||||
expect(metrics.inner.height).toBeGreaterThan(0)
|
||||
expect(metrics.outer.width).toBeGreaterThanOrEqual(metrics.inner.width)
|
||||
})
|
||||
|
||||
itOn(
|
||||
'android',
|
||||
'activityName reports the activity hosting the window',
|
||||
async () => {
|
||||
const name = await tauri((api) =>
|
||||
api.window.getCurrentWindow().activityName()
|
||||
)
|
||||
expect(name).toMatch(/MainActivity/)
|
||||
}
|
||||
)
|
||||
|
||||
// The window is the whole screen on mobile: `set_size` is a no-op.
|
||||
itDesktop('setSize resizes the window', async () => {
|
||||
const scale = await tauri((api) =>
|
||||
api.window.getCurrentWindow().scaleFactor()
|
||||
)
|
||||
const original = await tauri(async (api) => {
|
||||
const size = await api.window.getCurrentWindow().innerSize()
|
||||
return { width: size.width, height: size.height }
|
||||
})
|
||||
|
||||
await tauri(
|
||||
(api, width, height) =>
|
||||
api.window
|
||||
.getCurrentWindow()
|
||||
.setSize(new api.dpi.LogicalSize(width, height)),
|
||||
600,
|
||||
400
|
||||
)
|
||||
|
||||
await eventually(async () => {
|
||||
const inner = await tauri(async (api) => {
|
||||
const size = await api.window.getCurrentWindow().innerSize()
|
||||
return { width: size.width, height: size.height }
|
||||
})
|
||||
const tolerance = Math.ceil(scale) * 4
|
||||
if (Math.abs(inner.width - 600 * scale) > tolerance) {
|
||||
throw new Error(`width ${inner.width} not near ${600 * scale}`)
|
||||
}
|
||||
if (Math.abs(inner.height - 400 * scale) > tolerance) {
|
||||
throw new Error(`height ${inner.height} not near ${400 * scale}`)
|
||||
}
|
||||
})
|
||||
|
||||
// restore the original physical size
|
||||
await tauri(
|
||||
(api, width, height) =>
|
||||
api.window
|
||||
.getCurrentWindow()
|
||||
.setSize(new api.dpi.PhysicalSize(width, height)),
|
||||
original.width,
|
||||
original.height
|
||||
)
|
||||
})
|
||||
|
||||
// Mobile windows are never resizable (`is_resizable` is always `false`).
|
||||
itDesktop('setResizable toggles resizability', async () => {
|
||||
await tauri((api) => api.window.getCurrentWindow().setResizable(false))
|
||||
expect(
|
||||
await tauri((api) => api.window.getCurrentWindow().isResizable())
|
||||
).toBe(false)
|
||||
await tauri((api) => api.window.getCurrentWindow().setResizable(true))
|
||||
expect(
|
||||
await tauri((api) => api.window.getCurrentWindow().isResizable())
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
// Desktop-only commands (`#[cfg(desktop)]` in the window plugin).
|
||||
itDesktop('assorted setters resolve without throwing', async () => {
|
||||
await tauri(async (api) => {
|
||||
const w = api.window.getCurrentWindow()
|
||||
await w.setAlwaysOnTop(true)
|
||||
await w.setAlwaysOnTop(false)
|
||||
await w.setShadow(true)
|
||||
await w.setContentProtected(false)
|
||||
await w.setCursorVisible(true)
|
||||
await w.requestUserAttention(null)
|
||||
return null
|
||||
})
|
||||
})
|
||||
|
||||
itWm('setPosition moves the window', async () => {
|
||||
const original = await tauri(async (api) => {
|
||||
const pos = await api.window.getCurrentWindow().outerPosition()
|
||||
return { x: pos.x, y: pos.y }
|
||||
})
|
||||
|
||||
await tauri(
|
||||
(api, x, y) =>
|
||||
api.window
|
||||
.getCurrentWindow()
|
||||
.setPosition(new api.dpi.PhysicalPosition(x, y)),
|
||||
original.x + 40,
|
||||
original.y + 40
|
||||
)
|
||||
|
||||
await eventually(async () => {
|
||||
const pos = await tauri(async (api) => {
|
||||
const p = await api.window.getCurrentWindow().outerPosition()
|
||||
return { x: p.x, y: p.y }
|
||||
})
|
||||
// Window managers can nudge the final position; allow a generous tolerance.
|
||||
if (
|
||||
Math.abs(pos.x - (original.x + 40)) > 30
|
||||
|| Math.abs(pos.y - (original.y + 40)) > 30
|
||||
) {
|
||||
throw new Error(
|
||||
`position ${pos.x},${pos.y} not near ${original.x + 40},${original.y + 40}`
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
await tauri(
|
||||
(api, x, y) =>
|
||||
api.window
|
||||
.getCurrentWindow()
|
||||
.setPosition(new api.dpi.PhysicalPosition(x, y)),
|
||||
original.x,
|
||||
original.y
|
||||
)
|
||||
})
|
||||
|
||||
itWm('minimize and unminimize toggle the minimized state', async () => {
|
||||
await tauri((api) => api.window.getCurrentWindow().minimize())
|
||||
await eventually(async () => {
|
||||
if (
|
||||
!(await tauri((api) => api.window.getCurrentWindow().isMinimized()))
|
||||
) {
|
||||
throw new Error('window is not minimized')
|
||||
}
|
||||
})
|
||||
await tauri((api) => api.window.getCurrentWindow().unminimize())
|
||||
await eventually(async () => {
|
||||
if (await tauri((api) => api.window.getCurrentWindow().isMinimized())) {
|
||||
throw new Error('window is still minimized')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
itWm('maximize and unmaximize toggle the maximized state', async () => {
|
||||
await tauri((api) => api.window.getCurrentWindow().maximize())
|
||||
await eventually(async () => {
|
||||
if (
|
||||
!(await tauri((api) => api.window.getCurrentWindow().isMaximized()))
|
||||
) {
|
||||
throw new Error('window is not maximized')
|
||||
}
|
||||
})
|
||||
await tauri((api) => api.window.getCurrentWindow().unmaximize())
|
||||
await eventually(async () => {
|
||||
if (await tauri((api) => api.window.getCurrentWindow().isMaximized())) {
|
||||
throw new Error('window is still maximized')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
itWm('setFullscreen toggles fullscreen', async () => {
|
||||
await tauri((api) => api.window.getCurrentWindow().setFullscreen(true))
|
||||
await eventually(async () => {
|
||||
if (
|
||||
!(await tauri((api) => api.window.getCurrentWindow().isFullscreen()))
|
||||
) {
|
||||
throw new Error('window is not fullscreen')
|
||||
}
|
||||
})
|
||||
await tauri((api) => api.window.getCurrentWindow().setFullscreen(false))
|
||||
await eventually(async () => {
|
||||
if (await tauri((api) => api.window.getCurrentWindow().isFullscreen())) {
|
||||
throw new Error('window is still fullscreen')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
itWm('setFullscreenOnMonitor goes fullscreen on that monitor', async () => {
|
||||
// Use the monitor the window is on, so the assertion holds on single-monitor CI.
|
||||
const origin = await tauri(async (api) => {
|
||||
const monitor = await api.window.currentMonitor()
|
||||
return monitor ? { x: monitor.position.x, y: monitor.position.y } : null
|
||||
})
|
||||
expect(origin).not.toBeNull()
|
||||
|
||||
await tauri(
|
||||
(api, origin) =>
|
||||
api.window
|
||||
.getCurrentWindow()
|
||||
.setFullscreenOnMonitor(
|
||||
new api.dpi.PhysicalPosition(origin.x, origin.y)
|
||||
),
|
||||
origin!
|
||||
)
|
||||
await eventually(async () => {
|
||||
const state = await tauri(async (api) => {
|
||||
const w = api.window.getCurrentWindow()
|
||||
const position = await w.outerPosition()
|
||||
return {
|
||||
fullscreen: await w.isFullscreen(),
|
||||
x: position.x,
|
||||
y: position.y
|
||||
}
|
||||
})
|
||||
if (!state.fullscreen) {
|
||||
throw new Error('window is not fullscreen')
|
||||
}
|
||||
// a fullscreen window sits at its monitor's origin
|
||||
if (state.x !== origin!.x || state.y !== origin!.y) {
|
||||
throw new Error(
|
||||
`window is at (${state.x}, ${state.y}), expected (${origin!.x}, ${origin!.y})`
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
await tauri((api) => api.window.getCurrentWindow().setFullscreen(false))
|
||||
await eventually(async () => {
|
||||
if (await tauri((api) => api.window.getCurrentWindow().isFullscreen())) {
|
||||
throw new Error('window is still fullscreen')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
itWm('hide and show toggle visibility', async () => {
|
||||
await tauri((api) => api.window.getCurrentWindow().hide())
|
||||
await eventually(async () => {
|
||||
if (await tauri((api) => api.window.getCurrentWindow().isVisible())) {
|
||||
throw new Error('window is still visible')
|
||||
}
|
||||
})
|
||||
await tauri((api) => api.window.getCurrentWindow().show())
|
||||
await eventually(async () => {
|
||||
if (!(await tauri((api) => api.window.getCurrentWindow().isVisible()))) {
|
||||
throw new Error('window is not visible')
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user