Changeset View
Changeset View
Standalone View
Standalone View
src/tests/quick-tests/tst_UserPage.qml
| /* | /* | ||||
| * This file is part of kazv. | * This file is part of kazv. | ||||
| * SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe> | * SPDX-FileCopyrightText: 2023 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 QtTest 1.0 | import QtTest 1.0 | ||||
| import '../../contents/ui' as Kazv | import '../../contents/ui' as Kazv | ||||
| import './test-helpers' as TestHelpers | import './test-helpers' as QmlHelpers | ||||
| import 'test-helpers.js' as JsHelpers | import 'test-helpers.js' as JsHelpers | ||||
| import moe.kazv.mxc.kazv 0.0 as MK | import moe.kazv.mxc.kazv 0.0 as MK | ||||
| Item { | QmlHelpers.TestItem { | ||||
| id: upper | id: upper | ||||
| width: 800 | |||||
| height: 600 | |||||
| property var l10n: JsHelpers.fluentMock | readonly property var gnMap: upper.sdkVars.userGivenNicknameMap | ||||
| property var matrixSdk: TestHelpers.MatrixSdkMock { | |||||
| property var userId: '@foo:example.com' | |||||
| } | |||||
| property var mockHelper: TestHelpers.MockHelper {} | |||||
| property var sdkVars: QtObject { | |||||
| property var userGivenNicknameMap: QtObject { | |||||
| id: gnMap | |||||
| property var map: ({}) | |||||
| property var setAndUpload: mockHelper.promise() | |||||
| } | |||||
| } | |||||
| property var showPassiveNotification: mockHelper.noop() | |||||
| property var powerLevelMapping: ({ | property var powerLevelMapping: ({ | ||||
| '@mew:example.com': 100, | '@mew:example.com': 100, | ||||
| }) | }) | ||||
| property var room: QtObject { | property var room: QtObject { | ||||
| signal onPowerLevelsChanged() | signal onPowerLevelsChanged() | ||||
| function userPowerLevel(userId) { | function userPowerLevel(userId) { | ||||
| return powerLevelMapping[userId]; | return powerLevelMapping[userId]; | ||||
| Show All 29 Lines | QmlHelpers.TestItem { | ||||
| } | } | ||||
| TestCase { | TestCase { | ||||
| id: userPageTest | id: userPageTest | ||||
| name: 'UserPageTest' | name: 'UserPageTest' | ||||
| when: windowShown | when: windowShown | ||||
| function init() { | function init() { | ||||
| upper.matrixSdk.userId = '@foo:example.com'; | |||||
| gnMap.map = {}; | |||||
| mockHelper.clearAll(); | mockHelper.clearAll(); | ||||
| room.membership = MK.MatrixRoom.Join; | room.membership = MK.MatrixRoom.Join; | ||||
| userPage = userPageComp.createObject(layout); | userPage = userPageComp.createObject(layout); | ||||
| userPageWithoutName = userPageWithoutNameComp.createObject(layout); | userPageWithoutName = userPageWithoutNameComp.createObject(layout); | ||||
| layout.children = [userPage, userPageWithoutName]; | layout.children = [userPage, userPageWithoutName]; | ||||
| if (MK.KazvUtil.kfQtMajorVersion === 6) { | if (MK.KazvUtil.kfQtMajorVersion === 6) { | ||||
| userPage.contentItem.clip = false; | userPage.contentItem.clip = false; | ||||
| } | } | ||||
| } | } | ||||
| function cleanup() { | function cleanup() { | ||||
| layout.children = []; | layout.children = []; | ||||
| userPage.destroy(); | userPage.destroy(); | ||||
| userPage = null; | userPage = null; | ||||
| gnMap.map = {}; | |||||
| } | } | ||||
| function test_powerLevel() { | function test_powerLevel() { | ||||
| verify(findChild(userPage, 'powerLevelLabel').visible); | verify(findChild(userPage, 'powerLevelLabel').visible); | ||||
| verify(findChild(userPage, 'powerLevelLabel').text.includes('100')); | verify(findChild(userPage, 'powerLevelLabel').text.includes('100')); | ||||
| verify(!findChild(userPage, 'newPowerLevelInput').visible); | verify(!findChild(userPage, 'newPowerLevelInput').visible); | ||||
| const editButton = findChild(userPage, 'editPowerLevelButton'); | const editButton = findChild(userPage, 'editPowerLevelButton'); | ||||
| ▲ Show 20 Lines • Show All 313 Lines • Show Last 20 Lines | |||||