2016-01-15 14:55:33 +01:00
|
|
|
# Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2013-05-15 13:17:33 +02:00
|
|
|
|
2012-05-10 10:53:06 +02:00
|
|
|
source("../shared/qmls.py")
|
2012-04-25 09:57:22 +02:00
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
projectDir = tempDir()
|
2017-10-13 10:08:08 +02:00
|
|
|
editorArea = startQtCreatorWithNewAppAtQMLEditor(projectDir, "SampleApp")
|
2012-05-10 10:53:06 +02:00
|
|
|
if not editorArea:
|
2012-04-25 09:57:22 +02:00
|
|
|
return
|
2017-10-13 10:08:08 +02:00
|
|
|
# add basic TextEdit item to check it afterwards
|
|
|
|
|
codelines = ['TextEdit {', 'id: textEdit', 'text: "Enter something"', 'anchors.top: parent.top',
|
|
|
|
|
'anchors.horizontalCenter: parent.horizontalCenter', 'anchors.topMargin: 20']
|
|
|
|
|
if not addTestableCodeAfterLine(editorArea, 'title: qsTr("Hello World")', codelines):
|
|
|
|
|
saveAndExit()
|
|
|
|
|
return
|
|
|
|
|
placeCursorToLine(editorArea, "TextEdit {")
|
2018-08-02 13:45:34 +02:00
|
|
|
for _ in range(5):
|
2012-05-25 11:52:01 +02:00
|
|
|
type(editorArea, "<Left>")
|
2012-04-25 09:57:22 +02:00
|
|
|
# invoke Refactoring - Move Component into separate file
|
2013-02-20 19:49:32 +01:00
|
|
|
invokeContextMenuItem(editorArea, "Refactoring", "Move Component into Separate File")
|
2012-04-25 09:57:22 +02:00
|
|
|
# give component name and proceed
|
|
|
|
|
replaceEditorContent(waitForObject(":Dialog.componentNameEdit_QLineEdit"), "MyComponent")
|
|
|
|
|
clickButton(waitForObject(":Dialog.OK_QPushButton"))
|
2012-05-16 18:13:55 +02:00
|
|
|
try:
|
|
|
|
|
waitForObject(":Add to Version Control_QMessageBox", 5000)
|
|
|
|
|
clickButton(waitForObject(":Add to Version Control.No_QPushButton"))
|
|
|
|
|
except:
|
|
|
|
|
pass
|
2012-04-25 09:57:22 +02:00
|
|
|
# verify if refactoring is done correctly
|
|
|
|
|
waitFor("'MyComponent' in str(editorArea.plainText)", 2000)
|
|
|
|
|
codeText = str(editorArea.plainText)
|
2016-08-11 16:54:18 +02:00
|
|
|
patternCodeToAdd = "MyComponent\s+\{\s*id: textEdit\s*\}"
|
|
|
|
|
patternCodeToMove = "TextEdit\s+\{.*\}"
|
|
|
|
|
# there should be empty MyComponent item instead of TextEdit item
|
2012-04-25 09:57:22 +02:00
|
|
|
if re.search(patternCodeToAdd, codeText, re.DOTALL) and not re.search(patternCodeToMove, codeText, re.DOTALL):
|
|
|
|
|
test.passes("Refactoring was properly applied in source file")
|
|
|
|
|
else:
|
|
|
|
|
test.fail("Refactoring of Text to MyComponent failed in source file. Content of editor:\n%s" % codeText)
|
2023-02-16 14:15:40 +01:00
|
|
|
myCompTE = "SampleApp.appSampleApp.MyComponent\\.qml"
|
2012-04-25 09:57:22 +02:00
|
|
|
# there should be new QML file generated with name "MyComponent.qml"
|
|
|
|
|
try:
|
2023-01-30 14:58:05 +01:00
|
|
|
# openDocument() doesn't wait for expected elements, so it might be faster than the updates
|
2023-04-03 16:15:25 +02:00
|
|
|
# to the tree. Explicitly wait here to avoid timing issues. Using wFPTI() instead of
|
2023-01-30 14:58:05 +01:00
|
|
|
# snooze() allows to proceed earlier, just in case it can find the item.
|
2023-04-03 16:15:25 +02:00
|
|
|
waitForProjectTreeItem(myCompTE, 2000)
|
2012-04-25 09:57:22 +02:00
|
|
|
except:
|
2023-01-30 14:58:05 +01:00
|
|
|
pass
|
2014-04-03 08:58:19 +02:00
|
|
|
# open MyComponent.qml file for verification
|
2023-04-01 00:44:19 +02:00
|
|
|
docOpened = openDocument(myCompTE)
|
2023-04-20 23:54:17 +02:00
|
|
|
if not test.verify(docOpened, "Was MyComponent.qml properly generated in project explorer?"):
|
|
|
|
|
test.fatal("Could not open MyComponent.qml.")
|
|
|
|
|
saveAndExit()
|
|
|
|
|
return
|
2012-04-25 09:57:22 +02:00
|
|
|
editorArea = waitForObject(":Qt Creator_QmlJSEditor::QmlJSTextEditorWidget")
|
|
|
|
|
codeText = str(editorArea.plainText)
|
|
|
|
|
# there should be Text item in new file
|
|
|
|
|
if re.search(patternCodeToMove, codeText, re.DOTALL):
|
|
|
|
|
test.passes("Refactoring was properly applied to destination file")
|
|
|
|
|
else:
|
|
|
|
|
test.fail("Refactoring failed in destination file. Content of editor:\n%s" % codeText)
|
|
|
|
|
#save and exit
|
|
|
|
|
invokeMenuItem("File", "Save All")
|
|
|
|
|
# check if new file was created in file system
|
2014-04-08 15:34:46 +02:00
|
|
|
test.verify(os.path.exists(os.path.join(projectDir, "SampleApp", "MyComponent.qml")),
|
2012-04-25 09:57:22 +02:00
|
|
|
"Verifying if MyComponent.qml exists in file system after save")
|
|
|
|
|
invokeMenuItem("File", "Exit")
|