From 69c2e873e74727526cf197ab4a06b368a1d820ec Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 31 Jul 2018 13:46:48 +0200 Subject: Fixed texteditor test --- framework/qml/TextEditor.qml | 9 ++------- framework/qml/tests/tst_texteditor.qml | 32 +++++++++----------------------- 2 files changed, 11 insertions(+), 30 deletions(-) (limited to 'framework/qml') diff --git a/framework/qml/TextEditor.qml b/framework/qml/TextEditor.qml index 7dd30625..bc50169e 100644 --- a/framework/qml/TextEditor.qml +++ b/framework/qml/TextEditor.qml @@ -24,9 +24,8 @@ import org.kube.framework 1.0 as Kube FocusScope { id: root - property string text: "" - - property bool htmlEnabled: false + property string text: document.text + property bool htmlEnabled: document.containsFormatting property alias bold: document.bold property alias italic: document.italic @@ -46,10 +45,6 @@ FocusScope { document: edit.textDocument selectionStart: edit.selectionStart selectionEnd: edit.selectionEnd - onTextChanged: { - root.htmlEnabled = containsFormatting(); - root.htmlEnabled ? root.text = htmlText : root.text = plainText - } cursorPosition: edit.cursorPosition } diff --git a/framework/qml/tests/tst_texteditor.qml b/framework/qml/tests/tst_texteditor.qml index f80afe66..544270e5 100644 --- a/framework/qml/tests/tst_texteditor.qml +++ b/framework/qml/tests/tst_texteditor.qml @@ -33,41 +33,27 @@ TestCase { Kube.TextEditor {} } - function test_1initialText() { - var editor = createTemporaryObject(editorComponent, testCase, {initialText: "Foobar\nBarBar", htmlEnabled: false}) - compare(editor.text, editor.initialText) - } + property string htmlText: "

Foobar
BarBar

" + property string plainText: "Foobar\nBarBar" - function test_2plainToHtmlConversion() { - var editor = createTemporaryObject(editorComponent, testCase, {initialText: "Foobar\nBarBar", htmlEnabled: false}) - editor.htmlEnabled = true - verify(editor.text.indexOf("") !== -1) - //It's converted into two paragraphs, so we can't check as a single string - verify(editor.text.indexOf("Foobar") !== -1) - verify(editor.text.indexOf("BarBar") !== -1) - editor.htmlEnabled = false + function test_1initialText() { + var editor = createTemporaryObject(editorComponent, testCase, {initialText: plainText}) compare(editor.text, editor.initialText) - - editor.htmlEnabled = true - verify(editor.text.indexOf("") !== -1) } function test_3htmlToPlainConversion() { - var editor = createTemporaryObject(editorComponent, testCase, {initialText: "

test

", htmlEnabled: true}) - editor.htmlEnabled = false - compare(editor.text, "test") - - editor.htmlEnabled = true - verify(editor.text.indexOf("") !== -1) + var editor = createTemporaryObject(editorComponent, testCase, {initialText: htmlText}) + editor.clearFormatting() + compare(editor.text, plainText) } function test_4detectPlain() { - var editor = createTemporaryObject(editorComponent, testCase, {initialText: "Foobar\nBarBar", htmlEnabled: true}) + var editor = createTemporaryObject(editorComponent, testCase, {initialText: plainText}) compare(editor.htmlEnabled, false) } function test_5detectHtml() { - var editor = createTemporaryObject(editorComponent, testCase, {initialText: "

test

", htmlEnabled: false}) + var editor = createTemporaryObject(editorComponent, testCase, {initialText: htmlText}) compare(editor.htmlEnabled, true) } } -- cgit v1.2.3