Changeset View
Changeset View
Standalone View
Standalone View
src/tests/quick-tests/tst_RoomTimelineView.qml
| /* | /* | ||||
| * This file is part of kazv. | * This file is part of kazv. | ||||
| * SPDX-FileCopyrightText: 2024 tusooa <tusooa@kazv.moe> | * SPDX-FileCopyrightText: 2024 tusooa <tusooa@kazv.moe> | ||||
| * SPDX-License-Identifier: AGPL-3.0-or-later | * SPDX-License-Identifier: AGPL-3.0-or-later | ||||
| */ | */ | ||||
| import QtQuick 2.15 | import QtQuick 2.15 | ||||
| import QtQuick.Layouts 1.15 | import QtQuick.Layouts 1.15 | ||||
| import QtQuick.Window | import QtQuick.Window | ||||
| import QtQuick.Controls | import QtQuick.Controls | ||||
| import QtTest 1.0 | import QtTest 1.0 | ||||
| import moe.kazv.mxc.kazv 0.0 as MK | import moe.kazv.mxc.kazv 0.0 as MK | ||||
| import org.kde.kirigami 2.13 as Kirigami | import org.kde.kirigami 2.13 as Kirigami | ||||
| import '../../contents/ui' as Kazv | import '../../contents/ui' as Kazv | ||||
| import 'test-helpers.js' as Helpers | import 'test-helpers.js' as JsHelpers | ||||
| import 'test-helpers' as TestHelpers | import 'test-helpers' as QmlHelpers | ||||
| Item { | QmlHelpers.TestItem { | ||||
| id: item | id: item | ||||
| width: 800 | |||||
| height: 600 | |||||
| property var mockHelper: TestHelpers.MockHelper {} | |||||
| property var l10n: Helpers.fluentMock | |||||
| property var matrixSdk: TestHelpers.MatrixSdkMock {} | |||||
| property var makeLocalEcho: (i) => ({ | property var makeLocalEcho: (i) => ({ | ||||
| eventId: '', | eventId: '', | ||||
| sender: '', | sender: '', | ||||
| type: 'm.room.message', | type: 'm.room.message', | ||||
| stateKey: '', | stateKey: '', | ||||
| content: { | content: { | ||||
| msgtype: 'm.text', | msgtype: 'm.text', | ||||
| body: 'some body' + i, | body: 'some body' + i, | ||||
| Show All 27 Lines | property var room: ({ | ||||
| messageById(id) { | messageById(id) { | ||||
| return { eventId: id }; | return { eventId: id }; | ||||
| }, | }, | ||||
| localEchoById(id) { | localEchoById(id) { | ||||
| return { txnId: id }; | return { txnId: id }; | ||||
| } | } | ||||
| }) | }) | ||||
| property var showPassiveNotification: mockHelper.noop() | |||||
| Kazv.RoomTimelineView { | Kazv.RoomTimelineView { | ||||
| anchors.fill: parent | anchors.fill: parent | ||||
| id: roomTimelineView | id: roomTimelineView | ||||
| timeline: item.timeline | timeline: item.timeline | ||||
| } | } | ||||
| property var timeline: ListModel { | property var timeline: ListModel { | ||||
| ListElement {} | ListElement {} | ||||
| Show All 33 Lines | TestCase { | ||||
| function test_pinSuccess() { | function test_pinSuccess() { | ||||
| roomTimelineView.pinEventRequested('$2'); | roomTimelineView.pinEventRequested('$2'); | ||||
| const popup = findChild(Overlay.overlay, 'pinEventPopup'); | const popup = findChild(Overlay.overlay, 'pinEventPopup'); | ||||
| verify(popup); | verify(popup); | ||||
| tryVerify(() => popup.opened); | tryVerify(() => popup.opened); | ||||
| mouseClick(findChild(popup, 'confirmButton')); | mouseClick(findChild(popup, 'confirmButton')); | ||||
| verify(room.pinEvents.calledTimes() === 1); | verify(room.pinEvents.calledTimes() === 1); | ||||
| verify(Helpers.deepEqual(room.pinEvents.lastArgs()[0], ['$2'])); | verify(JsHelpers.deepEqual(room.pinEvents.lastArgs()[0], ['$2'])); | ||||
| tryVerify(() => !popup.opened); | tryVerify(() => !popup.opened); | ||||
| tryVerify(() => !findChild(Overlay.overlay, 'pinEventPopup')); | tryVerify(() => !findChild(Overlay.overlay, 'pinEventPopup')); | ||||
| room.pinEvents.lastRetVal().resolve(true, {}); | room.pinEvents.lastRetVal().resolve(true, {}); | ||||
| compare(showPassiveNotification.calledTimes(), 1); | compare(showPassiveNotification.calledTimes(), 1); | ||||
| compare(showPassiveNotification.lastArgs()[0], l10n.get('event-pin-success-prompt')); | compare(showPassiveNotification.lastArgs()[0], l10n.get('event-pin-success-prompt')); | ||||
| } | } | ||||
| function test_pinFailure() { | function test_pinFailure() { | ||||
| roomTimelineView.pinEventRequested('$2'); | roomTimelineView.pinEventRequested('$2'); | ||||
| const popup = findChild(Overlay.overlay, 'pinEventPopup'); | const popup = findChild(Overlay.overlay, 'pinEventPopup'); | ||||
| verify(popup); | verify(popup); | ||||
| tryVerify(() => popup.opened); | tryVerify(() => popup.opened); | ||||
| mouseClick(findChild(popup, 'confirmButton')); | mouseClick(findChild(popup, 'confirmButton')); | ||||
| verify(room.pinEvents.calledTimes() === 1); | verify(room.pinEvents.calledTimes() === 1); | ||||
| verify(Helpers.deepEqual(room.pinEvents.lastArgs()[0], ['$2'])); | verify(JsHelpers.deepEqual(room.pinEvents.lastArgs()[0], ['$2'])); | ||||
| tryVerify(() => !popup.opened); | tryVerify(() => !popup.opened); | ||||
| tryVerify(() => !findChild(Overlay.overlay, 'pinEventPopup')); | tryVerify(() => !findChild(Overlay.overlay, 'pinEventPopup')); | ||||
| room.pinEvents.lastRetVal().resolve(false, { errorCode: 'M_FORBIDDEN', error: 'You are not allowed to do so' }); | room.pinEvents.lastRetVal().resolve(false, { errorCode: 'M_FORBIDDEN', error: 'You are not allowed to do so' }); | ||||
| compare(showPassiveNotification.calledTimes(), 1); | compare(showPassiveNotification.calledTimes(), 1); | ||||
| compare(showPassiveNotification.lastArgs()[0], l10n.get('event-pin-failed-prompt', { errorCode: 'M_FORBIDDEN', errorMsg: 'You are not allowed to do so' })); | compare(showPassiveNotification.lastArgs()[0], l10n.get('event-pin-failed-prompt', { errorCode: 'M_FORBIDDEN', errorMsg: 'You are not allowed to do so' })); | ||||
| } | } | ||||
| function test_unpinSuccess() { | function test_unpinSuccess() { | ||||
| roomTimelineView.unpinEventRequested('$2'); | roomTimelineView.unpinEventRequested('$2'); | ||||
| const popup = findChild(Overlay.overlay, 'unpinEventPopup'); | const popup = findChild(Overlay.overlay, 'unpinEventPopup'); | ||||
| verify(popup); | verify(popup); | ||||
| tryVerify(() => popup.opened); | tryVerify(() => popup.opened); | ||||
| mouseClick(findChild(popup, 'confirmButton')); | mouseClick(findChild(popup, 'confirmButton')); | ||||
| verify(room.unpinEvents.calledTimes() === 1); | verify(room.unpinEvents.calledTimes() === 1); | ||||
| verify(Helpers.deepEqual(room.unpinEvents.lastArgs()[0], ['$2'])); | verify(JsHelpers.deepEqual(room.unpinEvents.lastArgs()[0], ['$2'])); | ||||
| tryVerify(() => !popup.opened); | tryVerify(() => !popup.opened); | ||||
| tryVerify(() => !findChild(Overlay.overlay, 'unpinEventPopup')); | tryVerify(() => !findChild(Overlay.overlay, 'unpinEventPopup')); | ||||
| room.unpinEvents.lastRetVal().resolve(true, {}); | room.unpinEvents.lastRetVal().resolve(true, {}); | ||||
| compare(showPassiveNotification.calledTimes(), 1); | compare(showPassiveNotification.calledTimes(), 1); | ||||
| compare(showPassiveNotification.lastArgs()[0], l10n.get('event-unpin-success-prompt')); | compare(showPassiveNotification.lastArgs()[0], l10n.get('event-unpin-success-prompt')); | ||||
| } | } | ||||
| function test_unpinFailure() { | function test_unpinFailure() { | ||||
| roomTimelineView.unpinEventRequested('$2'); | roomTimelineView.unpinEventRequested('$2'); | ||||
| const popup = findChild(Overlay.overlay, 'unpinEventPopup'); | const popup = findChild(Overlay.overlay, 'unpinEventPopup'); | ||||
| verify(popup); | verify(popup); | ||||
| tryVerify(() => popup.opened); | tryVerify(() => popup.opened); | ||||
| mouseClick(findChild(popup, 'confirmButton')); | mouseClick(findChild(popup, 'confirmButton')); | ||||
| verify(room.unpinEvents.calledTimes() === 1); | verify(room.unpinEvents.calledTimes() === 1); | ||||
| verify(Helpers.deepEqual(room.unpinEvents.lastArgs()[0], ['$2'])); | verify(JsHelpers.deepEqual(room.unpinEvents.lastArgs()[0], ['$2'])); | ||||
| tryVerify(() => !popup.opened); | tryVerify(() => !popup.opened); | ||||
| tryVerify(() => !findChild(Overlay.overlay, 'unpinEventPopup')); | tryVerify(() => !findChild(Overlay.overlay, 'unpinEventPopup')); | ||||
| room.unpinEvents.lastRetVal().resolve(false, { errorCode: 'M_FORBIDDEN', error: 'You are not allowed to do so' }); | room.unpinEvents.lastRetVal().resolve(false, { errorCode: 'M_FORBIDDEN', error: 'You are not allowed to do so' }); | ||||
| compare(showPassiveNotification.calledTimes(), 1); | compare(showPassiveNotification.calledTimes(), 1); | ||||
| compare(showPassiveNotification.lastArgs()[0], l10n.get('event-unpin-failed-prompt', { errorCode: 'M_FORBIDDEN', errorMsg: 'You are not allowed to do so' })); | compare(showPassiveNotification.lastArgs()[0], l10n.get('event-unpin-failed-prompt', { errorCode: 'M_FORBIDDEN', errorMsg: 'You are not allowed to do so' })); | ||||
| } | } | ||||
| function test_deleteEvent() { | function test_deleteEvent() { | ||||
| Show All 27 Lines | |||||