Skip to content

Commit

Permalink
Add tests for move by line and char
Browse files Browse the repository at this point in the history
  • Loading branch information
feerrenrut committed Aug 4, 2021
1 parent 8c8e2bb commit fa5929f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 13 deletions.
77 changes: 66 additions & 11 deletions tests/system/robot/notepadTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"""Logic for reading text using NVDA in the notepad text editor.
"""
# imported methods start with underscore (_) so they don't get imported into robot files as keywords
import typing

from SystemTestSpy import (
_getLib,
)
Expand All @@ -14,14 +16,32 @@
from NotepadLib import NotepadLib as _NotepadLib
from AssertsLib import AssertsLib as _AssertsLib
import NvdaLib as _NvdaLib
from robot.libraries.BuiltIn import BuiltIn

builtIn: BuiltIn = BuiltIn()
_notepad: _NotepadLib = _getLib("NotepadLib")
_asserts: _AssertsLib = _getLib("AssertsLib")

navToNextCharKey = "numpad3"
navToNextWordKey = "numpad6"
navToNextLineKey = "numpad9"


def _pressKeyAndCollectSpeech(key: str, numberOfTimes: int) -> typing.List[str]:
actual = []
for _ in range(numberOfTimes):
spoken = _NvdaLib.getSpeechAfterKey(key)
# collect all output before asserting to show full picture of behavior
actual.append(spoken)
return actual


def test_moveByWord_symbolLevelWord():
"""Disabled due to revert of PR #11856 is: "Speak all symbols when moving by words (#11779)
"""
spy = _NvdaLib.getSpyLib()
spy.set_configValue(["speech", "symbolLevelWordAll"], True)

# unlike other symbols used, symbols.dic doesn't preserve quote symbols with SYMPRES_ALWAYS
_wordsToExpected = {
'Say': 'Say',
Expand All @@ -32,17 +52,16 @@ def test_moveByWord_symbolLevelWord():
'👕': 't-shirt', # Speech for symbols shouldn't change
}

spy = _NvdaLib.getSpyLib()
spy.set_configValue(["speech", "symbolLevelWordAll"], True)

textStr = ' '.join(_wordsToExpected.keys())
_notepad.prepareNotepad(f"Test: {textStr}")
for expectedWord in _wordsToExpected.values():
wordSpoken = _NvdaLib.getSpeechAfterKey("numpad6") # navigate to next word
_asserts.strings_match(wordSpoken, expectedWord)
actual = _pressKeyAndCollectSpeech(navToNextWordKey, numberOfTimes=len(_wordsToExpected))
builtIn.should_be_equal(actual, list(_wordsToExpected.values()))


def test_moveByWord():
spy = _NvdaLib.getSpyLib()
spy.set_configValue(["speech", "symbolLevelWordAll"], False)

_wordsToExpected = {
'Say': 'Say',
'(quietly)': '(quietly)',
Expand All @@ -52,11 +71,47 @@ def test_moveByWord():
'👕': 't shirt',
}

textStr = ' '.join(_wordsToExpected.keys())
_notepad.prepareNotepad(f"Test: {textStr}")
actual = _pressKeyAndCollectSpeech(navToNextWordKey, numberOfTimes=len(_wordsToExpected))
builtIn.should_be_equal(actual, list(_wordsToExpected.values()))


def test_moveByLine():
spy = _NvdaLib.getSpyLib()
spy.set_configValue(["speech", "symbolLevelWordAll"], False)

_wordsToExpected = {
'Say': 'Say',
'(quietly)': '(quietly)',
'"Hello,': 'Hello,',
'Jim".': 'Jim .',
'➔': 'right-pointing arrow',
'👕': 't-shirt',
}

textStr = '\n'.join(_wordsToExpected.keys())
_notepad.prepareNotepad(f"Test:\n{textStr}") # initial new line which isn't spoken
actual = _pressKeyAndCollectSpeech(navToNextLineKey, numberOfTimes=len(_wordsToExpected))
builtIn.should_be_equal(actual, list(_wordsToExpected.values()))


def test_moveByChar():
spy = _NvdaLib.getSpyLib()
spy.set_configValue(["speech", "symbolLevelWordAll"], False)

textStr = ' '.join(_wordsToExpected.keys())
_notepad.prepareNotepad(f"Test: {textStr}")
for expectedWord in _wordsToExpected.values():
wordSpoken = _NvdaLib.getSpeechAfterKey("numpad6") # navigate to next word
_asserts.strings_match(wordSpoken, expectedWord)
_text = 'S ()e,➔👕' # to speed up test, reduce superfluous characters
_expected = [
'S',
'space',
'left paren',
'right paren',
'e',
'comma',
'right pointing arrow',
't shirt',
]

_notepad.prepareNotepad(f" {_text}")
actual = _pressKeyAndCollectSpeech(navToNextCharKey, numberOfTimes=len(_expected))
builtIn.should_be_equal(actual, _expected)
10 changes: 8 additions & 2 deletions tests/system/robot/notepadTests.robot
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Test Teardown default teardown
default teardown
${screenshotName}= create_preserved_test_output_filename failedTest.png
Run Keyword If Test Failed Take Screenshot ${screenShotName}
Run Keyword If Test Failed dump_speech_to_log
dump_speech_to_log
exit notepad
quit NVDA

Expand All @@ -33,5 +33,11 @@ moveByWord with symbolLevelWord
[Documentation] Ensure all symbols are read when navigating by word.
test_moveByWord_symbolLevelWord
moveByWord
[Documentation] Ensure symbols announced as expected when navigating by word.
[Documentation] Ensure symbols announced as expected when navigating by word (numpad 6).
test_moveByWord
moveByLine
[Documentation] Ensure symbols announced as expected when navigating by line (numpad 9).
test_moveByLine
moveByCharacter
[Documentation] Ensure symbols announced as expected when navigating by character (numpad 3).
test_moveByChar

0 comments on commit fa5929f

Please sign in to comment.