Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F112645
D66.1732340158.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
12 KB
Referenced Files
None
Subscribers
None
D66.1732340158.diff
View Options
diff --git a/src/contents/ui/UserPage.qml b/src/contents/ui/UserPage.qml
--- a/src/contents/ui/UserPage.qml
+++ b/src/contents/ui/UserPage.qml
@@ -52,7 +52,7 @@
property var ensurePowerLevels: Kazv.AsyncHandler {
trigger: () => room.ensureStateEvent('m.room.power_levels', '')
- onResolved: {
+ onResolved: (success, data) => {
if (success) {
userPage.powerLevelsLoaded = true;
}
@@ -84,7 +84,7 @@
userPage.submittingPowerLevel = true;
return room.setUserPowerLevel(userPage.userId, parseInt(newPowerLevel.text));
}
- onResolved: {
+ onResolved: (success, data) => {
if (!success) {
showPassiveNotification(l10n.get('user-page-set-power-level-failed-prompt', { errorCode: data.errorCode, errorMsg: data.error }));
} else {
diff --git a/src/tests/quick-tests/tst_UserPage.qml b/src/tests/quick-tests/tst_UserPage.qml
--- a/src/tests/quick-tests/tst_UserPage.qml
+++ b/src/tests/quick-tests/tst_UserPage.qml
@@ -10,7 +10,7 @@
import '../../contents/ui' as Kazv
import './test-helpers' as TestHelpers
-import 'test-helpers.js' as Helpers
+import 'test-helpers.js' as JsHelpers
import moe.kazv.mxc.kazv 0.0 as MK
Item {
@@ -18,7 +18,7 @@
width: 800
height: 600
- property var l10n: Helpers.fluentMock
+ property var l10n: JsHelpers.fluentMock
property var matrixSdk: TestHelpers.MatrixSdkMock {
property var userId: '@foo:example.com'
}
@@ -37,29 +37,29 @@
'@mew:example.com': 100,
})
- property var room: ({
- userPowerLevel(userId) {
+ property var room: QtObject {
+ signal onPowerLevelsChanged()
+ function userPowerLevel(userId) {
return powerLevelMapping[userId];
- },
- setUserPowerLevel: mockHelper.promise(),
- ensureStateEvent: mockHelper.promise(),
- kickUser: mockHelper.promise(),
- banUser: mockHelper.promise(),
- unbanUser: mockHelper.promise(),
- })
+ }
+ property var setUserPowerLevel: mockHelper.promise()
+ property var ensureStateEvent: mockHelper.promise()
+ property var kickUser: mockHelper.promise()
+ property var banUser: mockHelper.promise()
+ property var unbanUser: mockHelper.promise()
+ }
- ColumnLayout {
+ property var userPage: null
+ property var userPageComp: Component {
Kazv.UserPage {
- id: userPage
userId: '@mew:example.com'
user: ({ userId: '@mew:example.com', name: 'mew' })
room: upper.room
}
+ }
- Kazv.UserPage {
- id: userPageSelf
- userId: '@foo:example.com'
- }
+ ColumnLayout {
+ id: layout
}
TestCase {
@@ -67,21 +67,19 @@
name: 'UserPageTest'
when: windowShown
- function initTestCase() {
+ function init() {
+ mockHelper.clearAll();
+ userPage = userPageComp.createObject(layout);
+ layout.children = [userPage];
if (MK.KazvUtil.kfQtMajorVersion === 6) {
userPage.contentItem.clip = false;
- userPageSelf.contentItem.clip = false;
}
}
- function cleanupTestCase() {
- mockHelper.clearAll();
- userPage.submittingPowerLevel = false;
- userPage.editingPowerLevel = false;
- userPage.powerLevelsLoaded = false;
- userPage.banningUser = false;
- userPage.unbanningUser = false;
- userPage.user = ({});
+ function cleanup() {
+ layout.children = [];
+ userPage.destroy();
+ userPage = null;
gnMap.map = {};
}
@@ -93,17 +91,23 @@
const editButton = findChild(userPage, 'editPowerLevelButton');
verify(editButton.visible);
verify(!editButton.enabled);
+ tryVerify(() => userPage.room.ensureStateEvent.calledTimes() === 2);
+ tryVerify(() => userPage.room.ensureStateEvent.args[1][0] === 'm.room.power_levels', 1000);
tryVerify(() => userPage.room.ensureStateEvent.retVals[1], 1000);
userPage.room.ensureStateEvent.retVals[1].resolve(true, {});
+ tryVerify(() => userPage.powerLevelsLoaded);
tryVerify(() => editButton.enabled);
+ tryVerify(() => editButton.visible);
mouseClick(editButton);
const textField = findChild(userPage, 'newPowerLevelInput');
- tryVerify(() => textField.visible, 1000);
+ tryVerify(() => textField.visible);
textField.text = '50';
const saveButton = findChild(userPage, 'savePowerLevelButton');
+ verify(saveButton.visible);
mouseClick(saveButton);
+ tryVerify(() => room.setUserPowerLevel.calledTimes(), 1000);
tryVerify(() => room.setUserPowerLevel.lastRetVal(), 1000);
// Text field is not closed until the request succeeded
verify(textField.visible);
@@ -152,13 +156,9 @@
verify(findChild(userPage, 'discardPowerLevelButton').enabled);
}
- /**
- * The zz prefix is to allow this test to run after tst_powerlevel,
- * which would otherwise fail for unknown reasons.
- */
- function test_zzbanUser() {
+ function test_banUser() {
// Ban user is only available if membership ! = "ban"
- userPage.user = ({ membership: "join" });
+ userPage.user = ({ membership: "join", userId: '@mew:example.com' });
const banButton = findChild(userPage, 'banUserButton');
verify(banButton.visible);
verify(banButton.enabled);
@@ -184,7 +184,7 @@
tryVerify(() => banButton.enabled, 1000);
}
- function test_zzbanUserFailure() {
+ function test_banUserFailure() {
// Ban user is only available if membership ! = "ban"
userPage.user = ({ membership: "join" });
const banButton = findChild(userPage, 'banUserButton');
@@ -246,95 +246,97 @@
tryVerify(() => upper.showPassiveNotification.calledTimes(), 1000);
tryVerify(() => unbanButton.enabled, 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.kickUser.lastRetVal(), 1000);
- verify(room.kickUser.lastArgs()[0] === '@mew:example.com');
- verify(room.kickUser.lastArgs()[1] === 'some reason');
-
- room.kickUser.lastRetVal().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);
- }
+ function test_kickUser() {
+ const kickButton = findChild(userPage, 'kickUserButton');
+ verify(kickButton.visible);
+ verify(kickButton.enabled);
- function test_overridedName() {
- const input = findChild(userPage, 'nameOverrideInput');
- compare(input.text, '');
+ const reasonDialog = findChild(userPage, 'kickUserReasonDialog');
+ verify(!reasonDialog.opened);
+ const textField = findChild(userPage, 'kickUserReasonInput');
- gnMap.map = { '@mew:example.com': 'something' };
- compare(input.text, 'something');
+ mouseClick(kickButton);
+ verify(!reasonDialog.opened);
+ verify(!textField.readOnly);
- verify(!findChild(userPageSelf, 'nameOverrideInput').visible);
- }
+ textField.text = 'some reason';
+ reasonDialog.accept();
+ tryVerify(() => !reasonDialog.opened, 1000);
+ tryVerify(() => !kickButton.enabled, 1000);
+ tryVerify(() => room.kickUser.lastRetVal(), 1000);
+ verify(room.kickUser.lastArgs()[0] === '@mew:example.com');
+ verify(room.kickUser.lastArgs()[1] === 'some reason');
- function test_updateOverridedName() {
- const input = findChild(userPage, 'nameOverrideInput');
- compare(input.text, '');
- verify(input.enabled);
- input.text = 'something';
- const saveButton = findChild(userPage, 'saveNameOverrideButton');
- verify(saveButton.enabled);
- mouseClick(saveButton);
- tryVerify(() => !input.enabled);
- verify(!saveButton.enabled);
- compare(gnMap.setAndUpload.calledTimes(), 1);
- verify(TestHelpers.deepEqual(gnMap.setAndUpload.lastRetVal(), ['@mew:example.com', 'something']));
- gnMap.setAndUpload.lastRetVal().resolve(true, {});
- tryVerify(() => input.enabled);
- verify(saveButton.enabled);
- }
+ room.kickUser.lastRetVal().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);
+ }
- function test_updateOverridedNameFailed() {
- const input = findChild(userPage, 'nameOverrideInput');
- compare(input.text, '');
- verify(input.enabled);
- input.text = 'something';
- const saveButton = findChild(userPage, 'saveNameOverrideButton');
- verify(saveButton.enabled);
- mouseClick(saveButton);
- tryVerify(() => !input.enabled);
- verify(!saveButton.enabled);
- compare(gnMap.setAndUpload.calledTimes(), 1);
- verify(TestHelpers.deepEqual(gnMap.setAndUpload.lastArgs(), ['@mew:example.com', 'something']));
- gnMap.setAndUpload.lastRetVal().resolve(false, {});
- tryVerify(() => input.enabled);
- verify(saveButton.enabled);
- }
+ function test_overridedName() {
+ const input = findChild(userPage, 'nameOverrideInput');
+ compare(input.text, '');
+
+ gnMap.map = { '@mew:example.com': 'something' };
+ tryCompare(input, 'text', 'something');
+ }
+
+ function test_noOverridedNameForSelf() {
+ userPage.userId = '@foo:example.com';
+ verify(!findChild(userPage, 'nameOverrideInput').visible);
+ }
+
+ function test_updateOverridedName() {
+ const input = findChild(userPage, 'nameOverrideInput');
+ compare(input.text, '');
+ verify(input.enabled);
+ input.text = 'something';
+ const saveButton = findChild(userPage, 'saveNameOverrideButton');
+ verify(saveButton.enabled);
+ mouseClick(saveButton);
+ tryVerify(() => !input.enabled);
+ verify(!saveButton.enabled);
+ compare(gnMap.setAndUpload.calledTimes(), 1);
+ verify(JsHelpers.deepEqual(gnMap.setAndUpload.lastArgs(), ['@mew:example.com', 'something']));
+ gnMap.setAndUpload.lastRetVal().resolve(true, {});
+ tryVerify(() => input.enabled);
+ verify(saveButton.enabled);
+ }
- function test_removeOverridedName() {
- gnMap.map = { '@mew:example.com': 'something' };
- const input = findChild(userPage, 'nameOverrideInput');
- compare(input.text, 'something');
- input.text = '';
- const saveButton = findChild(userPage, 'saveNameOverrideButton');
- verify(saveButton.enabled);
- mouseClick(saveButton);
- tryVerify(() => !input.enabled);
- verify(!saveButton.enabled);
- compare(gnMap.setAndUpload.calledTimes(), 1);
- verify(TestHelpers.deepEqual(gnMap.setAndUpload.lastArgs(), ['@mew:example.com', null]));
- gnMap.setAndUpload.lastRetVal().resolve(true, {});
- tryVerify(() => input.enabled);
- verify(saveButton.enabled);
+ function test_updateOverridedNameFailed() {
+ const input = findChild(userPage, 'nameOverrideInput');
+ compare(input.text, '');
+ verify(input.enabled);
+ input.text = 'something';
+ const saveButton = findChild(userPage, 'saveNameOverrideButton');
+ verify(saveButton.enabled);
+ mouseClick(saveButton);
+ tryVerify(() => !input.enabled);
+ verify(!saveButton.enabled);
+ compare(gnMap.setAndUpload.calledTimes(), 1);
+ verify(JsHelpers.deepEqual(gnMap.setAndUpload.lastArgs(), ['@mew:example.com', 'something']));
+ gnMap.setAndUpload.lastRetVal().resolve(false, {});
+ tryVerify(() => input.enabled);
+ verify(saveButton.enabled);
+ }
+
+ function test_removeOverridedName() {
+ gnMap.map = { '@mew:example.com': 'something' };
+ const input = findChild(userPage, 'nameOverrideInput');
+ compare(input.text, 'something');
+ input.text = '';
+ const saveButton = findChild(userPage, 'saveNameOverrideButton');
+ verify(saveButton.enabled);
+ mouseClick(saveButton);
+ tryVerify(() => !input.enabled);
+ verify(!saveButton.enabled);
+ compare(gnMap.setAndUpload.calledTimes(), 1);
+ verify(JsHelpers.deepEqual(gnMap.setAndUpload.lastArgs(), ['@mew:example.com', null]));
+ gnMap.setAndUpload.lastRetVal().resolve(true, {});
+ tryVerify(() => input.enabled);
+ verify(saveButton.enabled);
+ }
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 22, 9:35 PM (17 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39119
Default Alt Text
D66.1732340158.diff (12 KB)
Attached To
Mode
D66: Fix some UserPageTest not being run
Attached
Detach File
Event Timeline
Log In to Comment