Files
OSGKeyboard/OSGKeyboardTests/EditableInputReferenceTests.swift
T
Rocky 2bc8c1b87d fix(ipad): ship iPad P0 layout/globe fixes, edit-last-input, drop clipboard commands
Adapt typing/voice surfaces for iPad width and height, add the system globe
key and last-input editing flow, harden host-only Rime deployment, and remove
clipboard voice commands. Bump build to 61.
2026-08-10 13:50:50 +08:00

64 lines
2.1 KiB
Swift

import XCTest
@testable import OSGKeyboardShared
final class EditableInputReferenceTests: XCTestCase {
func testReferenceExpiresAfterTenMinutes() {
let reference = EditableInputReference(
displayText: "hello",
insertedText: " hello",
postInsertionFingerprint: "field",
extensionInstanceID: UUID(),
createdAt: 100
)
XCTAssertFalse(reference.isExpired(at: 699))
XCTAssertTrue(reference.isExpired(at: 700))
}
func testRebuiltExtensionRequiresFullSuffixAndFingerprint() {
let reference = EditableInputReference(
displayText: "hello",
insertedText: " hello",
postInsertionFingerprint: "field",
extensionInstanceID: UUID(),
createdAt: Date().timeIntervalSince1970
)
XCTAssertTrue(
reference.isFullyVerified(
contextBeforeInput: "prefix hello",
fieldFingerprint: "field"
)
)
XCTAssertFalse(
reference.isFullyVerified(
contextBeforeInput: "prefix hello",
fieldFingerprint: "other"
)
)
XCTAssertFalse(
reference.isFullyVerified(
contextBeforeInput: "different",
fieldFingerprint: "field"
)
)
}
func testStoreRoundTripAndExpiryCleanup() throws {
let suite = "EditableInputReferenceTests.\(UUID().uuidString)"
let defaults = try XCTUnwrap(UserDefaults(suiteName: suite))
defer { defaults.removePersistentDomain(forName: suite) }
let reference = EditableInputReference(
displayText: "hello",
insertedText: "hello",
postInsertionFingerprint: nil,
extensionInstanceID: UUID(),
createdAt: 100
)
EditableInputReferenceStore.save(reference, defaults: defaults)
XCTAssertEqual(
EditableInputReferenceStore.load(defaults: defaults, now: 200),
reference
)
XCTAssertNil(EditableInputReferenceStore.load(defaults: defaults, now: 701))
}
}