Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F140070
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/changelogs/79.fix b/changelogs/79.fix
new file mode 100644
index 0000000..bb8982a
--- /dev/null
+++ b/changelogs/79.fix
@@ -0,0 +1 @@
+Fix join room page
diff --git a/src/contents/ui/JoinRoomPage.qml b/src/contents/ui/JoinRoomPage.qml
index b6136fa..ec7bd7b 100644
--- a/src/contents/ui/JoinRoomPage.qml
+++ b/src/contents/ui/JoinRoomPage.qml
@@ -1,80 +1,75 @@
/*
* This file is part of kazv.
- * SPDX-FileCopyrightText: 2022 tusooa <tusooa@kazv.moe>
+ * SPDX-FileCopyrightText: 2022-2024 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.1
import org.kde.kirigami 2.4 as Kirigami
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.1
+import '.' as Kazv
+
Kirigami.Page {
id: joinRoomPage
title: l10n.get('join-room-page-title')
ButtonGroup {
id: visibilityButtons
}
ColumnLayout {
width: parent.width
spacing: Kirigami.Units.largeSpacing
GridLayout {
columns: 2
Label {
text: l10n.get('join-room-page-id-or-alias-prompt')
}
TextField {
id: idOrAlias
+ objectName: 'idOrAliasInput'
placeholderText: l10n.get('join-room-page-id-or-alias-placeholder')
Layout.fillWidth: true
}
Label {
text: l10n.get('join-room-page-servers-prompt')
}
TextArea {
id: servers
+ objectName: 'serversInput'
placeholderText: l10n.get('join-room-page-servers-placeholder')
Layout.fillWidth: true
}
}
Button {
+ objectName: 'joinRoomButton'
text: l10n.get('join-room-page-action-join-room')
onClicked: joinRoomPage.joinRoom()
}
}
- Connections {
- target: matrixSdk
- function onJoinRoomSuccessful(room) {
- showPassiveNotification(l10n.get('join-room-page-success-prompt', { room }));
- }
-
- function onJoinRoomFailed(room, errorCode, errorMsg) {
- showPassiveNotification(l10n.get('join-room-page-failed-prompt', { room, errorCode, errorMsg }));
- }
- }
-
property var joinRoomHandler: Kazv.AsyncHandler {
property var serverNames: servers.text.split('\n').map(k => k.trim()).filter(k => k)
- property var room: roomIdOrAlias.text
+ property var room: idOrAlias.text
trigger: () => matrixSdk.joinRoom(room, serverNames)
onResolved: {
if (success) {
showPassiveNotification(l10n.get('join-room-page-success-prompt', { room }));
+ pageStack.removePage(joinRoomPage);
} else {
showPassiveNotification(l10n.get('join-room-page-failed-prompt', { room, errorCode: data.errorCode, errorMsg: data.error }));
}
}
}
function joinRoom()
{
joinRoomHandler.call();
}
}
diff --git a/src/tests/quick-tests/tst_JoinRoomPage.qml b/src/tests/quick-tests/tst_JoinRoomPage.qml
new file mode 100644
index 0000000..e481de6
--- /dev/null
+++ b/src/tests/quick-tests/tst_JoinRoomPage.qml
@@ -0,0 +1,116 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2024 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.js' as Helpers
+import 'test-helpers' as TestHelpers
+
+import moe.kazv.mxc.kazv 0.0 as MK
+
+Item {
+ id: item
+ width: 800
+ height: 600
+
+ property var promiseComp: Component {
+ TestHelpers.MatrixPromiseMock {}
+ }
+ property var l10n: Helpers.fluentMock
+ property var showPassiveNotification: () => {}
+ property var matrixSdk: TestHelpers.MatrixSdkMock {
+ property var _joinRoomCalled: 0
+ property var _joinRoomArgs: ({})
+ property var _joinRoomPromise: undefined
+
+ function joinRoom(
+ room, serverNames
+ ) {
+ ++item.matrixSdk._joinRoomCalled;
+ item.matrixSdk._joinRoomArgs = {
+ room,
+ serverNames,
+ };
+ item.matrixSdk._joinRoomPromise = promiseComp.createObject(item);
+ return item.matrixSdk._joinRoomPromise;
+ }
+ }
+ property var sdkVars: ({})
+ property var pageStack: ({
+ removePage (page) {
+ ++item.pageStack._removePageCalled;
+ },
+ _removePageCalled: 0,
+ })
+
+ Kazv.JoinRoomPage {
+ id: joinRoomPage
+ }
+
+ TestCase {
+ id: joinRoomPageTest
+ name: 'JoinRoomPageTest'
+ when: windowShown
+
+ function cleanup() {
+ item.matrixSdk._joinRoomCalled = 0;
+ item.matrixSdk._joinRoomArgs = {};
+ item.matrixSdk._joinRoomPromise = undefined;
+ item.pageStack._removePageCalled = 0;
+ }
+
+ function test_joinRoomWithServers() {
+ findChild(joinRoomPage, 'idOrAliasInput').text = '#foo:example.com';
+ findChild(joinRoomPage, 'serversInput').text = 'example.com\nexample.org';
+ const button = findChild(joinRoomPage, 'joinRoomButton');
+ verify(button.enabled);
+ mouseClick(button);
+
+ tryVerify(() => item.matrixSdk._joinRoomCalled === 1, 1000);
+ console.log(JSON.stringify(item.matrixSdk._joinRoomArgs));
+ verify(Helpers.deepEqual(item.matrixSdk._joinRoomArgs, {
+ room: '#foo:example.com',
+ serverNames: ['example.com', 'example.org'],
+ }));
+
+ item.matrixSdk._joinRoomPromise.resolve(true, {});
+ tryVerify(() => item.pageStack._removePageCalled === 1);
+ }
+
+ function test_joinRoomWithoutServers() {
+ findChild(joinRoomPage, 'idOrAliasInput').text = '#foo:example.com';
+ findChild(joinRoomPage, 'serversInput').text = '';
+ const button = findChild(joinRoomPage, 'joinRoomButton');
+ verify(button.enabled);
+ mouseClick(button);
+
+ tryVerify(() => item.matrixSdk._joinRoomCalled === 1, 1000);
+ verify(Helpers.deepEqual(item.matrixSdk._joinRoomArgs, {
+ room: '#foo:example.com',
+ serverNames: [],
+ }));
+
+ item.matrixSdk._joinRoomPromise.resolve(true, {});
+ tryVerify(() => item.pageStack._removePageCalled === 1);
+ }
+
+ function test_joinRoomFailure() {
+ findChild(joinRoomPage, 'idOrAliasInput').text = '#foo:example.com';
+ findChild(joinRoomPage, 'serversInput').text = '';
+ const button = findChild(joinRoomPage, 'joinRoomButton');
+ verify(button.enabled);
+ mouseClick(button);
+
+ tryVerify(() => item.matrixSdk._joinRoomCalled === 1, 1000);
+
+ item.matrixSdk._joinRoomPromise.resolve(false, {});
+ tryVerify(() => item.pageStack._removePageCalled === 0);
+ }
+ }
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jan 19, 11:45 AM (4 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55141
Default Alt Text
(6 KB)
Attached To
Mode
rK kazv
Attached
Detach File
Event Timeline
Log In to Comment