Changeset View
Changeset View
Standalone View
Standalone View
src/tests/quick-tests/tst_StickerPicker.qml
- This file was added.
| /* | |||||
| * This file is part of kazv. | |||||
| * SPDX-FileCopyrightText: 2026 tusooa <tusooa@kazv.moe> | |||||
| * SPDX-License-Identifier: AGPL-3.0-or-later | |||||
| */ | |||||
| import QtQuick 2.15 | |||||
| import QtQuick.Layouts 1.15 | |||||
| import QtQuick.Window | |||||
| import QtQuick.Controls | |||||
| import QtTest 1.0 | |||||
| import '../../contents/ui' as Kazv | |||||
| import 'test-helpers.js' as JsHelpers | |||||
| import 'test-helpers' as QmlHelpers | |||||
| QmlHelpers.TestItem { | |||||
| id: item | |||||
| property var someShortCode: 'myemote' | |||||
| property var somePack: ListModel { | |||||
| id: somePack | |||||
| property string packName: 'Pack 0' | |||||
| function removeSticker(shortCode) { | |||||
| return { _removedShortCode: shortCode }; | |||||
| } | |||||
| function at(index) { | |||||
| return null; | |||||
| } | |||||
| } | |||||
| Kazv.StickerPicker { | |||||
| id: stickerPicker | |||||
| anchors.fill: parent | |||||
| stickerPackList: ListModel { | |||||
| id: stickerPackListModel | |||||
| ListElement {} | |||||
| function at(index) { | |||||
| return somePack; | |||||
| } | |||||
| } | |||||
| } | |||||
| TestCase { | |||||
| id: stickerPickerTest | |||||
| name: 'StickerPickerTest' | |||||
| when: windowShown | |||||
| function init() { | |||||
| mockHelper.clearAll(); | |||||
| } | |||||
| function _openConfirmation() { | |||||
| stickerPicker.requestRemoveSticker(somePack, item.someShortCode); | |||||
| const popup = findChild(Overlay.overlay, 'removeStickerConfirmation'); | |||||
| verify(popup); | |||||
| tryVerify(() => popup.opened); | |||||
| return popup; | |||||
| } | |||||
| function test_removeStickerConfirm() { | |||||
| const popup = _openConfirmation(); | |||||
| mouseClick(findChild(popup, 'confirmButton')); | |||||
| verify(matrixSession.updateStickerPack.calledTimes() === 1); | |||||
| verify(JsHelpers.deepEqual(matrixSession.updateStickerPack.lastArgs()[0], { _removedShortCode: item.someShortCode })); | |||||
| tryVerify(() => !popup.opened); | |||||
| tryVerify(() => !findChild(Overlay.overlay, 'removeStickerConfirmation')); | |||||
| compare(showPassiveNotification.calledTimes(), 0); | |||||
| } | |||||
| function test_removeStickerFailure() { | |||||
| const popup = _openConfirmation(); | |||||
| mouseClick(findChild(popup, 'confirmButton')); | |||||
| verify(matrixSession.updateStickerPack.calledTimes() === 1); | |||||
| tryVerify(() => !popup.opened); | |||||
| matrixSession.updateStickerPack.lastRetVal().resolve(false, { errorCode: 'M_FORBIDDEN', error: 'no' }); | |||||
| compare(showPassiveNotification.calledTimes(), 1); | |||||
| compare(showPassiveNotification.lastArgs()[0], l10n.get('sticker-remove-failed-prompt', { errorCode: 'M_FORBIDDEN', errorMsg: 'no' })); | |||||
| } | |||||
| } | |||||
| } | |||||