# Integrations pass (S009): spell check. Offline: a tiny en_US hunspell dictionary (tests/smoke/data/dict) is copied
# into the throwaway cache first. Run:
#   h=target/smoke/integ-spell-home; rm -rf $h; mkdir -p $h/.cache/nacre-browser/dictionaries
#   cp tests/smoke/data/dict/en_US.* $h/.cache/nacre-browser/dictionaries/
#   python3 -m http.server 8768 --bind 127.0.0.1 --directory tests/smoke/pages &
#   SMOKE_HOME=$PWD/$h tools/smoke.sh tests/smoke/integ-spell.txt target/smoke/integ-spell
# Read spell-menu.png: the page menu over the misspelled word lists "mistake" and "Add ... to the dictionary".
set /spell/langs ["en_US"]
wait 3
open http://127.0.0.1:8768/spell.html
waitload
locate #area
wait 1
click @
pagetype hello wrold this is a mistaek
wait 2
shot spell-marked
# The mirror underlines the two wrong words only.
assert document.querySelectorAll('.__nacre_spell_mirror u').length === 2
assert [...document.querySelectorAll('.__nacre_spell_mirror u')].map(u => u.textContent).join() === 'wrold,mistaek'
js window.__nacre.spell.replace('wrold', 'world'); document.getElementById('area').value
wait 1
assert document.getElementById('area').value === 'hello world this is a mistaek'
# Right-click the misspelled word at the end of the text: the menu offers suggestions.
rclick 215 33
wait 1
shot spell-menu
# Choosing the suggestion replaces the word.
tap 299 154
wait 1
assert document.getElementById('area').value === 'hello world this is a mistake'
# A single-line input inside a positioned, transformed box (S056: the underline crossed the text on a search page):
# the mirror sits exactly on the field and its line box fills the field's content height (text centred like the input).
locate #line
wait 1
click @
pagetype wrold here
wait 2
shot spell-input
assert (() => { const m = document.querySelector('.__nacre_spell_mirror'), a = m.getBoundingClientRect(), b = document.getElementById('line').getBoundingClientRect(); return Math.abs(a.top - b.top) < 1 && Math.abs(a.left - b.left) < 1 && Math.abs(a.height - b.height) < 1; })()
assert (() => { const u = document.querySelector('.__nacre_spell_mirror u'); if (!u) return false; const r = u.getBoundingClientRect(), b = document.getElementById('line').getBoundingClientRect(); return Math.abs((r.top + r.bottom) / 2 - (b.top + b.bottom) / 2) < 3; })()
status done
quit
