Commit ea63b86e authored by Robert Loehning's avatar Robert Loehning Committed by Robert Löhning
Browse files

Squish: Replaced function moveTextCursor



Change-Id: Ie4cccd0de668690a3d66baf422bcfff7acae7345
Reviewed-by: default avatarChristian Stenger <christian.stenger@nokia.com>
parent 53fb9d4a
......@@ -30,21 +30,6 @@ def placeCursorToLine(editor, line, isRegex=False):
editor.setTextCursor(cursor)
return True
# this function moves the text cursor of an editor by using Qt internal functions
# this is more reliable (especially on Mac) than the type() approach
# param editor an editor object
# param moveOperation a value of enum MoveOperation (of QTextCursor)
# param moveAnchor a value of enum MoveMode (of QTextCursor)
# param n how often repeat the move operation?
def moveTextCursor(editor, moveOperation, moveAnchor, n=1):
if not editor or isinstance(editor, (str,unicode)):
test.fatal("Either got a NoneType or a string instead of an editor object")
return False
textCursor = editor.textCursor()
result = textCursor.movePosition(moveOperation, moveAnchor, n)
editor.setTextCursor(textCursor)
return result
# this function returns True if a QMenu is
# popped up above the given editor
# param editor is the editor where the menu should appear
......
......@@ -16,8 +16,9 @@ def main():
"Verifying if error is properly reported")
# repair error - go to written line
placeCursorToLine(editorArea, testingCodeLine)
moveTextCursor(editorArea, QTextCursor.Left, QTextCursor.MoveAnchor, 14)
moveTextCursor(editorArea, QTextCursor.Right, QTextCursor.KeepAnchor, 1)
for i in range(14):
type(editorArea, "<Left>")
type(editorArea, "<Shift+Right>")
type(editorArea, "c")
# invoke QML parsing
invokeMenuItem("Tools", "QML/JS", "Run Checks")
......
......@@ -59,7 +59,8 @@ def main():
if not placeCursorToLine(editorArea, "Rectangle {"):
invokeMenuItem("File", "Exit")
return
moveTextCursor(editorArea, QTextCursor.Left, QTextCursor.MoveAnchor, 5)
for i in range(5):
type(editorArea, "<Left>")
ctxtMenu = openContextMenuOnTextCursorPosition(editorArea)
activateItem(waitForObjectItem(objectMap.realName(ctxtMenu), "Find Usages"))
# check if usage was properly found
......@@ -77,7 +78,8 @@ def main():
if not placeCursorToLine(editorArea, "anchors { left: parent.left; top: parent.top; right: parent.right; bottom: parent.verticalCenter }"):
invokeMenuItem("File", "Exit")
return
moveTextCursor(editorArea, QTextCursor.Left, QTextCursor.MoveAnchor, 87)
for i in range(87):
type(editorArea, "<Left>")
invokeMenuItem("Tools", "QML/JS", "Find Usages")
# check if usage was properly found
expectedResults = [ExpectedResult("color-animation.qml", 50, "anchors { left: parent.left; top: parent.top; right: parent.right; bottom: parent.verticalCenter }"),
......@@ -94,7 +96,8 @@ def main():
if not placeCursorToLine(editorArea, "SequentialAnimation on opacity {"):
invokeMenuItem("File", "Exit")
return
moveTextCursor(editorArea, QTextCursor.Left, QTextCursor.MoveAnchor, 5)
for i in range(5):
type(editorArea, "<Left>")
type(editorArea, "<Ctrl+Shift+U>")
# check if usage was properly found
expectedResults = [ExpectedResult("color-animation.qml", 87, "SequentialAnimation on opacity {")]
......
......@@ -5,7 +5,8 @@ def main():
editorArea = startQtCreatorWithNewAppAtQMLEditor(projectDir, "SampleApp", "Text {")
if not editorArea:
return
moveTextCursor(editorArea, QTextCursor.Left, QTextCursor.MoveAnchor, 5)
for i in range(5):
type(editorArea, "<Left>")
# invoke Refactoring - Move Component into separate file
ctxtMenu = openContextMenuOnTextCursorPosition(editorArea)
activateItem(waitForObjectItem(objectMap.realName(ctxtMenu), "Refactoring"))
......
......@@ -4,12 +4,17 @@ def main():
editorArea = startQtCreatorWithNewAppAtQMLEditor(tempDir(), "SampleApp", "Text {")
if not editorArea:
return
moveTextCursor(editorArea, QTextCursor.StartOfLine, QTextCursor.MoveAnchor)
homeKey = "<Home>"
if platform.system() == "Darwin":
homeKey = "<Ctrl+Left>"
for i in range(2):
type(editorArea, homeKey)
type(editorArea, "<Return>")
moveTextCursor(editorArea, QTextCursor.Up, QTextCursor.MoveAnchor)
type(editorArea, "<Up>")
type(editorArea, "<Tab>")
type(editorArea, "Item { x: 10; y: 20; width: 10 }")
moveTextCursor(editorArea, QTextCursor.Left, QTextCursor.MoveAnchor, 30)
for i in range(30):
type(editorArea, "<Left>")
invokeMenuItem("File", "Save All")
# activate menu and apply 'Refactoring - Split initializer'
numLinesExpected = len(str(editorArea.plainText).splitlines()) + 4
......@@ -20,16 +25,9 @@ def main():
waitFor("len(str(editorArea.plainText).splitlines()) == numLinesExpected", 5000)
# verify if refactoring was properly applied - each part on separate line
verifyMessage = "Verifying split initializer functionality at element line."
verifyCurrentLine(editorArea, "Item {", verifyMessage)
moveTextCursor(editorArea, QTextCursor.Down, QTextCursor.MoveAnchor, 1)
verifyCurrentLine(editorArea, "x: 10;", verifyMessage)
moveTextCursor(editorArea, QTextCursor.Down, QTextCursor.MoveAnchor, 1)
verifyCurrentLine(editorArea, "y: 20;", verifyMessage)
moveTextCursor(editorArea, QTextCursor.Down, QTextCursor.MoveAnchor, 1)
verifyCurrentLine(editorArea, "width: 10", verifyMessage)
moveTextCursor(editorArea, QTextCursor.Down, QTextCursor.MoveAnchor, 1)
verifyCurrentLine(editorArea, "}", verifyMessage)
moveTextCursor(editorArea, QTextCursor.Down, QTextCursor.MoveAnchor, 1)
for line in ["Item {", "x: 10;", "y: 20;", "width: 10", "}"]:
verifyCurrentLine(editorArea, line, verifyMessage)
type(editorArea, "<Down>")
#save and exit
invokeMenuItem("File", "Save All")
invokeMenuItem("File", "Exit")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment