#!/usr/bin/env bash # ElyDoc: undated notes are named; the lists stay visible. set -euo pipefail root=$(cd "$(dirname "$0")/../.." && pwd) [ "$(uname)" = Darwin ] || { echo "SKIP: macOS only"; exit 0; } work=$(mktemp -d) trap 'kill "${pid:-0}" 2>/dev/null || true; rm -rf "$work"' EXIT fail() { echo "FAIL: $*" >&2 exit 1 } cargo build -q -p ely-lok --bins -p ely-doc --manifest-path "$root/Cargo.toml" swiftc -O -o "$work/axv" "$root/tests/scripts/ax-values.swift" [ "$("$work/axv" $$)" != untrusted ] || { echo "SKIP: needs Accessibility permission"; exit 0; } # One dated note, twenty without a date, one tracked insertion. python3 - "$work/notes.docx" <<'PY' import sys, zipfile W = 'xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"' notes = ['Valid note'] paras = [] for i in range(21): if i: notes.append(f'Note {i}') paras.append(f'Para {i}') paras.append('Tracked') rel = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships' files = { '[Content_Types].xml': '', '_rels/.rels': f'', 'word/_rels/document.xml.rels': f'', 'word/comments.xml': f'' + ''.join(notes) + '', 'word/document.xml': f'' + ''.join(paras) + '', } with zipfile.ZipFile(sys.argv[1], 'w') as z: for name, text in files.items(): z.writestr(name, text) PY ELY_LOCALE=en ELY_NO_DIALOG=1 HOME="$work" XDG_DATA_HOME="$work/data" \ perl -e 'alarm 120; exec @ARGV' "$root/target/debug/ely-doc" "$work/notes.docx" >"$work/out" 2>"$work/err" & pid=$! log() { find "$work" -path '*/ElyOffice/ely-doc/ely.log' 2>/dev/null | head -n 1; } for _ in $(seq 200); do grep -q "review lists 21 notes, 1 changes" "$(log)" 2>/dev/null && break; sleep 0.2; done grep -q "review lists 21 notes, 1 changes" "$(log)" || fail "the lists did not read: $(tail -n 3 "$(log)")" "$work/axv" "$pid" >/dev/null osascript -e "tell application \"System Events\" to tell (first process whose unix id is $pid)" -e 'set frontmost to true' \ -e 'click menu item "Comments and Changes" of menu "Review" of menu bar 1' -e 'end tell' >/dev/null seen= for _ in $(seq 10); do seen=$("$work/axv" "$pid") grep -q "ValidAuthor: Valid note" <<<"$seen" && break sleep 1 done [ "$(grep -c "A comment by Undated[0-9]* has an unreadable time" <<<"$seen")" = 20 ] || fail "each undated note is not named" # The valid note's center lies inside the window. read -r top height < <(osascript -e "tell application \"System Events\" to tell (first process whose unix id is $pid)" \ -e 'set {x, y} to position of window 1' -e 'set {w, h} to size of window 1' -e 'return (y as text) & " " & (h as text)' -e 'end tell') at=$(grep "ValidAuthor: Valid note" <<<"$seen" | head -n 1 | sed 's/.*at=[0-9]*,//') [ -n "$at" ] && [ "$at" -lt $((top + height)) ] || fail "the valid note sits below the window ($at, window ends $((top + height)))" echo "ok: doc-review"