Changeset View
Changeset View
Standalone View
Standalone View
src/tests/quick-tests/tst_SendMessageBox.qml
| Show All 32 Lines | return { | ||||
| messageById () { return {}; }, | messageById () { return {}; }, | ||||
| member () { return {}; }, | member () { return {}; }, | ||||
| localDraft: '', | localDraft: '', | ||||
| setLocalDraft (localDraft) { | setLocalDraft (localDraft) { | ||||
| this.localDraft = localDraft; | this.localDraft = localDraft; | ||||
| }, | }, | ||||
| updateLocalDraftNow () { | updateLocalDraftNow () { | ||||
| }, | }, | ||||
| members () { | |||||
| return membersModel; | |||||
| }, | |||||
| }; | }; | ||||
| } | } | ||||
| property var room: makeRoom() | property var room: makeRoom() | ||||
| property var membersModel: ListModel { | |||||
| ListElement { userId: '@foo:example.com' } | |||||
| ListElement { userId: '@bar:example.com' } | |||||
| property string filter | |||||
| property var count: 2 | |||||
| function at(index) { | |||||
| return get(index); | |||||
| } | |||||
| } | |||||
| property var l10n: Helpers.fluentMock | property var l10n: Helpers.fluentMock | ||||
| property var matrixSdk: TestHelpers.MatrixSdkMock {} | property var matrixSdk: TestHelpers.MatrixSdkMock {} | ||||
| property var kazvIOManager: TestHelpers.KazvIOManagerMock {} | property var kazvIOManager: TestHelpers.KazvIOManagerMock {} | ||||
| property var sdkVars: ({}) | |||||
| Kazv.SendMessageBox { | Kazv.SendMessageBox { | ||||
| id: sendMessageBox | id: sendMessageBox | ||||
| y: 400 | |||||
| room: item.room | room: item.room | ||||
| } | } | ||||
| TestCase { | TestCase { | ||||
| id: sendMessageBoxTest | id: sendMessageBoxTest | ||||
| name: 'SendMessageBoxTest' | name: 'SendMessageBoxTest' | ||||
| when: windowShown | when: windowShown | ||||
| function init() { | function init() { | ||||
| membersModel.count = 2; | |||||
| findChild(sendMessageBox, 'draftMessage').text = ''; | findChild(sendMessageBox, 'draftMessage').text = ''; | ||||
| } | } | ||||
| function test_empty() { | function test_empty() { | ||||
| const textArea = findChild(sendMessageBox, 'draftMessage'); | const textArea = findChild(sendMessageBox, 'draftMessage'); | ||||
| sendMessageBox.mentionUser('@foo:example.com'); | sendMessageBox.mentionUser('@foo:example.com'); | ||||
| tryVerify(() => textArea.text === '@foo:example.com '); | tryVerify(() => textArea.text === '@foo:example.com '); | ||||
| verify(textArea.cursorPosition === textArea.text.length); | verify(textArea.cursorPosition === textArea.text.length); | ||||
| Show All 27 Lines | TestCase { | ||||
| } | } | ||||
| function test_cursorAtBeginningSpacingAfter() { | function test_cursorAtBeginningSpacingAfter() { | ||||
| const textArea = findChild(sendMessageBox, 'draftMessage'); | const textArea = findChild(sendMessageBox, 'draftMessage'); | ||||
| textArea.text = '\nsome test'; | textArea.text = '\nsome test'; | ||||
| textArea.cursorPosition = 0; | textArea.cursorPosition = 0; | ||||
| sendMessageBox.mentionUser('@foo:example.com'); | sendMessageBox.mentionUser('@foo:example.com'); | ||||
| tryVerify(() => textArea.text === '@foo:example.com\nsome test'); | tryVerify(() => textArea.text === '@foo:example.com\nsome test'); | ||||
| verify(textArea.cursorPosition === '@foo:example.com'.length); | verify(textArea.cursorPosition === '@foo:example.com\n'.length); | ||||
| } | } | ||||
| function test_cursorInMiddleNoSpacing() { | function test_cursorInMiddleNoSpacing() { | ||||
| const textArea = findChild(sendMessageBox, 'draftMessage'); | const textArea = findChild(sendMessageBox, 'draftMessage'); | ||||
| textArea.text = 'some\ntest'; | textArea.text = 'some\ntest'; | ||||
| textArea.cursorPosition = 1; | textArea.cursorPosition = 1; | ||||
| sendMessageBox.mentionUser('@foo:example.com'); | sendMessageBox.mentionUser('@foo:example.com'); | ||||
| tryVerify(() => textArea.text === 's @foo:example.com ome\ntest'); | tryVerify(() => textArea.text === 's @foo:example.com ome\ntest'); | ||||
| Show All 10 Lines | TestCase { | ||||
| } | } | ||||
| function test_cursorInMiddleSpacingAfter() { | function test_cursorInMiddleSpacingAfter() { | ||||
| const textArea = findChild(sendMessageBox, 'draftMessage'); | const textArea = findChild(sendMessageBox, 'draftMessage'); | ||||
| textArea.text = 'some\ntest'; | textArea.text = 'some\ntest'; | ||||
| textArea.cursorPosition = 4; | textArea.cursorPosition = 4; | ||||
| sendMessageBox.mentionUser('@foo:example.com'); | sendMessageBox.mentionUser('@foo:example.com'); | ||||
| tryVerify(() => textArea.text === 'some @foo:example.com\ntest'); | tryVerify(() => textArea.text === 'some @foo:example.com\ntest'); | ||||
| verify(textArea.cursorPosition === 'some @foo:example.com'.length); | verify(textArea.cursorPosition === 'some @foo:example.com\n'.length); | ||||
| } | } | ||||
| function test_cursorInMiddleSpacingAround() { | function test_cursorInMiddleSpacingAround() { | ||||
| const textArea = findChild(sendMessageBox, 'draftMessage'); | const textArea = findChild(sendMessageBox, 'draftMessage'); | ||||
| textArea.text = 'some\n\ntest'; | textArea.text = 'some\n\ntest'; | ||||
| textArea.cursorPosition = 5; | textArea.cursorPosition = 5; | ||||
| sendMessageBox.mentionUser('@foo:example.com'); | sendMessageBox.mentionUser('@foo:example.com'); | ||||
| tryVerify(() => textArea.text === 'some\n@foo:example.com\ntest'); | tryVerify(() => textArea.text === 'some\n@foo:example.com\ntest'); | ||||
| verify(textArea.cursorPosition === 'some\n@foo:example.com'.length); | verify(textArea.cursorPosition === 'some\n@foo:example.com\n'.length); | ||||
| } | |||||
| function test_filter() { | |||||
| const data = [ | |||||
| ['some\n\ntest', 5, ''], | |||||
| ['some\n\n@test\n', 11, '@test'], | |||||
| ['some\n\n@test\n', 10, '@tes'], | |||||
| ['some\n\n@test喵 ', 12, '@test喵'], | |||||
| // separated by a whitespace | |||||
| ['some\n\n@test\n', 12, ''], | |||||
| ['some\n\n@test\t', 12, ''], | |||||
| ['some\n\n@test ', 12, ''], | |||||
| // multiple @s | |||||
| ['@test@233', 9, '@233'], | |||||
| ]; | |||||
| const textArea = findChild(sendMessageBox, 'draftMessage'); | |||||
| data.forEach(([text, pos, expected]) => { | |||||
| textArea.text = text; | |||||
| textArea.cursorPosition = pos; | |||||
| compare(textArea.filter, expected); | |||||
| }); | |||||
| } | |||||
| function test_completion() { | |||||
| const textArea = findChild(sendMessageBox, 'draftMessage'); | |||||
| textArea.text = '@ex'; | |||||
| textArea.cursorPosition = 3; | |||||
| const completionPopup = findChild(sendMessageBox, 'completionPopup'); | |||||
| tryVerify(() => completionPopup.opened); | |||||
| const listView = findChild(completionPopup, 'completionListView'); | |||||
| tryVerify(() => listView); | |||||
| tryVerify(() => findChild(listView, 'completionItem0')); | |||||
| tryVerify(() => findChild(listView, 'completionItem1')); | |||||
| const first = findChild(listView, 'completionItem0'); | |||||
| const second = findChild(listView, 'completionItem1'); | |||||
| verify(findChild(first, 'userIdLabel').text === '@foo:example.com'); | |||||
| verify(findChild(second, 'userIdLabel').text === '@bar:example.com'); | |||||
| mouseClick(second); | |||||
| tryVerify(() => !completionPopup.opened); | |||||
| const expected = '@bar:example.com '; | |||||
| tryCompare(textArea, 'text', expected); | |||||
| compare(textArea.cursorPosition, expected.length); | |||||
| } | |||||
| function test_zeroCompletion() { | |||||
| membersModel.count = 0; | |||||
| const textArea = findChild(sendMessageBox, 'draftMessage'); | |||||
| textArea.text = '@ex'; | |||||
| textArea.cursorPosition = 3; | |||||
| const completionPopup = findChild(sendMessageBox, 'completionPopup'); | |||||
| tryVerify(() => !completionPopup.opened); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||