Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F140113
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/tests/quick-tests/tst_UserPage.qml b/src/tests/quick-tests/tst_UserPage.qml
index 2a26dff..557b291 100644
--- a/src/tests/quick-tests/tst_UserPage.qml
+++ b/src/tests/quick-tests/tst_UserPage.qml
@@ -1,195 +1,229 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtTest 1.0
import '../../contents/ui' as Kazv
import './test-helpers' as TestHelpers
import 'test-helpers.js' as Helpers
Item {
id: upper
width: 800
height: 600
property var l10n: Helpers.fluentMock
property var matrixSdk: TestHelpers.MatrixSdkMock {}
property var lastNotification: undefined
function showPassiveNotification(msg) {
upper.lastNotification = msg;
}
property var promiseComp: Component {
TestHelpers.MatrixPromiseMock {
}
}
property var powerLevelMapping: ({
'@mew:example.com': 100,
})
property var room: ({
userPowerLevel(userId) {
return powerLevelMapping[userId];
},
setUserPowerLevel(userId, powerLevel) {
upper.room._setUserPowerLevelUserId = userId;
upper.room._setUserPowerLevelPowerLevel = powerLevel;
upper.room._setUserPowerLevelPromise = promiseComp.createObject(upper.room);
return upper.room._setUserPowerLevelPromise;
},
ensureStateEvent(type, stateKey) {
const promise = promiseComp.createObject(upper.room);
console.log('ensureStateEvent', type, stateKey, promise);
upper.room._ensureStateEventPromises.push(promise);
console.log(upper.room._ensureStateEventPromises);
return promise;
},
kickUser(userId, reason) {
upper.room._kickUserUserId = userId;
upper.room._kickUserReason = reason;
upper.room._kickUserPromise = promiseComp.createObject(upper.room);
return upper.room._kickUserPromise;
},
+ banUser(userId, reason) {
+ upper.room._banUserUserId = userId;
+ upper.room._banUserReason = reason;
+ upper.room._banUserPromise = promiseComp.createObject(upper.room);
+ return upper.room._banUserPromise;
+ },
_setUserPowerLevelUserId: undefined,
_setUserPowerLevelPowerLevel: undefined,
_setUserPowerLevelPromise: undefined,
_ensureStateEventPromises: [],
_kickUserUserId: undefined,
_kickUserReason: undefined,
_kickUserPromise: undefined,
+ _banUserUserId: undefined,
+ _banUserReason: undefined,
+ _banUserPromise: undefined,
})
ColumnLayout {
Kazv.UserPage {
id: userPage
userId: '@mew:example.com'
user: ({})
room: upper.room
}
}
TestCase {
id: userPageTest
name: 'UserPageTest'
when: windowShown
function cleanupTestCase() {
upper.room._setUserPowerLevelUserId = undefined;
upper.room._setUserPowerLevelPowerLevel = undefined;
upper.room._setUserPowerLevelPromise = undefined;
upper.room._ensureStateEventPromises = [];
upper.room._kickUserUserId = undefined;
upper.room._kickUserReason = undefined;
upper.room._kickUserPromise = undefined;
+ upper.room._banUserUserId = undefined;
+ upper.room._banUserReason = undefined;
+ upper.room._banUserPromise = undefined;
userPage.submittingPowerLevel = false;
userPage.editingPowerLevel = false;
userPage.powerLevelsLoaded = false;
+ userPage.banningUser = false;
upper.lastNotification = undefined;
}
function test_powerLevel() {
verify(findChild(userPage, 'powerLevelLabel').visible);
verify(findChild(userPage, 'powerLevelLabel').text.includes('100'));
verify(!findChild(userPage, 'newPowerLevelInput').visible);
const editButton = findChild(userPage, 'editPowerLevelButton');
verify(editButton.visible);
verify(!editButton.enabled);
tryVerify(() => userPage.room._ensureStateEventPromises[1], 1000);
userPage.room._ensureStateEventPromises[1].resolve(true, {});
tryVerify(() => editButton.enabled);
mouseClick(editButton);
const textField = findChild(userPage, 'newPowerLevelInput');
tryVerify(() => textField.visible, 1000);
textField.text = '50';
const saveButton = findChild(userPage, 'savePowerLevelButton');
mouseClick(saveButton);
tryVerify(() => room._setUserPowerLevelPromise, 1000);
// Text field is not closed until the request succeeded
verify(textField.visible);
verify(textField.readOnly);
verify(room._setUserPowerLevelUserId === '@mew:example.com');
verify(room._setUserPowerLevelPowerLevel === 50);
// the buttons are disabled until the request responded
verify(!saveButton.enabled);
verify(!findChild(userPage, 'discardPowerLevelButton').enabled);
room._setUserPowerLevelPromise.resolve(true, {});
tryVerify(() => !textField.visible, 1000);
// Text field is editable when we try to edit the power level again
mouseClick(editButton);
tryVerify(() => textField.visible, 1000);
verify(!textField.readOnly);
}
function test_powerLevelEditFailure() {
tryVerify(() => userPage.room._ensureStateEventPromises[1], 1000);
userPage.room._ensureStateEventPromises[1].resolve(true, {});
const editButton = findChild(userPage, 'editPowerLevelButton');
tryVerify(() => editButton.enabled);
mouseClick(editButton);
const textField = findChild(userPage, 'newPowerLevelInput');
tryVerify(() => textField.visible, 1000);
textField.text = '50';
const saveButton = findChild(userPage, 'savePowerLevelButton');
mouseClick(saveButton);
tryVerify(() => room._setUserPowerLevelPromise, 1000);
// Text field is not closed until the request succeeded
room._setUserPowerLevelPromise.resolve(false, {});
// text field is no longer readonly if failed
tryVerify(() => !textField.readOnly, 1000);
// show error message
verify(upper.lastNotification);
// the buttons are enabled when the request responded
verify(saveButton.enabled);
verify(findChild(userPage, 'discardPowerLevelButton').enabled);
}
+
+ function test_banUser() {
+ const textField = findChild(userPage, 'banUserReasonInput');
+ verify(textField.visible);
+ verify(!textField.readOnly);
+ const banButton = findChild(userPage, 'banUserButton');
+ verify(banButton.visible);
+ verify(banButton.enabled);
+
+ textField.text = 'some reason';
+ mouseClick(banButton);
+ tryVerify(() => room._banUserPromise, 1000);
+ verify(textField.readOnly);
+ verify(!banButton.enabled);
+ verify(room._banUserUserId === '@mew:example.com');
+ verify(room._banUserReason === 'some reason');
+
+ room._banUserPromise.resolve(true, {});
+ tryVerify(() => banButton.enabled, 1000);
+ tryVerify(() => textField.text === '', 1000);
+ }
}
function test_kickUser() {
const kickButton = findChild(userPage, 'kickUserButton');
verify(kickButton.visible);
verify(kickButton.enabled);
const reasonDialog = findChild(userPage, 'kickUserReasonDialog');
verify(!reasonDialog.opened);
const textField = findChild(userPage, 'kickUserReasonInput');
mouseClick(kickButton);
verify(!reasonDialog.opened);
verify(textField.visible);
verify(!textField.readOnly);
textField.text = 'some reason';
reasonDialog.accept();
tryVerify(() => !reasonDialog.opened, 1000);
tryVerify(() => !kickButton.enabled, 1000);
tryVerify(() => room._kickUserPromise, 1000);
verify(room._kickUserUserId === '@mew:example.com');
verify(room._kickUserReason === 'some reason');
room._kickUserPromise.resolve(true, {});
tryVerify(() => textField.text === '', 1000);
// still available only because this is a mock call, no real action
// is performed on the user
tryVerify(() => kickButton.enabled, 1000);
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jan 19, 12:55 PM (5 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55182
Default Alt Text
(8 KB)
Attached To
Mode
rK kazv
Attached
Detach File
Event Timeline
Log In to Comment