Page MenuHomePhorge

No OneTemporary

Size
169 KB
Referenced Files
None
Subscribers
None
diff --git a/src/tests/quick-tests/test-helpers/KazvIOManagerMock.qml b/src/tests/quick-tests/test-helpers/KazvIOManagerMock.qml
index c3bddcc..9e73cce 100644
--- a/src/tests/quick-tests/test-helpers/KazvIOManagerMock.qml
+++ b/src/tests/quick-tests/test-helpers/KazvIOManagerMock.qml
@@ -1,15 +1,28 @@
/*
* 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
QtObject {
id: managerMock
+ property var startNewUploadJob: mockHelper.noop([
+ 'serverUrl',
+ 'fileUrl',
+ 'token',
+ 'roomId',
+ 'roomList',
+ 'encrypted',
+ 'draftRelType',
+ 'draftRelatedTo'
+ ])
+ property var deleteDownloadJob: mockHelper.noop()
+ property var deleteUploadJob: mockHelper.noop()
+
function getDownloadJob (jobId) {
const component = Qt.createComponent("KazvIOJobMock.qml");
return component.createObject(managerMock);
}
}
diff --git a/src/tests/quick-tests/test-helpers/MatrixSdkMock.qml b/src/tests/quick-tests/test-helpers/MatrixSdkMock.qml
index 822ae79..e11b10b 100644
--- a/src/tests/quick-tests/test-helpers/MatrixSdkMock.qml
+++ b/src/tests/quick-tests/test-helpers/MatrixSdkMock.qml
@@ -1,18 +1,37 @@
/*
* 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
QtObject {
+ property var userId: ''
+ property var serverUrl: 'https://example.com'
+ property var token: 'token'
+ property var updateStickerPack: mockHelper.promise()
+ property var createRoom: mockHelper.promise([
+ 'isPrivate',
+ 'name',
+ 'alias',
+ 'invites',
+ 'isDirect',
+ 'allowFederate',
+ 'topic',
+ 'powerLevelContentOverride',
+ 'preset',
+ 'encrypted',
+ ])
+ property var joinRoom: mockHelper.promise()
+ property var sendAccountData: mockHelper.promise()
+
function mxcUriToHttp (uri) {
console.log('mxcUriToHttp');
return uri || '';
}
function devicesOfUser (userId) {
return [];
}
}
diff --git a/src/tests/quick-tests/test-helpers/TestItem.qml b/src/tests/quick-tests/test-helpers/TestItem.qml
new file mode 100644
index 0000000..562bd61
--- /dev/null
+++ b/src/tests/quick-tests/test-helpers/TestItem.qml
@@ -0,0 +1,50 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2024 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import QtQuick
+import QtTest
+import '.' as QmlHelpers
+import '../test-helpers.js' as JsHelpers
+
+Item {
+ id: item
+ width: 800
+ height: 600
+
+ property var l10n: JsHelpers.fluentMock
+ property var mockHelper: QmlHelpers.MockHelper {}
+ property var promiseComp: Component {
+ QmlHelpers.MatrixPromiseMock {}
+ }
+ property var matrixSdk: QmlHelpers.MatrixSdkMock {
+ }
+ property var sdkVars: QtObject {
+ property var roomList: ({})
+ property var userGivenNicknameMap: QtObject {
+ property var map: ({
+ '@foo:tusooa.xyz': 'something',
+ })
+ property var setAndUpload: mockHelper.promise()
+ }
+ }
+ property var kazvIOManager: QmlHelpers.KazvIOManagerMock {}
+ property var showPassiveNotification: mockHelper.noop()
+ property var pageStack: QtObject {
+ property var removePage: mockHelper.noop()
+ }
+
+ function applicationWindow() {
+ return Window.window;
+ }
+
+ Component.onCompleted: {
+ const testFunctions = Object.keys(item).filter(name => name.startsWith('test_'));
+ if (testFunctions.length) {
+ console.error('There are functions starting with test_ in the root item. It is likely that they belong to the TestCase instead. The functions are:', testFunctions);
+ throw new Error('Unexpected test functions');
+ }
+ }
+}
diff --git a/src/tests/quick-tests/tst_About.qml b/src/tests/quick-tests/tst_About.qml
index 29ec012..3da8ac2 100644
--- a/src/tests/quick-tests/tst_About.qml
+++ b/src/tests/quick-tests/tst_About.qml
@@ -1,65 +1,61 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2024 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick
import QtTest
import '../../contents/ui' as Kazv
-import 'test-helpers.js' as Helpers
+import 'test-helpers' as QmlHelpers
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
-
- property var l10n: Helpers.fluentMock
Kazv.About {
id: about
authors: [
{
name: 'author 0',
task: 'task 0',
},
{
name: 'author 1',
task: 'task 1',
emailAddress: 'email@example.com',
},
{
name: 'author 2',
task: 'task 2',
website: 'https://example.com',
},
{
name: 'author 3',
task: 'task 3',
emailAddress: 'email@example.com',
website: 'https://example.com',
},
]
}
TestCase {
id: aboutTest
name: 'AboutTest'
when: windowShown
function test_authors() {
const card = findChild(about, 'authorsCard');
verify(!findChild(findChild(card, 'authors0'), 'emailButton').visible);
verify(!findChild(findChild(card, 'authors0'), 'websiteButton').visible);
verify(findChild(findChild(card, 'authors1'), 'emailButton').visible);
verify(!findChild(findChild(card, 'authors1'), 'websiteButton').visible);
verify(!findChild(findChild(card, 'authors2'), 'emailButton').visible);
verify(findChild(findChild(card, 'authors2'), 'websiteButton').visible);
verify(findChild(findChild(card, 'authors3'), 'emailButton').visible);
verify(findChild(findChild(card, 'authors3'), 'websiteButton').visible);
}
}
}
diff --git a/src/tests/quick-tests/tst_AddStickerPopup.qml b/src/tests/quick-tests/tst_AddStickerPopup.qml
index f87c41d..ac4ca56 100644
--- a/src/tests/quick-tests/tst_AddStickerPopup.qml
+++ b/src/tests/quick-tests/tst_AddStickerPopup.qml
@@ -1,150 +1,138 @@
/*
* 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 org.kde.kirigami 2.20 as Kirigami
import '../../contents/ui' as Kazv
import 'test-helpers.js' as Helpers
-import 'test-helpers' as TestHelpers
+import 'test-helpers' as QmlHelpers
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
-
- property var l10n: Helpers.fluentMock
- property var mockHelper: TestHelpers.MockHelper {}
- property var promiseComp: Component {
- TestHelpers.MatrixPromiseMock {}
- }
- property var matrixSdk: TestHelpers.MatrixSdkMock {
- id: matrixSdk
- property var updateStickerPack: mockHelper.promise()
- }
Kazv.AddStickerPopup {
id: addStickerPopup
event: ({
content: {
url: 'mxc://example.org/something',
},
})
stickerPackList: ({
at(index) {
return {
addSticker(shortCode, event) {
return {
_packIndex: index,
event: {
content: {
images: {
[shortCode]: event.content,
},
},
},
};
},
hasShortCode(shortCode) {
return shortCode === 'foo';
},
};
},
packs: [
{ packName: 'pack0' },
{ packName: 'pack1' },
],
})
property var close: mockHelper.noop()
}
TestCase {
id: eventViewTest
name: 'EventViewTest'
when: windowShown
function init() {
addStickerPopup.contentItem.parent = item;
findChild(addStickerPopup, 'packChooser').currentIndex = 0;
addStickerPopup.addingSticker = false;
}
function cleanup() {
item.mockHelper.clearAll();
}
function test_addSticker() {
findChild(addStickerPopup, 'shortCodeInput').text = 'bar';
verify(!findChild(addStickerPopup, 'shortCodeExistsWarning').visible);
const button = findChild(addStickerPopup, 'addStickerButton');
verify(button.enabled);
mouseClick(button);
tryVerify(() => matrixSdk.updateStickerPack.calledTimes() === 1);
verify(Helpers.deepEqual(matrixSdk.updateStickerPack.lastArgs()[0].event.content.images, {
'bar': {
url: 'mxc://example.org/something',
}
}));
tryVerify(() => !button.enabled);
tryVerify(() => findChild(addStickerPopup, 'shortCodeInput').readOnly);
verify(addStickerPopup.close.calledTimes() === 0);
matrixSdk.updateStickerPack.lastRetVal().resolve(true, {});
tryVerify(() => addStickerPopup.close.calledTimes() === 1);
}
function test_addStickerOtherPack() {
verify(Helpers.deepEqual(addStickerPopup.availablePackNames, ['pack0', 'pack1']));
findChild(addStickerPopup, 'packChooser').currentIndex = 1;
findChild(addStickerPopup, 'shortCodeInput').text = 'bar';
verify(!findChild(addStickerPopup, 'shortCodeExistsWarning').visible);
const button = findChild(addStickerPopup, 'addStickerButton');
verify(button.enabled);
mouseClick(button);
tryVerify(() => matrixSdk.updateStickerPack.calledTimes() === 1);
compare(matrixSdk.updateStickerPack.lastArgs()[0]._packIndex, 1);
}
function test_addStickerFailed() {
findChild(addStickerPopup, 'shortCodeInput').text = 'bar';
verify(!findChild(addStickerPopup, 'shortCodeExistsWarning').visible);
const button = findChild(addStickerPopup, 'addStickerButton');
verify(button.enabled);
mouseClick(button);
tryVerify(() => matrixSdk.updateStickerPack.calledTimes() === 1);
verify(Helpers.deepEqual(matrixSdk.updateStickerPack.lastArgs()[0].event.content.images, {
'bar': {
url: 'mxc://example.org/something',
}
}));
matrixSdk.updateStickerPack.lastRetVal().resolve(false, {});
tryVerify(() => button.enabled);
verify(addStickerPopup.close.calledTimes() === 0);
}
function test_addStickerOverride() {
findChild(addStickerPopup, 'shortCodeInput').text = 'foo';
tryVerify(() => findChild(addStickerPopup, 'shortCodeExistsWarning').visible);
const button = findChild(addStickerPopup, 'addStickerButton');
verify(button.enabled);
mouseClick(button);
tryVerify(() => matrixSdk.updateStickerPack.calledTimes() === 1);
verify(Helpers.deepEqual(matrixSdk.updateStickerPack.lastArgs()[0].event.content.images, {
'foo': {
url: 'mxc://example.org/something',
}
}));
tryVerify(() => !button.enabled);
tryVerify(() => findChild(addStickerPopup, 'shortCodeInput').readOnly);
verify(addStickerPopup.close.calledTimes() === 0);
matrixSdk.updateStickerPack.lastRetVal().resolve(true, {});
tryVerify(() => addStickerPopup.close.calledTimes() === 1);
}
}
}
diff --git a/src/tests/quick-tests/tst_ConfirmUploadPopup.qml b/src/tests/quick-tests/tst_ConfirmUploadPopup.qml
index 66b24bf..29f167b 100644
--- a/src/tests/quick-tests/tst_ConfirmUploadPopup.qml
+++ b/src/tests/quick-tests/tst_ConfirmUploadPopup.qml
@@ -1,102 +1,99 @@
/*
* 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 org.kde.kirigami 2.20 as Kirigami
import moe.kazv.mxc.kazv 0.0 as MK
import '../../contents/ui' as Kazv
-import 'test-helpers.js' as Helpers
-import 'test-helpers' as TestHelpers
+import 'test-helpers' as QmlHelpers
-Item {
+QmlHelpers.TestItem {
id: item
width: Kirigami.Units.gridUnit * 80
height: 600
- property var l10n: Helpers.fluentMock
-
SignalSpy {
id: uploadRequestedSpy
signalName: 'uploadRequested'
}
Kazv.ConfirmUploadPopup {
id: confirmUploadPopup
}
function isSheetOpen(sheet) {
return sheet.opened;
}
TestCase {
id: confirmUploadPopupTest
name: 'ConfirmUploadPopupTest'
when: windowShown
function init() {
uploadRequestedSpy.clear();
uploadRequestedSpy.target = confirmUploadPopup;
}
function test_singleUpload() {
confirmUploadPopup.call(['file:///tmp/image.png']);
tryVerify(() => isSheetOpen(confirmUploadPopup));
if (MK.KazvUtil.kfQtMajorVersion === 5) {
confirmUploadPopup.contentItem.parent = item;
}
tryVerify(() => findChild(confirmUploadPopup, 'imagePreview').visible);
mouseClick(findChild(confirmUploadPopup, 'acceptButton'));
tryVerify(() => !isSheetOpen(confirmUploadPopup));
verify(uploadRequestedSpy.count === 1);
verify(uploadRequestedSpy.signalArguments[0][0] === 'file:///tmp/image.png');
}
function test_singleUploadCancelled() {
confirmUploadPopup.call(['file:///tmp/image.png']);
tryVerify(() => isSheetOpen(confirmUploadPopup));
if (MK.KazvUtil.kfQtMajorVersion === 5) {
confirmUploadPopup.contentItem.parent = item;
}
tryVerify(() => findChild(confirmUploadPopup, 'imagePreview').visible);
mouseClick(findChild(confirmUploadPopup, 'cancelButton'));
tryVerify(() => !isSheetOpen(confirmUploadPopup));
verify(uploadRequestedSpy.count === 0);
}
function test_multiUpload() {
confirmUploadPopup.call(['file:///tmp/image.png', 'file:///tmp/a.txt']);
tryVerify(() => isSheetOpen(confirmUploadPopup));
if (MK.KazvUtil.kfQtMajorVersion === 5) {
confirmUploadPopup.contentItem.parent = item;
}
tryVerify(() => findChild(confirmUploadPopup, 'imagePreview').visible);
mouseClick(findChild(confirmUploadPopup, 'acceptButton'));
verify(isSheetOpen(confirmUploadPopup));
tryVerify(() => !findChild(confirmUploadPopup, 'imagePreview').visible);
verify(uploadRequestedSpy.count === 1);
verify(uploadRequestedSpy.signalArguments[0][0] === 'file:///tmp/image.png');
verify(confirmUploadPopup.currentIndex === 1);
mouseClick(findChild(confirmUploadPopup, 'acceptButton'));
tryVerify(() => !isSheetOpen(confirmUploadPopup));
verify(uploadRequestedSpy.count === 2);
verify(uploadRequestedSpy.signalArguments[1][0] === 'file:///tmp/a.txt');
}
function test_multiUploadCancelled() {
confirmUploadPopup.call(['file:///tmp/image.png', 'file:///tmp/a.txt']);
tryVerify(() => isSheetOpen(confirmUploadPopup));
tryVerify(() => findChild(confirmUploadPopup, 'imagePreview').visible);
const button = findChild(confirmUploadPopup, 'cancelButton');
mouseClick(button);
tryVerify(() => !isSheetOpen(confirmUploadPopup));
verify(uploadRequestedSpy.count === 0);
}
}
}
diff --git a/src/tests/quick-tests/tst_CreateRoomPage.qml b/src/tests/quick-tests/tst_CreateRoomPage.qml
index 56ac681..f6e0271 100644
--- a/src/tests/quick-tests/tst_CreateRoomPage.qml
+++ b/src/tests/quick-tests/tst_CreateRoomPage.qml
@@ -1,279 +1,259 @@
/*
* 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 'test-helpers.js' as JsHelpers
+import 'test-helpers' as QmlHelpers
import moe.kazv.mxc.kazv 0.0 as MK
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
-
- property var mockHelper: TestHelpers.MockHelper {}
- property var l10n: Helpers.fluentMock
- property var matrixSdk: TestHelpers.MatrixSdkMock {
- property var createRoom: mockHelper.promise([
- 'isPrivate',
- 'name',
- 'alias',
- 'invites',
- 'isDirect',
- 'allowFederate',
- 'topic',
- 'powerLevelContentOverride',
- 'preset',
- 'encrypted',
- ])
- }
- property var sdkVars: ({})
Kazv.CreateRoomPage {
anchors.fill: parent
id: createRoomPage
}
TestCase {
id: createRoomPageTest
name: 'CreateRoomPageTest'
when: windowShown
function initTestCase() {
if (MK.KazvUtil.kfQtMajorVersion === 6) {
createRoomPage.contentItem.clip = false;
}
waitForRendering(createRoomPage);
}
function cleanup() {
mockHelper.clearAll();
createRoomPage.inviteUserIds = [];
createRoomPage.creatingRoom = false;
createRoomPage.encryptedChangedOnce = false;
}
function test_createRoomPublic() {
mouseClick(findChild(createRoomPage, 'typePublicRadio'));
findChild(createRoomPage, 'roomNameInput').text = 'some name';
findChild(createRoomPage, 'roomAliasInput').text = 'alias';
findChild(createRoomPage, 'roomTopicInput').text = 'some topic';
const button = findChild(createRoomPage, 'createRoomButton');
verify(button.enabled);
mouseClick(button);
tryVerify(() => item.matrixSdk.createRoom.calledTimes() === 1, 1000);
- verify(Helpers.deepEqual(item.matrixSdk.createRoom.lastArgs(), {
+ verify(JsHelpers.deepEqual(item.matrixSdk.createRoom.lastArgs(), {
isPrivate: false,
name: 'some name',
alias: 'alias',
topic: 'some topic',
invites: [],
isDirect: false,
allowFederate: true,
powerLevelContentOverride: {},
preset: MK.MatrixSdk.PublicChat,
encrypted: false,
}));
}
function test_createRoomPrivate() {
mouseClick(findChild(createRoomPage, 'typePrivateRadio'));
findChild(createRoomPage, 'roomNameInput').text = 'some name';
findChild(createRoomPage, 'roomAliasInput').text = 'alias';
findChild(createRoomPage, 'roomTopicInput').text = 'some topic';
const button = findChild(createRoomPage, 'createRoomButton');
verify(button.enabled);
mouseClick(button);
tryVerify(() => item.matrixSdk.createRoom.calledTimes() === 1, 1000);
- verify(Helpers.deepEqual(item.matrixSdk.createRoom.lastArgs(), {
+ verify(JsHelpers.deepEqual(item.matrixSdk.createRoom.lastArgs(), {
isPrivate: true,
name: 'some name',
alias: 'alias',
topic: 'some topic',
invites: [],
isDirect: false,
allowFederate: true,
powerLevelContentOverride: {},
preset: MK.MatrixSdk.PrivateChat,
encrypted: true,
}));
}
function test_createRoomDirect() {
mouseClick(findChild(createRoomPage, 'typeDirectRadio'));
findChild(createRoomPage, 'roomNameInput').text = 'some name';
findChild(createRoomPage, 'roomAliasInput').text = 'alias';
findChild(createRoomPage, 'roomTopicInput').text = 'some topic';
const button = findChild(createRoomPage, 'createRoomButton');
verify(button.enabled);
mouseClick(button);
tryVerify(() => item.matrixSdk.createRoom.calledTimes() === 1, 1000);
- verify(Helpers.deepEqual(item.matrixSdk.createRoom.lastArgs(), {
+ verify(JsHelpers.deepEqual(item.matrixSdk.createRoom.lastArgs(), {
isPrivate: true,
name: 'some name',
alias: 'alias',
topic: 'some topic',
invites: [],
isDirect: false,
allowFederate: true,
powerLevelContentOverride: {},
preset: MK.MatrixSdk.TrustedPrivateChat,
encrypted: true,
}));
}
function test_createRoomDirectInviteOne() {
mouseClick(findChild(createRoomPage, 'typeDirectRadio'));
findChild(createRoomPage, 'roomNameInput').text = 'some name';
findChild(createRoomPage, 'roomAliasInput').text = 'alias';
findChild(createRoomPage, 'roomTopicInput').text = 'some topic';
const addInviteInput = findChild(createRoomPage, 'newInviteUserInput');
addInviteInput.text = '@foo:example.org';
const addInviteButton = findChild(createRoomPage, 'addInviteUserButton');
mouseClick(addInviteButton);
tryVerify(() => addInviteInput.text === '', 1000);
const button = findChild(createRoomPage, 'createRoomButton');
verify(button.enabled);
mouseClick(button);
tryVerify(() => item.matrixSdk.createRoom.calledTimes() === 1, 1000);
- verify(Helpers.deepEqual(item.matrixSdk.createRoom.lastArgs(), {
+ verify(JsHelpers.deepEqual(item.matrixSdk.createRoom.lastArgs(), {
isPrivate: true,
name: 'some name',
alias: 'alias',
topic: 'some topic',
invites: ['@foo:example.org'],
isDirect: true,
allowFederate: true,
powerLevelContentOverride: {},
preset: MK.MatrixSdk.TrustedPrivateChat,
encrypted: true,
}));
}
function test_createRoomDirectInviteMultiple() {
mouseClick(findChild(createRoomPage, 'typeDirectRadio'));
findChild(createRoomPage, 'roomNameInput').text = 'some name';
findChild(createRoomPage, 'roomAliasInput').text = 'alias';
findChild(createRoomPage, 'roomTopicInput').text = 'some topic';
const addInviteInput = findChild(createRoomPage, 'newInviteUserInput');
const addInviteButton = findChild(createRoomPage, 'addInviteUserButton');
addInviteInput.text = '@foo:example.org';
mouseClick(addInviteButton);
tryVerify(() => addInviteInput.text === '', 1000);
addInviteInput.text = '@bar:example.org';
mouseClick(addInviteButton);
tryVerify(() => addInviteInput.text === '', 1000);
const button = findChild(createRoomPage, 'createRoomButton');
verify(button.enabled);
mouseClick(button);
tryVerify(() => item.matrixSdk.createRoom.calledTimes() === 1, 1000);
- verify(Helpers.deepEqual(item.matrixSdk.createRoom.lastArgs(), {
+ verify(JsHelpers.deepEqual(item.matrixSdk.createRoom.lastArgs(), {
isPrivate: true,
name: 'some name',
alias: 'alias',
topic: 'some topic',
invites: ['@foo:example.org', '@bar:example.org'],
isDirect: false,
allowFederate: true,
powerLevelContentOverride: {},
preset: MK.MatrixSdk.TrustedPrivateChat,
encrypted: true,
}));
}
function test_invite() {
mouseClick(findChild(createRoomPage, 'typePublicRadio'));
findChild(createRoomPage, 'roomNameInput').text = 'some name';
findChild(createRoomPage, 'roomAliasInput').text = 'alias';
findChild(createRoomPage, 'roomTopicInput').text = 'some topic';
const button = findChild(createRoomPage, 'createRoomButton');
verify(button.enabled);
mouseClick(button);
// add three invites
const addInviteInput = findChild(createRoomPage, 'newInviteUserInput');
const addInviteButton = findChild(createRoomPage, 'addInviteUserButton');
addInviteInput.text = '@foo:example.org';
mouseClick(addInviteButton);
tryVerify(() => addInviteInput.text === '', 1000);
addInviteInput.text = '@bar:example.org';
mouseClick(addInviteButton);
tryVerify(() => addInviteInput.text === '', 1000);
addInviteInput.text = '@baz:example.org';
mouseClick(addInviteButton);
tryVerify(() => addInviteInput.text === '', 1000);
// remove the second invite (bar)
tryVerify(() => findChild(createRoomPage, 'inviteUserItem_1'), 1000);
const inviteItem = findChild(createRoomPage, 'inviteUserItem_1');
compare(findChild(inviteItem, 'inviteUserIdLabel').text, '@bar:example.org');
findChild(inviteItem, 'removeInviteAction').trigger();
tryVerify(() => {
const label = findChild(
findChild(createRoomPage, 'inviteUserItem_1'),
'inviteUserIdLabel'
);
return label && label.text === '@baz:example.org'
}, 50000);
tryVerify(() => item.matrixSdk.createRoom.calledTimes() === 1, 1000);
- verify(Helpers.deepEqual(item.matrixSdk.createRoom.lastArgs(), {
+ verify(JsHelpers.deepEqual(item.matrixSdk.createRoom.lastArgs(), {
isPrivate: false,
name: 'some name',
alias: 'alias',
topic: 'some topic',
invites: ['@foo:example.org', '@baz:example.org'],
isDirect: false,
allowFederate: true,
powerLevelContentOverride: {},
preset: MK.MatrixSdk.PublicChat,
encrypted: false,
}));
}
function test_encryptedCheckBox() {
const publicRadio = findChild(createRoomPage, 'typePublicRadio');
const privateRadio = findChild(createRoomPage, 'typePrivateRadio');
const directRadio = findChild(createRoomPage, 'typeDirectRadio')
const encryptedInput = findChild(createRoomPage, 'encryptedInput');
mouseClick(publicRadio);
verify(!encryptedInput.checked);
mouseClick(privateRadio);
verify(encryptedInput.checked);
mouseClick(directRadio);
verify(encryptedInput.checked);
mouseClick(encryptedInput);
verify(!encryptedInput.checked);
mouseClick(publicRadio);
verify(!encryptedInput.checked);
mouseClick(directRadio);
verify(!encryptedInput.checked);
}
}
}
diff --git a/src/tests/quick-tests/tst_Device.qml b/src/tests/quick-tests/tst_Device.qml
index 9ddae74..cfcde59 100644
--- a/src/tests/quick-tests/tst_Device.qml
+++ b/src/tests/quick-tests/tst_Device.qml
@@ -1,42 +1,38 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.3
import QtTest 1.0
import '../../contents/ui/device-mgmt' as KazvDM
-import 'test-helpers.js' as Helpers
-
-Item {
- width: 800
- height: 600
-
- property var l10n: Helpers.fluentMock
+import 'test-helpers' as QmlHelpers
+QmlHelpers.TestItem {
property var deviceItem: ({
deviceId: 'some-id',
displayName: 'name',
trustLevel: 'unseen'
})
+
KazvDM.Device {
id: device
}
TestCase {
id: deviceTest
name: 'DeviceTest'
when: windowShown
function initTestCase() {
device.item = deviceItem;
}
function test_device() {
verify(findChild(device, 'deviceIdLabel').text === 'some-id');
verify(findChild(device, 'trustLevelLabel').text === l10n.get('device-trust-level-unseen'));
}
}
}
diff --git a/src/tests/quick-tests/tst_DeviceList.qml b/src/tests/quick-tests/tst_DeviceList.qml
index 4f84a91..dcf2a19 100644
--- a/src/tests/quick-tests/tst_DeviceList.qml
+++ b/src/tests/quick-tests/tst_DeviceList.qml
@@ -1,63 +1,58 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.3
import QtTest 1.0
import '../../contents/ui/device-mgmt' as KazvDM
-import 'test-helpers.js' as Helpers
-
-Item {
- width: 800
- height: 600
-
- property var l10n: Helpers.fluentMock
+import 'test-helpers' as QmlHelpers
+QmlHelpers.TestItem {
property var deviceItems: [
{
deviceId: 'some-id',
displayName: 'name',
trustLevel: 'unseen'
},
{
deviceId: 'some-id2',
displayName: 'name2',
trustLevel: 'unseen'
},
]
property var deviceListModel: ({
count: 2,
at: (index) => {
return deviceItems[index] || {}
},
})
KazvDM.DeviceList {
id: deviceList
anchors.fill: parent
}
TestCase {
id: deviceListTest
name: 'DeviceListTest'
when: windowShown
function initTestCase() {
deviceList.devices = deviceListModel;
}
function test_deviceList() {
verify(deviceList.model === 2);
deviceList.currentIndex = 0;
verify(deviceList.itemAtIndex(0));
verify(findChild(deviceList.itemAtIndex(0), 'deviceIdLabel').text === 'some-id');
deviceList.currentIndex = 1;
tryVerify(() => findChild(deviceList.itemAtIndex(1)), 1000);
tryVerify(() => findChild(deviceList.itemAtIndex(1), 'deviceIdLabel').text === 'some-id2', 1000);
}
}
}
diff --git a/src/tests/quick-tests/tst_DevicePopup.qml b/src/tests/quick-tests/tst_DevicePopup.qml
index 1cf2ec8..b4127c5 100644
--- a/src/tests/quick-tests/tst_DevicePopup.qml
+++ b/src/tests/quick-tests/tst_DevicePopup.qml
@@ -1,58 +1,50 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.3
import QtTest 1.0
import moe.kazv.mxc.kazv 0.0 as MK
import '../../contents/ui/device-mgmt' as KazvDM
-import 'test-helpers.js' as Helpers
+import 'test-helpers' as QmlHelpers
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
-
- property var l10n: Helpers.fluentMock
property var deviceItem: ({
deviceId: 'some-id',
displayName: 'name',
trustLevel: 'unseen'
})
- function applicationWindow() {
- return Window.window;
- }
-
KazvDM.Device {
id: device
item: deviceItem
}
TestCase {
id: devicePopupTest
name: 'DevicePopupTest'
when: windowShown
function initTestCase() {
}
function test_trustLevelPopup() {
if (MK.KazvUtil.kfQtMajorVersion === 6) {
device.sheet.parent = item;
}
device.sheet.open();
tryVerify(() => device.sheet.getNewTrustLevel() === 'unseen', 1000);
const buttons = findChild(device.sheet, 'trustLevelChoices');
if (MK.KazvUtil.kfQtMajorVersion === 5) {
buttons.parent = device; // force showing, the OverlaySheet does not seem to show properly
}
const button = findChild(buttons, 'trustLevelChoice_verified');
mouseClick(button);
tryVerify(() => device.sheet.getNewTrustLevel() === 'verified', 1000);
}
}
}
diff --git a/src/tests/quick-tests/tst_EventHistoryView.qml b/src/tests/quick-tests/tst_EventHistoryView.qml
index 2458947..3682c07 100644
--- a/src/tests/quick-tests/tst_EventHistoryView.qml
+++ b/src/tests/quick-tests/tst_EventHistoryView.qml
@@ -1,61 +1,56 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2024 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick
import QtQuick.Layouts
import QtTest
import '../../contents/ui' as Kazv
-import 'test-helpers.js' as Helpers
-import 'test-helpers' as TestHelpers
+import 'test-helpers' as QmlHelpers
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
-
- property var mockHelper: TestHelpers.MockHelper {}
property var room: ({
messageById: (_id) => item.textEvent,
member: (_id) => ({}),
})
property var history: ListModel {
ListElement {}
ListElement {}
function at(index) {
return {
type: 'm.room.message',
content: {
msgtype: 'm.text',
body: `version ${index}`,
},
sender: '@foo:example.com',
};
}
}
Kazv.EventHistoryView {
id: eventHistoryView
anchors.fill: parent
history: item.history
}
TestCase {
id: eventHistoryViewTest
name: 'EventHistoryViewTest'
function test_history() {
tryVerify(() => eventHistoryView.itemAtIndex(0));
const v0 = eventHistoryView.itemAtIndex(0);
verify(findChild(v0, 'timeIndicator').visible);
compare(findChild(v0, 'textEventContent').text, 'version 0');
tryVerify(() => eventHistoryView.itemAtIndex(1));
compare(findChild(eventHistoryView.itemAtIndex(1), 'textEventContent').text, 'version 1');
}
}
}
diff --git a/src/tests/quick-tests/tst_EventReadIndicator.qml b/src/tests/quick-tests/tst_EventReadIndicator.qml
index 0356036..b096c19 100644
--- a/src/tests/quick-tests/tst_EventReadIndicator.qml
+++ b/src/tests/quick-tests/tst_EventReadIndicator.qml
@@ -1,71 +1,59 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.3
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 'test-helpers' as QmlHelpers
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
-
- property var l10n: Helpers.fluentMock
- property var matrixSdk: TestHelpers.MatrixSdkMock {}
- property var sdkVars: QtObject {
- property var userGivenNicknameMap: QtObject {
- property var map: ({})
- }
- }
- property var kazvIOManager: TestHelpers.KazvIOManagerMock {}
function makeModel(size) {
return {
at(index) {
return {
userId: `@u${index}:example.com`,
name: `user ${index}`,
};
},
count: size,
};
}
Kazv.EventReadIndicator {
id: indicator
}
TestCase {
id: eventReadIndicatorTest
name: 'EventReadIndicatorTest'
when: windowShown
function test_noUser() {
indicator.model = makeModel(0);
verify(!indicator.visible);
}
function test_singleUser() {
indicator.model = makeModel(1);
tryVerify(() => indicator.visible);
verify(findChild(indicator, 'readIndicatorAvatar0').name === 'user 0');
verify(!findChild(indicator, 'moreUsersIndicator').visible);
}
function test_tooManyUsers() {
indicator.model = makeModel(5);
tryVerify(() => indicator.visible);
verify(indicator.actualItems === indicator.maxItems);
verify(findChild(indicator, 'readIndicatorAvatar3').name === 'user 3');
verify(!findChild(indicator, 'readIndicatorAvatar4'));
verify(findChild(indicator, 'moreUsersIndicator').visible);
}
}
}
diff --git a/src/tests/quick-tests/tst_EventSourceView.qml b/src/tests/quick-tests/tst_EventSourceView.qml
index 898d2f0..d91bfae 100644
--- a/src/tests/quick-tests/tst_EventSourceView.qml
+++ b/src/tests/quick-tests/tst_EventSourceView.qml
@@ -1,90 +1,87 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.3
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 'test-helpers' as QmlHelpers
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
- property var l10n: Helpers.fluentMock
+
property var unencryptedEvent: ({
encrypted: false,
decrypted: false,
originalSource: {
event_id: '$foo',
content: {},
},
})
property var encryptedEvent: ({
encrypted: true,
decrypted: false,
originalSource: {
event_id: '$foo',
content: {},
},
})
property var decryptedEvent: ({
encrypted: true,
decrypted: true,
originalSource: {
event_id: '$foo',
content: {},
},
decryptedSource: {
content: {
msgtype: 'm.text',
body: 'foo',
},
},
})
ColumnLayout {
Kazv.EventSourceView {
id: evUnencrypted
event: unencryptedEvent
}
Kazv.EventSourceView {
id: evEncrypted
event: encryptedEvent
}
Kazv.EventSourceView {
id: evDecrypted
event: decryptedEvent
}
}
TestCase {
id: eventSourceViewTest
name: 'EventSourceViewTest'
when: windowShown
function test_unencrypted() {
verify(!findChild(evUnencrypted, 'decryptedSourceView').visible);
verify(findChild(evUnencrypted, 'originalSourceView').visible);
}
function test_encrypted() {
verify(findChild(evEncrypted, 'decryptedSourceView').visible);
verify(findChild(evEncrypted, 'originalSourceView').visible);
}
function test_decrypted() {
verify(findChild(evDecrypted, 'decryptedSourceView').visible);
verify(findChild(evDecrypted, 'originalSourceView').visible);
}
}
}
diff --git a/src/tests/quick-tests/tst_EventView.qml b/src/tests/quick-tests/tst_EventView.qml
index be2379d..e3a8f4c 100644
--- a/src/tests/quick-tests/tst_EventView.qml
+++ b/src/tests/quick-tests/tst_EventView.qml
@@ -1,714 +1,700 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.3
import QtQuick.Layouts 1.15
import QtTest 1.0
import moe.kazv.mxc.kazv 0.0 as MK
import org.kde.kirigami 2.13 as Kirigami
import '../../contents/ui' as Kazv
import 'test-helpers.js' as Helpers
-import 'test-helpers' as TestHelpers
+import 'test-helpers' as QmlHelpers
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
-
- property var mockHelper: TestHelpers.MockHelper {}
property var activateUserPage: mockHelper.noop()
property var paginateBackRequested: mockHelper.noop()
property var viewEventHistoryRequested: mockHelper.noop()
property var pinEventRequested: mockHelper.noop()
property var unpinEventRequested: mockHelper.noop()
property var deleteEventRequested: mockHelper.noop()
property var timeline: ({
gaps: [],
})
property var pinnedEvents: ({
count: 2,
eventIds: ['$123', '$456'],
})
property var room: ({
resendMessage: mockHelper.promise(),
removeLocalEcho: mockHelper.promise(),
ensureStateEvent: mockHelper.promise(),
messageById: (_id) => item.textEvent,
member: (_id) => ({}),
})
- property var l10n: Helpers.fluentMock
- property var matrixSdk: TestHelpers.MatrixSdkMock {
- property var userId: '@foo:tusooa.xyz'
- }
- property var sdkVars: QtObject {
- property var userGivenNicknameMap: QtObject {
- property var map: ({
- '@foo:tusooa.xyz': 'something',
- })
- }
- }
- property var kazvIOManager: TestHelpers.KazvIOManagerMock {}
+
property var localEcho: ({
eventId: '',
sender: '',
type: 'm.room.message',
stateKey: '',
content: {
msgtype: 'm.text',
body: 'some body',
},
encrypted: false,
isState: false,
unsignedData: {},
isLocalEcho: true,
isSending: true,
isFailed: false,
txnId: 'some-txn-id',
})
property var failedLocalEcho: Object.assign({}, item.localEcho, { isSending: false, isFailed: true, })
property var textEvent: ({
eventId: '',
sender: '@foo:tusooa.xyz',
type: 'm.room.message',
stateKey: '',
content: {
msgtype: 'm.text',
body: 'some body',
},
formattedTime: '4:06 P.M.',
})
property var htmlEvent: ({
eventId: '',
sender: '@foo:tusooa.xyz',
type: 'm.room.message',
stateKey: '',
content: {
msgtype: 'm.text',
body: '**some body**',
format: 'org.matrix.custom.html',
formatted_body: '<strong>some body</strong>',
},
formattedTime: '4:06 P.M.',
})
property var replyHtmlEvent: ({
eventId: '',
sender: '@foo:tusooa.xyz',
type: 'm.room.message',
stateKey: '',
replyingToEventId: '$xxx',
content: {
msgtype: 'm.text',
body: '> some quote\n**some body**',
format: 'org.matrix.custom.html',
formatted_body: '<mx-reply><blockquote>some quote</blockquote></mx-reply><strong>some body</strong>',
},
formattedTime: '4:06 P.M.',
})
property var replyNoQuoteHtmlEvent: ({
eventId: '',
sender: '@foo:tusooa.xyz',
type: 'm.room.message',
stateKey: '',
replyingToEventId: '$xxx',
content: {
msgtype: 'm.text',
body: '**some body**',
format: 'org.matrix.custom.html',
formatted_body: '<strong>some body</strong>',
},
formattedTime: '4:06 P.M.',
})
property var redactedEvent: ({
eventId: '',
sender: '@foo:tusooa.xyz',
type: 'm.room.message',
stateKey: '',
content: {},
redacted: true,
formattedTime: '4:06 P.M.',
})
property var imageEvent: ({
eventId: '',
sender: '@foo:tusooa.xyz',
type: 'm.room.message',
stateKey: '',
content: {
msgtype: 'm.image',
body: 'some body',
info: {
h: Kirigami.Units.gridUnit * 10,
w: Kirigami.Units.gridUnit * 10,
}
},
formattedTime: '4:06 P.M.',
})
property var stickerEvent: ({
eventId: '',
sender: '@foo:tusooa.xyz',
type: 'm.sticker',
stateKey: '',
content: {
body: 'some body',
},
formattedTime: '4:06 P.M.',
})
property var eventBySomeoneElse: ({
eventId: '',
sender: '@bar:tusooa.xyz',
type: 'm.room.message',
stateKey: '',
content: {
msgtype: 'm.image',
body: 'some body',
},
formattedTime: '4:06 P.M.',
})
property var eventTextBySomeoneElse: ({
eventId: '',
sender: '@bar:tusooa.xyz',
type: 'm.room.message',
stateKey: '',
content: {
msgtype: 'm.text',
body: 'some body',
},
formattedTime: '4:06 P.M.',
})
property var ignoredEvent: ({
eventId: '',
sender: '@foo:tusooa.xyz',
type: 'm.room.message',
relationType: 'm.replace',
stateKey: '',
content: {
msgtype: 'm.image',
body: 'some body',
},
formattedTime: '4:06 P.M.',
})
property var unknownTypeEvent: ({
eventId: '',
sender: '@foo:tusooa.xyz',
type: 'moe.kazv.mxc.unknown.event',
stateKey: '',
content: {
msgtype: 'm.image',
body: 'some body',
},
})
property var unknownMsgtypeEvent: ({
eventId: '',
sender: '@foo:tusooa.xyz',
type: 'm.room.message',
stateKey: '',
content: {
msgtype: 'moe.kazv.mxc.unknown.msgtype',
body: 'some body',
},
})
property var cannotDecryptEvent: ({
eventId: '',
sender: '@foo:tusooa.xyz',
type: 'm.room.message',
stateKey: '',
content: {
msgtype: 'moe.kazv.mxc.cannot.decrypt',
body: 'some body',
},
})
property var editedEvent: ({
eventId: '!some-event-id',
sender: '@foo:tusooa.xyz',
type: 'm.room.message',
stateKey: '',
content: {
msgtype: 'm.text',
body: 'some body',
},
formattedTime: '4:06 P.M.',
isEdited: true,
})
property var pinnedEvent: ({
eventId: '$123',
sender: '@foo:tusooa.xyz',
type: 'm.room.message',
content: {
msgtype: 'm.text',
body: 'some body',
},
formattedTime: '4:06 P.M.',
})
property var notPinnedEvent: ({
eventId: '$789',
sender: '@foo:tusooa.xyz',
type: 'm.room.message',
content: {
msgtype: 'm.text',
body: 'some body',
},
formattedTime: '4:06 P.M.',
})
property var sender: ({
membership: 'join',
userId: '@foo:tusooa.xyz',
name: 'foo',
avatarMxcUri: '',
})
property var senderOther: ({
membership: 'join',
userId: '@bar:tusooa.xyz',
name: 'bar',
avatarMxcUri: '',
})
property var eventViewComp: Component {
Kazv.EventView {
Layout.fillWidth: true
event: QtObject {
property var eventId: '$some-event-id'
function readers() { return 0; }
}
sender: item.sender
isGapped: true
}
}
property var eventComp: Component {
QtObject {
property var eventId: '$some-event-id'
function readers() { return 0; }
}
}
ColumnLayout {
anchors.fill: parent
Kazv.EventView {
Layout.fillWidth: true
id: eventView
event: item.localEcho
sender: item.sender
}
Kazv.EventView {
Layout.fillWidth: true
id: eventViewFailed
event: item.failedLocalEcho
sender: item.sender
property int index: 0
}
Kazv.EventView {
Layout.fillWidth: true
id: eventViewText
event: item.textEvent
sender: item.sender
}
Kazv.EventView {
Layout.fillWidth: true
id: eventViewHtml
event: item.htmlEvent
sender: item.sender
}
Kazv.EventView {
Layout.fillWidth: true
id: eventViewHtmlReply
event: item.replyHtmlEvent
sender: item.sender
}
Kazv.EventView {
Layout.fillWidth: true
id: eventViewHtmlReplyNoQuote
event: item.replyNoQuoteHtmlEvent
sender: item.sender
}
Kazv.EventView {
Layout.fillWidth: true
id: eventViewRedacted
event: item.redactedEvent
sender: item.sender
}
Kazv.EventView {
id: eventViewUnknownType
event: item.unknownTypeEvent
sender: item.sender
}
Kazv.EventView {
id: eventViewUnknownMsgtype
event: item.unknownMsgtypeEvent
sender: item.sender
}
Kazv.EventView {
id: eventViewCannotDecrypt
event: item.cannotDecryptEvent
sender: item.sender
}
Kazv.EventView {
id: eventViewCollapseSameSender
event: item.imageEvent
sender: item.sender
prevEvent: item.redactedEvent
}
Kazv.EventView {
id: eventViewCollapseLocalEcho
event: item.localEcho
sender: item.sender
prevEvent: item.redactedEvent
}
Kazv.EventView {
id: eventViewDontCollapseDifferentSender
event: item.imageEvent
sender: item.sender
prevEvent: item.eventBySomeoneElse
}
Kazv.EventView {
id: eventViewDontCollapseLocalEchoDifferentSender
event: item.localEcho
sender: item.sender
prevEvent: item.eventBySomeoneElse
}
Kazv.EventView {
id: eventViewDontCollapseIgnoredEvent
event: item.imageEvent
sender: item.sender
prevEvent: item.ignoredEvent
}
Kazv.EventView {
id: eventViewTextBySomeoneElse
event: item.eventTextBySomeoneElse
sender: item.senderOther
}
Kazv.EventView {
id: eventViewImage
event: item.imageEvent
sender: item.sender
}
Kazv.EventView {
id: eventViewImageCompact
compactMode: true
event: item.imageEvent
sender: item.sender
}
Kazv.EventView {
id: eventViewSticker
event: item.stickerEvent
sender: item.sender
}
Kazv.EventView {
id: eventViewStickerCompact
compactMode: true
event: item.stickerEvent
sender: item.sender
}
Kazv.EventView {
Layout.fillWidth: true
id: eventViewEdited
event: item.editedEvent
sender: item.sender
}
Kazv.EventView {
Layout.fillWidth: true
id: eventViewPinned
event: item.pinnedEvent
sender: item.sender
}
Kazv.EventView {
Layout.fillWidth: true
id: eventViewNotPinned
event: item.notPinnedEvent
sender: item.sender
}
}
TestCase {
id: eventViewTest
name: 'EventViewTest'
when: windowShown
function init() {
+ item.matrixSdk.userId = '@foo:tusooa.xyz';
eventView.event = item.localEcho;
mockHelper.clearAll();
}
function test_localEcho() {
const indicator = findChild(eventView, 'localEchoIndicator');
verify(indicator);
verify(indicator.icon.name === 'state-sync');
verify(indicator.Accessible.name === l10n.get('event-sending'));
const resendButton = findChild(eventView, 'localEchoIndicator');
verify(resendButton);
verify(!resendButton.enabled);
verify(!findChild(eventView, 'timeIndicator').visible);
}
function test_localEchoFailedRemove() {
const indicator = findChild(eventViewFailed, 'localEchoIndicator');
verify(indicator);
verify(indicator.visible);
verify(indicator.icon.name === 'state-warning');
verify(indicator.Accessible.name === l10n.get('event-resend'));
const menuComp = findChild(eventViewFailed, 'bubble').menuComp;
const menu = menuComp.createObject(menuComp.parent);
const deleteAction = findChild(menu, 'deleteMenuItem');
verify(deleteAction.enabled);
deleteAction.trigger();
compare(deleteEventRequested.calledTimes(), 1);
}
function test_sentMessage() {
const indicator = findChild(eventViewText, 'localEchoIndicator');
verify(indicator);
verify(!indicator.visible);
verify(findChild(eventViewText, 'timeIndicator').visible);
}
function test_htmlMessage() {
const text = findChild(eventViewHtml, 'eventViewMainItem');
verify(text.textFormat === TextEdit.RichText);
verify(text.text.includes('some body'));
}
function test_htmlMessageReply() {
const text = findChild(eventViewHtmlReply, 'eventViewMainItem');
verify(text.textFormat === TextEdit.RichText);
verify(!text.text.includes('<blockquote>'));
}
function test_htmlMessageReplyNoQuote() {
const text = findChild(eventViewHtmlReplyNoQuote, 'eventViewMainItem');
verify(text.textFormat === TextEdit.RichText);
verify(!text.text.includes('<blockquote>'));
verify(text.text.includes('some body'));
}
function test_menuText() {
const menuComp = findChild(eventViewText, 'bubble').menuComp;
const menu = menuComp.createObject(menuComp.parent);
verify(menu);
tryVerify(() => findChild(menu, 'replyToMenuItem').enabled);
tryVerify(() => findChild(menu, 'editMenuItem').enabled);
tryVerify(() => findChild(menu, 'deleteMenuItem').enabled);
}
function test_menuRedacted() {
const menuComp = findChild(eventViewRedacted, 'bubble').menuComp;
const menu = menuComp.createObject(menuComp.parent);
verify(menu);
tryVerify(() => !findChild(menu, 'replyToMenuItem').enabled);
tryVerify(() => !findChild(menu, 'deleteMenuItem').enabled);
}
function test_fallback() {
verify(findChild(eventViewUnknownType, 'fallbackIcon'));
verify(findChild(eventViewUnknownType, 'textEventContent').text ===
l10n.get('event-fallback-text', { type: unknownTypeEvent.type }));
verify(findChild(eventViewUnknownMsgtype, 'fallbackIcon'));
verify(findChild(eventViewUnknownMsgtype, 'textEventContent').text ===
l10n.get('event-msgtype-fallback-text', { msgtype: unknownMsgtypeEvent.content.msgtype }));
verify(findChild(eventViewCannotDecrypt, 'fallbackIcon'));
verify(findChild(eventViewCannotDecrypt, 'textEventContent').text ===
l10n.get('event-cannot-decrypt-text'));
}
function test_collapseSender() {
verify(!findChild(eventViewCollapseSameSender, 'senderAvatar').visible);
verify(findChild(eventViewCollapseSameSender, 'senderCollapsedPlaceholder').visible);
verify(!findChild(eventViewCollapseLocalEcho, 'senderAvatar').visible);
verify(findChild(eventViewCollapseLocalEcho, 'senderCollapsedPlaceholder').visible);
verify(findChild(eventViewDontCollapseDifferentSender, 'senderAvatar').visible);
verify(!findChild(eventViewDontCollapseDifferentSender, 'senderCollapsedPlaceholder').visible);
verify(findChild(eventViewDontCollapseLocalEchoDifferentSender, 'senderAvatar').visible);
verify(!findChild(eventViewDontCollapseLocalEchoDifferentSender, 'senderCollapsedPlaceholder').visible);
verify(findChild(eventViewDontCollapseIgnoredEvent, 'senderAvatar').visible);
verify(!findChild(eventViewDontCollapseIgnoredEvent, 'senderCollapsedPlaceholder').visible);
}
function test_eventByOther() {
const menuComp = findChild(eventViewTextBySomeoneElse, 'bubble').menuComp;
const menu = menuComp.createObject(menuComp.parent);
verify(menu);
tryVerify(() => !findChild(menu, 'editMenuItem').enabled);
}
function test_menuSelfDestruct() {
const menuComp = findChild(eventViewTextBySomeoneElse, 'bubble').menuComp;
const menu = menuComp.createObject(menuComp.parent);
verify(menu);
menu.popup(item);
menu.dismiss();
const menu2 = menuComp.createObject(menuComp.parent);
menu2.popup(item);
menu2.dismiss();
}
function test_userLink() {
const text = findChild(eventViewText, 'textEventContent');
text.linkActivated('https://matrix.to/#/@mew:example.com');
tryVerify(() => item.room.ensureStateEvent.calledTimes());
verify(Helpers.deepEqual(
item.room.ensureStateEvent.lastArgs(),
['m.room.member', '@mew:example.com']));
item.room.ensureStateEvent.lastRetVal().resolve(true, {});
tryVerify(() => item.activateUserPage.calledTimes());
}
function test_senderNameOverrided() {
const name = findChild(eventViewText, 'userNicknameText');
compare(name.text, l10n.get(
'user-name-overrided',
{ overridedName: 'something', globalName: 'foo' }));
}
function test_senderNameNotOverrided() {
const name = findChild(eventViewTextBySomeoneElse, 'userNicknameText');
compare(name.text, 'bar');
}
function test_paginateBack() {
const obj = item.eventViewComp.createObject(item);
tryVerify(() => item.paginateBackRequested.calledTimes());
verify(item.paginateBackRequested.lastArgs()[0] === '$some-event-id');
item.paginateBackRequested.clear();
obj.event.eventId = '$some-other-event-id';
tryVerify(() => item.paginateBackRequested.calledTimes() === 1);
verify(item.paginateBackRequested.lastArgs()[0] === '$some-other-event-id');
item.paginateBackRequested.clear();
const newEvent = eventComp.createObject(item);
obj.event = newEvent;
tryVerify(() => item.paginateBackRequested.calledTimes() === 1);
verify(item.paginateBackRequested.lastArgs()[0] === '$some-event-id');
item.paginateBackRequested.clear();
obj.isGapped = false;
verify(item.paginateBackRequested.calledTimes() === 0);
}
function test_avatarClick() {
const avatar = findChild(eventViewText, 'senderAvatar');
mouseClick(avatar);
tryVerify(() => item.activateUserPage.calledTimes() === 1);
// verify that the user id is passed
verify(item.activateUserPage.lastArgs()[2] === '@foo:tusooa.xyz');
}
function test_imageEvent() {
verify(!findChild(eventViewImage, 'summaryLabel').visible);
verify(findChild(eventViewImage, 'bodyLabel').visible);
verify(findChild(eventViewImageCompact, 'summaryLabel').visible);
verify(!findChild(eventViewImageCompact, 'bodyLabel').visible);
verify(!findChild(eventViewSticker, 'summaryLabel').visible);
verify(findChild(eventViewSticker, 'bodyLabel').visible);
verify(findChild(eventViewStickerCompact, 'summaryLabel').visible);
verify(!findChild(eventViewStickerCompact, 'bodyLabel').visible);
const image = findChild(eventViewImageCompact, 'mainImage');
verify(image.height <= Kirigami.Units.gridUnit * 5);
}
function test_history() {
{
const menuComp = findChild(eventViewText, 'bubble').menuComp;
const menu = menuComp.createObject(menuComp.parent);
const action = findChild(menu, 'viewHistoryMenuItem');
verify(!action.enabled);
}
{
const menuComp = findChild(eventViewEdited, 'bubble').menuComp;
const menu = menuComp.createObject(menuComp.parent);
const action = findChild(menu, 'viewHistoryMenuItem');
verify(action.enabled);
action.trigger();
compare(viewEventHistoryRequested.calledTimes(), 1);
compare(viewEventHistoryRequested.lastArgs()[0], '!some-event-id');
}
}
function test_pinned() {
{
const menuComp = findChild(eventViewPinned, 'bubble').menuComp;
const menu = menuComp.createObject(menuComp.parent);
const action = findChild(menu, 'pinUnpinMenuItem');
verify(action.enabled);
action.trigger();
compare(unpinEventRequested.calledTimes(), 1);
compare(unpinEventRequested.lastArgs()[0], '$123');
compare(pinEventRequested.calledTimes(), 0);
}
{
const menuComp = findChild(eventViewNotPinned, 'bubble').menuComp;
const menu = menuComp.createObject(menuComp.parent);
const action = findChild(menu, 'pinUnpinMenuItem');
verify(action.enabled);
action.trigger();
compare(pinEventRequested.calledTimes(), 1);
compare(pinEventRequested.lastArgs()[0], '$789');
compare(pinEventRequested.calledTimes(), 1);
}
{
const menuComp = findChild(eventView, 'bubble').menuComp;
const menu = menuComp.createObject(menuComp.parent);
const action = findChild(menu, 'pinUnpinMenuItem');
verify(!action.enabled);
}
}
}
}
diff --git a/src/tests/quick-tests/tst_EventViewRedacted.qml b/src/tests/quick-tests/tst_EventViewRedacted.qml
index 0ca6ba3..6cb2671 100644
--- a/src/tests/quick-tests/tst_EventViewRedacted.qml
+++ b/src/tests/quick-tests/tst_EventViewRedacted.qml
@@ -1,61 +1,58 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.3
import QtTest 1.0
import '../../contents/ui' as Kazv
-import 'test-helpers.js' as Helpers
+import 'test-helpers' as QmlHelpers
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
- property var l10n: Helpers.fluentMock
property var event: ({
eventId: '',
sender: '',
type: 'm.room.message',
stateKey: '',
content: {
},
redacted: true,
encrypted: false,
isState: false,
unsignedData: {},
isLocalEcho: false,
isSending: false,
isFailed: false,
txnId: 'some-txn-id',
})
property var sender: ({
membership: 'join',
userId: '@foo:tusooa.xyz',
name: 'foo',
avatarMxcUri: '',
})
Kazv.EventView {
id: eventView
event: item.event
sender: item.sender
}
TestCase {
id: eventViewRedactedTest
name: 'EventViewRedactedTest'
when: windowShown
function test_redacted() {
verify(eventView.getMessageType(event) === 'redacted');
const child = findChild(eventView, 'redactedEvent');
verify(child);
verify(child.text === l10n.get('event-deleted'));
}
}
}
diff --git a/src/tests/quick-tests/tst_EventViewVideo.qml b/src/tests/quick-tests/tst_EventViewVideo.qml
index 3312097..0245143 100644
--- a/src/tests/quick-tests/tst_EventViewVideo.qml
+++ b/src/tests/quick-tests/tst_EventViewVideo.qml
@@ -1,72 +1,68 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.3
import QtQuick.Layouts 1.15
import QtTest 1.0
import moe.kazv.mxc.kazv 0.0 as MK
import org.kde.kirigami 2.13 as Kirigami
import '../../contents/ui' as Kazv
-import 'test-helpers.js' as Helpers
-import 'test-helpers' as TestHelpers
+import 'test-helpers' as QmlHelpers
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
- property var mockHelper: TestHelpers.MockHelper {}
property var videoEvent: ({
eventId: '',
sender: '@foo:tusooa.xyz',
type: 'm.room.message',
stateKey: '',
content: {
msgtype: 'm.image',
body: 'some body',
info: {
h: Kirigami.Units.gridUnit * 10,
w: Kirigami.Units.gridUnit * 10,
}
},
formattedTime: '4:06 P.M.',
})
ColumnLayout {
anchors.fill: parent
Kazv.EventView {
id: eventViewVideo
event: item.videoEvent
sender: item.sender
}
Kazv.EventView {
id: eventViewVideoCompact
compactMode: true
event: item.videoEvent
sender: item.sender
}
}
TestCase {
id: eventViewVideoTest
name: 'EventViewVideoTest'
when: windowShown
function init() {
}
function test_videoEvent() {
verify(!findChild(eventViewVideo, 'summaryLabel').visible);
verify(findChild(eventViewVideo, 'bodyLabel').visible);
verify(findChild(eventViewVideoCompact, 'summaryLabel').visible);
verify(!findChild(eventViewVideoCompact, 'bodyLabel').visible);
const image = findChild(eventViewVideoCompact, 'mainImage');
verify(image.height <= Kirigami.Units.gridUnit * 5);
}
}
}
diff --git a/src/tests/quick-tests/tst_JoinRoomPage.qml b/src/tests/quick-tests/tst_JoinRoomPage.qml
index 61f1a00..db4831e 100644
--- a/src/tests/quick-tests/tst_JoinRoomPage.qml
+++ b/src/tests/quick-tests/tst_JoinRoomPage.qml
@@ -1,99 +1,86 @@
/*
* 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 'test-helpers.js' as JsHelpers
+import 'test-helpers' as QmlHelpers
import moe.kazv.mxc.kazv 0.0 as MK
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
-
- property var mockHelper: TestHelpers.MockHelper {}
- property var l10n: Helpers.fluentMock
- property var showPassiveNotification: () => {}
- property var matrixSdk: TestHelpers.MatrixSdkMock {
- property var joinRoom: mockHelper.promise()
- }
- property var sdkVars: ({})
- property var pageStack: ({
- removePage: mockHelper.noop(),
- })
Kazv.JoinRoomPage {
id: joinRoomPage
}
TestCase {
id: joinRoomPageTest
name: 'JoinRoomPageTest'
when: windowShown
function initTestCase() {
if (MK.KazvUtil.kfQtMajorVersion === 6) {
joinRoomPage.contentItem.clip = false;
}
}
function cleanup() {
mockHelper.clearAll();
}
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.joinRoom.calledTimes() === 1, 1000);
- verify(Helpers.deepEqual(item.matrixSdk.joinRoom.lastArgs(), [
+ verify(JsHelpers.deepEqual(item.matrixSdk.joinRoom.lastArgs(), [
'#foo:example.com',
['example.com', 'example.org'],
]));
item.matrixSdk.joinRoom.lastRetVal().resolve(true, {});
tryVerify(() => item.pageStack.removePage.calledTimes() === 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.joinRoom.calledTimes() === 1, 1000);
- verify(Helpers.deepEqual(item.matrixSdk.joinRoom.lastArgs(), [
+ verify(JsHelpers.deepEqual(item.matrixSdk.joinRoom.lastArgs(), [
'#foo:example.com',
[],
]));
item.matrixSdk.joinRoom.lastRetVal().resolve(true, {});
tryVerify(() => item.pageStack.removePage.calledTimes() === 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.joinRoom.calledTimes() === 1, 1000);
item.matrixSdk.joinRoom.lastRetVal().resolve(false, {});
tryVerify(() => item.pageStack.removePage.calledTimes() === 0);
}
}
}
diff --git a/src/tests/quick-tests/tst_KazvIOMenu.qml b/src/tests/quick-tests/tst_KazvIOMenu.qml
index c874173..3db9543 100644
--- a/src/tests/quick-tests/tst_KazvIOMenu.qml
+++ b/src/tests/quick-tests/tst_KazvIOMenu.qml
@@ -1,243 +1,235 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2024 nannanko <nannanko@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick
import QtTest
import '../../contents/ui' as Kazv
-import 'test-helpers' as TestHelpers
-import 'test-helpers.js' as Helpers
+import 'test-helpers' as QmlHelpers
+import 'test-helpers.js' as JsHelpers
import moe.kazv.mxc.kazv 0.0 as MK
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
- property var mockHelper: TestHelpers.MockHelper {}
- property var kazvIOManager: QtObject {
- property var deleteDownloadJob: mockHelper.noop()
- property var deleteUploadJob: mockHelper.noop()
- }
property var kazvIOJob: QtObject {
function isResulted() { return false; }
function isSuspended() { return false; }
function fileName() { return 'some-file-name'; }
property var suspend: mockHelper.noop()
property var cancel: mockHelper.noop()
property var progress: 0.0
signal result(int ec)
}
property var suspendedJob: QtObject {
function isResulted() { return false; }
function isSuspended() { return true; }
property var resume: mockHelper.noop()
}
property var resultedJob: QtObject {
function isResulted() { return true; }
function isSuspended() { return false; }
function error() { return MK.KazvIOBaseJob.NoError; }
}
- property var l10n: Helpers.fluentMock
Kazv.KazvIOMenu {
id: progressBar
kazvIOJob: null
jobId: 'some-job-id'
isUpload: false
}
TestCase {
id: kazvIOMenuTest
name: 'KazvIOMenuTest'
when: windowShown
function init() {
progressBar.kazvIOJob = null;
progressBar.isUpload = false;
}
function test_progress() {
progressBar.kazvIOJob = kazvIOJob;
const progress = findChild(progressBar, 'progressBar');
const progressText = findChild(progressBar, 'progressText');
compare(progress.value, kazvIOJob.progress);
compare(progressText.text, l10n.get("kazv-io-progress", {
progress: Math.floor(kazvIOJob.progress * 100)}));
kazvIOJob.progress = Math.random();
compare(progress.value, kazvIOJob.progress);
compare(progressText.text, l10n.get("kazv-io-progress", {
progress: Math.floor(kazvIOJob.progress * 100)}));
}
function test_progressBarNullJob() {
progressBar.kazvIOJob = null;
verify(!progressBar.visible);
}
function test_progressBarDownload() {
progressBar.kazvIOJob = kazvIOJob;
progressBar.isUpload = false;
verify(progressBar.visible);
const prompt = findChild(progressBar, 'fileNamePrompt');
const progressLayout = findChild(progressBar, 'progressLayout');
const resultLayout = findChild(progressBar, 'resultLayout');
verify(prompt.visible);
verify(progressLayout.visible);
verify(!resultLayout.visible);
compare(prompt.text, l10n.get('kazv-io-downloading-prompt', {
fileName: kazvIOJob.fileName()}));
}
function test_progressBarUpload() {
progressBar.kazvIOJob = kazvIOJob;
progressBar.isUpload = true;
const prompt = findChild(progressBar, 'fileNamePrompt');
compare(prompt.text, l10n.get('kazv-io-uploading-prompt', {
fileName: kazvIOJob.fileName()}));
}
function test_resume() {
progressBar.kazvIOJob = kazvIOJob;
const pauseBtn = findChild(progressBar, 'pauseBtn');
compare(pauseBtn.icon.name, 'media-playback-pause');
mouseClick(pauseBtn);
compare(kazvIOJob.suspend.calledTimes(), 1);
}
function test_pause() {
progressBar.kazvIOJob = suspendedJob;
const pauseBtn = findChild(progressBar, 'pauseBtn');
compare(pauseBtn.icon.name, 'media-playback-start');
mouseClick(pauseBtn);
compare(suspendedJob.resume.calledTimes(), 1);
}
function test_cancel() {
progressBar.kazvIOJob = kazvIOJob;
const cancelBtn = findChild(progressBar, 'cancelBtn');
mouseClick(cancelBtn);
compare(kazvIOJob.cancel.calledTimes(), 1);
}
function test_resulted() {
progressBar.kazvIOJob = resultedJob;
const progressLayout = findChild(progressBar, 'progressLayout');
const resultLayout = findChild(progressBar, 'resultLayout');
verify(!progressLayout.visible);
verify(resultLayout.visible);
}
/**
* ProgressBar is destroyed automatically after a successful upload,
* so there is no need to test
*/
function test_resultSuccDownload() {
progressBar.kazvIOJob = kazvIOJob;
progressBar.isUpload = false;
const progressLayout = findChild(progressBar, 'progressLayout');
const resultLayout = findChild(progressBar, 'resultLayout');
const resultMsg = findChild(progressBar, 'resultMsg');
kazvIOJob.result(MK.KazvIOBaseJob.NoError);
verify(!progressLayout.visible);
verify(resultLayout.visible);
compare(resultMsg.text, l10n.get('kazv-io-download-success-prompt'));
}
function test_resultFailDownload() {
progressBar.kazvIOJob = kazvIOJob;
progressBar.isUpload = false;
const progressLayout = findChild(progressBar, 'progressLayout');
const resultLayout = findChild(progressBar, 'resultLayout');
const resultMsg = findChild(progressBar, 'resultMsg');
kazvIOJob.result(MK.KazvIOBaseJob.UserCancel);
verify(!progressLayout.visible);
verify(resultLayout.visible);
const failPromptL10nId = 'kazv-io-download-failure-prompt';
compare(resultMsg.text, l10n.get(failPromptL10nId, {
detail: l10n.get('kazv-io-failure-detail-user-cancel')}));
kazvIOJob.result(MK.KazvIOBaseJob.OpenFileError);
compare(resultMsg.text, l10n.get(failPromptL10nId, {
detail: l10n.get('kazv-io-failure-detail-open-file-error')}));
kazvIOJob.result(MK.KazvIOBaseJob.WriteFileError);
compare(resultMsg.text, l10n.get(failPromptL10nId, {
detail: l10n.get('kazv-io-failure-detail-write-file-error')}));
kazvIOJob.result(MK.KazvIOBaseJob.KIOError);
compare(resultMsg.text, l10n.get(failPromptL10nId, {
detail: l10n.get('kazv-io-failure-detail-network-error')}));
kazvIOJob.result(MK.KazvIOBaseJob.HashError);
compare(resultMsg.text, l10n.get(failPromptL10nId, {
detail: l10n.get('kazv-io-failure-detail-hash-error')}));
kazvIOJob.result(MK.KazvIOBaseJob.ResponseError);
compare(resultMsg.text, l10n.get(failPromptL10nId, {
detail: l10n.get('kazv-io-failure-detail-response-error')}));
kazvIOJob.result(MK.KazvIOBaseJob.KazvError);
compare(resultMsg.text, l10n.get(failPromptL10nId, {
detail: l10n.get('kazv-io-failure-detail-kazv-error')}));
}
function test_resultFailUpload() {
progressBar.kazvIOJob = kazvIOJob;
progressBar.isUpload = true;
const progressLayout = findChild(progressBar, 'progressLayout');
const resultLayout = findChild(progressBar, 'resultLayout');
const resultMsg = findChild(progressBar, 'resultMsg');
kazvIOJob.result(MK.KazvIOBaseJob.UserCancel);
verify(!progressLayout.visible);
verify(resultLayout.visible);
const failPromptL10nId = 'kazv-io-upload-failure-prompt';
compare(resultMsg.text, l10n.get(failPromptL10nId, {
detail: l10n.get('kazv-io-failure-detail-user-cancel')}));
kazvIOJob.result(MK.KazvIOBaseJob.OpenFileError);
compare(resultMsg.text, l10n.get(failPromptL10nId, {
detail: l10n.get('kazv-io-failure-detail-open-file-error')}));
kazvIOJob.result(MK.KazvIOBaseJob.WriteFileError);
compare(resultMsg.text, l10n.get(failPromptL10nId, {
detail: l10n.get('kazv-io-failure-detail-write-file-error')}));
kazvIOJob.result(MK.KazvIOBaseJob.KIOError);
compare(resultMsg.text, l10n.get(failPromptL10nId, {
detail: l10n.get('kazv-io-failure-detail-network-error')}));
kazvIOJob.result(MK.KazvIOBaseJob.HashError);
compare(resultMsg.text, l10n.get(failPromptL10nId, {
detail: l10n.get('kazv-io-failure-detail-hash-error')}));
kazvIOJob.result(MK.KazvIOBaseJob.ResponseError);
compare(resultMsg.text, l10n.get(failPromptL10nId, {
detail: l10n.get('kazv-io-failure-detail-response-error')}));
kazvIOJob.result(MK.KazvIOBaseJob.KazvError);
compare(resultMsg.text, l10n.get(failPromptL10nId, {
detail: l10n.get('kazv-io-failure-detail-kazv-error')}));
}
function test_closeDownload() {
progressBar.kazvIOJob = kazvIOJob;
progressBar.isUpload = false;
const progressLayout = findChild(progressBar, 'progressLayout');
const resultLayout = findChild(progressBar, 'resultLayout');
const closeBtn = findChild(progressBar, 'closeBtn')
kazvIOJob.result(MK.KazvIOBaseJob.NoError);
verify(!progressLayout.visible);
verify(resultLayout.visible);
mouseClick(closeBtn);
compare(kazvIOManager.deleteDownloadJob.calledTimes(), 1);
}
function test_closeUpload() {
progressBar.kazvIOJob = kazvIOJob;
progressBar.isUpload = true;
const progressLayout = findChild(progressBar, 'progressLayout');
const resultLayout = findChild(progressBar, 'resultLayout');
const closeBtn = findChild(progressBar, 'closeBtn')
kazvIOJob.result(MK.KazvIOBaseJob.NoError);
verify(!progressLayout.visible);
verify(resultLayout.visible);
mouseClick(closeBtn);
compare(kazvIOManager.deleteUploadJob.calledTimes(), 1);
}
}
}
diff --git a/src/tests/quick-tests/tst_Notifications.qml b/src/tests/quick-tests/tst_Notifications.qml
index ee4fff3..e7a209e 100644
--- a/src/tests/quick-tests/tst_Notifications.qml
+++ b/src/tests/quick-tests/tst_Notifications.qml
@@ -1,47 +1,45 @@
/*
* 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
TestCase {
id: notificationsTest
name: 'NotificationsTest'
when: true
signal switchToRoomRequested(string roomId)
SignalSpy {
id: switchToRoomSpy
}
Kazv.MessageNotification {
id: notification
roomId: '!foo:example.com'
}
function init() {
switchToRoomSpy.clear();
switchToRoomSpy.target = notificationsTest;
switchToRoomSpy.signalName = 'switchToRoomRequested';
}
function test_messageNotification() {
if (MK.KazvUtil.kfQtMajorVersion === 5) {
notification.defaultActivated();
} else {
notification.defaultAction.activated();
}
tryCompare(switchToRoomSpy, 'count', 1);
compare(switchToRoomSpy.signalArguments[0][0], '!foo:example.com');
}
}
diff --git a/src/tests/quick-tests/tst_PageManager.qml b/src/tests/quick-tests/tst_PageManager.qml
index 8373718..99df529 100644
--- a/src/tests/quick-tests/tst_PageManager.qml
+++ b/src/tests/quick-tests/tst_PageManager.qml
@@ -1,77 +1,75 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.3
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 'test-helpers.js' as JsHelpers
+import 'test-helpers' as QmlHelpers
import moe.kazv.mxc.kazv 0.0 as MK
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
property string testRoomId: '!roomtest:example.org'
property var pageStack: QtObject {
property var currentIndex: 0
function get(index) {
const roomPageComp = Qt.createComponent(Qt.resolvedUrl("../../contents/ui/RoomPage.qml"))
return roomPageComp.createObject(item, { roomId: testRoomId })
}
function goBack() {
--currentIndex;
}
function goForward() {
++currentIndex;
}
signal push(var url, var args)
}
SignalSpy {
id: pushSignalSpy
}
Kazv.PageManager {
id: pageManager
sdkVars: QtObject {
property string currentRoomId: testRoomId
}
pageStack: item.pageStack
main: QtObject {
signal switchToRoomRequested(string roomId)
}
}
TestCase {
id: pageManagerTest
name: 'PageManagerTest'
function init() {
pushSignalSpy.clear();
pushSignalSpy.target = pageStack;
pushSignalSpy.signalName = 'push';
pageStack.currentIndex = 0;
}
function test_returnToRoom() {
pageManager.main.switchToRoomRequested(testRoomId);
compare(pageStack.currentIndex, 1);
compare(pushSignalSpy.count, 0);
}
function test_switchToOtherRoom() {
compare(pushSignalSpy.count, 0);
pageManager.main.switchToRoomRequested('!otherroom:example.org');
tryCompare(pushSignalSpy, 'count', 1);
- verify(Helpers.deepEqual(pushSignalSpy.signalArguments[0][1], { roomId: '!otherroom:example.org' }));
+ verify(JsHelpers.deepEqual(pushSignalSpy.signalArguments[0][1], { roomId: '!otherroom:example.org' }));
}
}
}
diff --git a/src/tests/quick-tests/tst_ReactToEventPopup.qml b/src/tests/quick-tests/tst_ReactToEventPopup.qml
index dc19e3f..bf8a798 100644
--- a/src/tests/quick-tests/tst_ReactToEventPopup.qml
+++ b/src/tests/quick-tests/tst_ReactToEventPopup.qml
@@ -1,31 +1,30 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2024 April Simone <apr3vau@outlook.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick
import QtTest
import '../../contents/ui' as Kazv
+import 'test-helpers' as QmlHelpers
-Item {
- width: 800
- height: 600
+QmlHelpers.TestItem {
Kazv.ReactToEventPopup {
id: popup
}
TestCase {
id: reactToEventPopupTest
name: 'ReactToEventPopupTest'
when: windowShown
function test_react() {
skip("Skipped as it requires further change.");
popup.open();
const grid = findChild(popup, 'emojiGrid');
waitForRendering(grid);
mouseClick(grid.currentItem);
tryVerify(() => findChild(popup, 'reactionTextInput').text === grid.currentItem.str);
}
}
}
diff --git a/src/tests/quick-tests/tst_RoomInvitePage.qml b/src/tests/quick-tests/tst_RoomInvitePage.qml
index 15ae27a..d592cfa 100644
--- a/src/tests/quick-tests/tst_RoomInvitePage.qml
+++ b/src/tests/quick-tests/tst_RoomInvitePage.qml
@@ -1,85 +1,73 @@
/*
* 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/room-settings' as RoomSettings
-import 'test-helpers.js' as Helpers
-import 'test-helpers' as TestHelpers
+import 'test-helpers' as QmlHelpers
import moe.kazv.mxc.kazv 0.0 as MK
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
-
- property var mockHelper: TestHelpers.MockHelper {}
- property var showPassiveNotification: mockHelper.noop()
- property var pageStack: ({
- removePage: mockHelper.noop(),
- })
property var room: ({
name: 'room',
inviteUser: mockHelper.promise(),
})
- property var l10n: Helpers.fluentMock
- property var matrixSdk: TestHelpers.MatrixSdkMock {}
- property var sdkVars: ({})
RoomSettings.RoomInvitePage {
id: roomInvitePage
room: item.room
}
TestCase {
id: roomInvitePageTest
name: 'RoomInvitePageTest'
when: windowShown
function initTestCase() {
if (MK.KazvUtil.kfQtMajorVersion === 6) {
roomInvitePage.contentItem.clip = false;
}
}
function cleanup() {
mockHelper.clearAll();
}
function test_roomInvitePage() {
const input = findChild(roomInvitePage, 'inviteUserIdInput');
input.text = '@mew:example.com';
const button = findChild(roomInvitePage, 'inviteUserButton');
mouseClick(button);
tryVerify(() => item.room.inviteUser.calledTimes(), 1000);
verify(item.room.inviteUser);
verify(item.room.inviteUser.lastArgs()[0] == '@mew:example.com');
verify(!button.enabled);
const promise = item.room.inviteUser.lastRetVal();
promise.resolve(true, {});
tryVerify(() => button.enabled, 1000);
tryVerify(() => item.pageStack.removePage.calledTimes(), 1000);
}
function test_roomInvitePageFailed() {
const input = findChild(roomInvitePage, 'inviteUserIdInput');
input.text = '@mew:example.com';
const button = findChild(roomInvitePage, 'inviteUserButton');
mouseClick(button);
tryVerify(() => item.room.inviteUser.calledTimes(), 1000);
const promise = item.room.inviteUser.lastRetVal();
verify(promise);
promise.resolve(false, {});
tryVerify(() => button.enabled, 1000);
verify(!item.pageStack.removePage.calledTimes());
}
}
}
diff --git a/src/tests/quick-tests/tst_RoomListViewItemDelegate.qml b/src/tests/quick-tests/tst_RoomListViewItemDelegate.qml
index 53e397e..d2a0160 100644
--- a/src/tests/quick-tests/tst_RoomListViewItemDelegate.qml
+++ b/src/tests/quick-tests/tst_RoomListViewItemDelegate.qml
@@ -1,294 +1,288 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.3
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 'test-helpers.js' as JsHelpers
+import 'test-helpers' as QmlHelpers
import moe.kazv.mxc.kazv 0.0 as MK
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
- property var roomInvite: Helpers.factory.room({
+ property var roomInvite: JsHelpers.factory.room({
membership: MK.MatrixRoom.Invite,
unreadNotificationCount: 0,
})
- property var roomJoin: Helpers.factory.room({
+ property var roomJoin: JsHelpers.factory.room({
membership: MK.MatrixRoom.Join,
unreadNotificationCount: 0,
})
- property var roomLeave: Helpers.factory.room({
+ property var roomLeave: JsHelpers.factory.room({
membership: MK.MatrixRoom.Leave,
unreadNotificationCount: 0,
})
- property var roomWithUnreadNotificationCount: Helpers.factory.room({
+ property var roomWithUnreadNotificationCount: JsHelpers.factory.room({
membership: MK.MatrixRoom.Join,
unreadNotificationCount: 2,
})
property var timelineUnread: QtObject {
property var count: 5
function at(i) {
if (i < 2) {
return {
isLocalEcho: true,
readers: () => ({ count: 0 }),
};
}
if (i < 3) {
return {
isLocalEcho: false,
sender: '@bar:example.org',
eventId: `$event${i}`,
readers: () => ({ count: 0 }),
};
}
return {
isLocalEcho: false,
sender: '@foo:example.org',
eventId: `$event${i}`,
readers: () => ({ count: 0 }),
};
}
}
property var timelineLastSentIsMine: QtObject {
property var count: 5
function at(i) {
if (i < 2) {
return {
isLocalEcho: true,
readers: () => ({ count: 0 }),
};
}
if (i < 3) {
return {
isLocalEcho: false,
sender: '@foo:example.org',
eventId: `$event${i}`,
readers: () => ({ count: 0 }),
};
}
return {
isLocalEcho: false,
sender: '@bar:example.org',
eventId: `$event${i}`,
readers: () => ({ count: 0 }),
};
}
}
property var timelineRead: QtObject {
property var count: 5
function at(i) {
if (i < 2) {
return {
isLocalEcho: true,
readers: () => ({ count: 0 }),
};
}
if (i < 3) {
return {
isLocalEcho: false,
sender: '@bar:example.org',
eventId: `$event${i}`,
readers: () => ({
count: 1,
at() {
return { userId: '@foo:example.org' };
},
}),
};
}
return {
isLocalEcho: false,
sender: '@foo:example.org',
eventId: `$event${i}`,
readers: () => ({ count: 0 }),
};
}
}
- property var l10n: Helpers.fluentMock
- property var matrixSdk: TestHelpers.MatrixSdkMock {
- property var userId: '@foo:example.org'
- }
- property var sdkVars: QtObject {
- property var userGivenNicknameMap: QtObject {
- property var map: ({
- '@foo:example.com': 'something',
- })
- }
- }
property string testRoomId: 'room-test'
signal switchToRoomRequested(string roomId)
SignalSpy {
id: switchToRoomSpy
target: item
signalName: 'switchToRoomRequested'
}
ColumnLayout {
anchors.fill: parent
Kazv.RoomListViewItemDelegate {
id: delegateInvite
item: roomInvite
}
Kazv.RoomListViewItemDelegate {
id: delegateJoin
item: roomJoin
}
Kazv.RoomListViewItemDelegate {
id: delegateLeave
item: roomLeave
}
Kazv.RoomListViewItemDelegate {
id: delegateRoom
- item: Helpers.factory.room({
+ item: JsHelpers.factory.room({
roomId: testRoomId
})
}
Kazv.RoomListViewItemDelegate {
id: delegateRoomWithName
item: QtObject {
property var roomId: testRoomId
property var name: 'some name'
}
}
Kazv.RoomListViewItemDelegate {
id: delegateRoomWithHeroes
item: QtObject {
property var roomId: testRoomId
property var heroEvents: [{
type: 'm.room.member',
state_key: '@foo:example.com',
content: {
displayname: 'foo',
},
}, {
type: 'm.room.member',
state_key: '@bar:example.com',
content: {
displayname: 'bar',
},
}]
}
}
Kazv.RoomListViewItemDelegate {
id: delegateUnread
item: Object.assign({}, roomJoin, {
timeline () {
return timelineUnread;
},
})
}
Kazv.RoomListViewItemDelegate {
id: delegateWithUnreadNotifications
item: Object.assign({}, roomWithUnreadNotificationCount, {
timeline () {
return timelineUnread;
},
})
}
}
TestCase {
id: roomListViewItemDelegateTest
name: 'RoomListViewItemDelegateTest'
when: windowShown
+ function initTestCase() {
+ item.matrixSdk.userId = '@foo:example.org';
+ item.sdkVars.userGivenNicknameMap.map = {
+ '@foo:example.com': 'something',
+ };
+ }
+
function test_inviteIndicator() {
const indicator = findChild(delegateInvite, 'inviteIndicator');
verify(indicator);
verify(indicator.visible);
const leaveIndicator = findChild(delegateInvite, 'leaveIndicator');
verify(leaveIndicator);
verify(!leaveIndicator.visible);
}
function test_inviteIndicatorJoin() {
const indicator = findChild(delegateJoin, 'inviteIndicator');
verify(indicator);
verify(!indicator.visible);
const leaveIndicator = findChild(delegateJoin, 'leaveIndicator');
verify(leaveIndicator);
verify(!leaveIndicator.visible);
}
function test_inviteIndicatorLeave() {
const indicator = findChild(delegateLeave, 'inviteIndicator');
verify(indicator);
verify(!indicator.visible);
const leaveIndicator = findChild(delegateLeave, 'leaveIndicator');
verify(leaveIndicator);
verify(leaveIndicator.visible);
}
function test_lastUnreadMessage() {
compare(delegateJoin.getLastUnreadMessage(timelineUnread, timelineUnread.count).eventId, '$event2');
compare(delegateJoin.getLastUnreadMessage(timelineLastSentIsMine, timelineLastSentIsMine.count), undefined);
compare(delegateJoin.getLastUnreadMessage(timelineRead, timelineRead.count), undefined);
}
function test_returnRoom() {
compare(switchToRoomSpy.count, 0);
mouseClick(delegateRoom);
tryCompare(switchToRoomSpy, 'count', 1);
- verify(Helpers.deepEqual(switchToRoomSpy.signalArguments[0], [testRoomId]));
+ verify(JsHelpers.deepEqual(switchToRoomSpy.signalArguments[0], [testRoomId]));
}
function test_roomName() {
compare(
findChild(delegateRoomWithName, 'roomDisplayNameLabel').text,
l10n.get('room-list-view-room-item-title-name', { name: 'some name' }));
compare(
findChild(delegateRoomWithHeroes, 'roomDisplayNameLabel').text,
l10n.get('room-list-view-room-item-title-heroes', {
hero: l10n.get(
'user-name-overrided',
{ overridedName: 'something', globalName: 'foo' }),
secondHero: 'bar',
otherNum: 1,
}));
}
function test_unreadIndicators() {
verify(!findChild(delegateWithUnreadNotifications, 'unreadIndicator').visible);
verify(findChild(delegateWithUnreadNotifications, 'unreadNotificationCount').visible);
verify(findChild(delegateUnread, 'unreadIndicator').visible);
verify(!findChild(delegateUnread, 'unreadNotificationCount').visible);
}
}
}
diff --git a/src/tests/quick-tests/tst_RoomMemberListPage.qml b/src/tests/quick-tests/tst_RoomMemberListPage.qml
index 57442ca..4bffa01 100644
--- a/src/tests/quick-tests/tst_RoomMemberListPage.qml
+++ b/src/tests/quick-tests/tst_RoomMemberListPage.qml
@@ -1,52 +1,42 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2023-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 '../../contents/ui/room-settings' as RS
-import 'test-helpers.js' as Helpers
-import 'test-helpers' as TestHelpers
+import 'test-helpers' as QmlHelpers
import moe.kazv.mxc.kazv 0.0 as MK
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
- property var mockHelper: TestHelpers.MockHelper {}
property var room: QtObject {
property var refreshState: mockHelper.promise()
}
- property var l10n: Helpers.fluentMock
- property var matrixSdk: TestHelpers.MatrixSdkMock {
- property var userId: '@foo:example.org'
- }
- property var sdkVars: ({})
-
property var pageComp: Component {
RS.RoomMemberListPage {
}
}
TestCase {
id: roomMemberListPageTest
name: 'RoomMemberListPageTest'
when: windowShown
function init() {
mockHelper.clearAll();
}
function test_loadState() {
const page = pageComp.createObject(item, { room, members: 0 });
tryVerify(() => room.refreshState.calledTimes());
}
}
}
diff --git a/src/tests/quick-tests/tst_RoomNameProvider.qml b/src/tests/quick-tests/tst_RoomNameProvider.qml
index b9060d0..14bb075 100644
--- a/src/tests/quick-tests/tst_RoomNameProvider.qml
+++ b/src/tests/quick-tests/tst_RoomNameProvider.qml
@@ -1,164 +1,164 @@
/*
* 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
+import './test-helpers' as QmlHelpers
+import 'test-helpers.js' as JsHelpers
TestCase {
id: roomNameProviderTest
name: 'RoomNameProviderTest'
when: true
property var sdkVars: QtObject {
property var userGivenNicknameMap: QtObject {
property var map: ({})
}
}
- property var l10n: Helpers.fluentMock
+ property var l10n: JsHelpers.fluentMock
property var providerFunctional: Kazv.RoomNameProvider {}
property var providerReactive: Kazv.RoomNameProvider {}
property var roomComp: Component {
QtObject {
property var name
property var heroEvents
property var roomId
}
}
property var heroEvents: [{
type: 'm.room.member',
state_key: '@foo:example.com',
content: {
displayname: 'foo',
},
}, {
type: 'm.room.member',
state_key: '@bar:example.com',
content: {
displayname: 'bar',
},
}]
function init() {
sdkVars.userGivenNicknameMap.map = {
'@foo:example.com': 'something',
};
}
function test_functional() {
compare(
providerFunctional.getName({ name: 'some name' }),
l10n.get(
'room-list-view-room-item-title-name',
{ name: 'some name' }));
compare(providerFunctional.getName({
heroEvents
}), l10n.get('room-list-view-room-item-title-heroes', {
hero: l10n.get(
'user-name-overrided',
{ overridedName: 'something', globalName: 'foo' }),
secondHero: 'bar',
otherNum: 1,
}));
compare(
providerFunctional.getName({ roomId: '!room:example.com' }),
l10n.get(
'room-list-view-room-item-title-id',
{ roomId: '!room:example.com' }));
}
function test_reactiveAgainstRoom() {
providerReactive.room = roomComp.createObject(roomNameProviderTest, {
name: 'some name',
heroEvents,
roomId: '!room:example.com',
});
compare(
providerReactive.name,
l10n.get(
'room-list-view-room-item-title-name',
{ name: 'some name' }));
providerReactive.room.name = 'other name';
compare(
providerReactive.name,
l10n.get(
'room-list-view-room-item-title-name',
{ name: 'other name' }));
providerReactive.room.name = undefined;
compare(
providerReactive.name,
l10n.get('room-list-view-room-item-title-heroes', {
hero: l10n.get(
'user-name-overrided',
{ overridedName: 'something', globalName: 'foo' }),
secondHero: 'bar',
otherNum: 1,
}));
providerReactive.room.heroEvents = [heroEvents[0]];
compare(
providerReactive.name,
l10n.get('room-list-view-room-item-title-heroes', {
hero: l10n.get(
'user-name-overrided',
{ overridedName: 'something', globalName: 'foo' }),
secondHero: undefined,
otherNum: 0,
}));
providerReactive.room.heroEvents = [];
compare(
providerReactive.name,
l10n.get('room-list-view-room-item-title-id', {
roomId: '!room:example.com',
}));
providerReactive.room = roomComp.createObject(roomNameProviderTest, {
name: 'some name 2',
heroEvents,
roomId: '!room:example.com',
});
compare(
providerReactive.name,
l10n.get(
'room-list-view-room-item-title-name',
{ name: 'some name 2' }));
}
function test_reactiveAgainstOverrides() {
providerReactive.room = roomComp.createObject(roomNameProviderTest, {
heroEvents,
roomId: '!room:example.com',
});
compare(
providerReactive.name,
l10n.get('room-list-view-room-item-title-heroes', {
hero: l10n.get(
'user-name-overrided',
{ overridedName: 'something', globalName: 'foo' }),
secondHero: 'bar',
otherNum: 1,
}));
sdkVars.userGivenNicknameMap.map = {
};
compare(
providerReactive.name,
l10n.get('room-list-view-room-item-title-heroes', {
hero: 'foo',
secondHero: 'bar',
otherNum: 1,
}));
}
}
diff --git a/src/tests/quick-tests/tst_RoomPage.qml b/src/tests/quick-tests/tst_RoomPage.qml
index 6c9b4e6..4d2f940 100644
--- a/src/tests/quick-tests/tst_RoomPage.qml
+++ b/src/tests/quick-tests/tst_RoomPage.qml
@@ -1,155 +1,147 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.3
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 'test-helpers.js' as JsHelpers
+import 'test-helpers' as QmlHelpers
import moe.kazv.mxc.kazv 0.0 as MK
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
- property var mockHelper: TestHelpers.MockHelper {}
property var roomTimeline: QtObject {
property var count: 5
function at(i) {
if (i < 2) {
return {
isLocalEcho: true,
};
}
if (i < 3) {
return {
isLocalEcho: false,
sender: '@foo:example.org',
eventId: `$event${i}`,
};
}
return {
isLocalEcho: false,
sender: '@bar:example.org',
eventId: `$event${i}`,
};
}
}
- property var roomInvite: Helpers.factory.room({
+ property var roomInvite: JsHelpers.factory.room({
membership: MK.MatrixRoom.Invite,
})
- property var roomJoin: Helpers.factory.room({
+ property var roomJoin: JsHelpers.factory.room({
membership: MK.MatrixRoom.Join,
paginateBackFrom: mockHelper.promise(),
pinnedEventsTimeline: () => ({
count: 0,
}),
})
- property var roomLeave: Helpers.factory.room({
+ property var roomLeave: JsHelpers.factory.room({
membership: MK.MatrixRoom.Leave,
})
- property var roomWithPinned: Helpers.factory.room({
+ property var roomWithPinned: JsHelpers.factory.room({
membership: MK.MatrixRoom.Join,
paginateBackFrom: mockHelper.promise(),
pinnedEventsTimeline: () => ({
count: 1,
}),
})
- property var l10n: Helpers.fluentMock
- property var matrixSdk: TestHelpers.MatrixSdkMock {
- property var userId: '@foo:example.org'
- }
- property var sdkVars: ({})
-
ColumnLayout {
Kazv.RoomPage {
id: pageInvite
room: roomInvite
}
Kazv.RoomPage {
id: pageJoin
room: roomJoin
}
Kazv.RoomPage {
id: pageLeave
room: roomLeave
}
Kazv.RoomPage {
id: pageWithPinned
room: roomWithPinned
}
}
TestCase {
id: roomPageTest
name: 'RoomPageTest'
when: windowShown
function init() {
+ matrixSdk.userId = '@foo:example.org';
mockHelper.clearAll();
}
function test_inviteRoom() {
const sendMessageBox = findChild(pageInvite, 'sendMessageBox');
verify(sendMessageBox);
verify(!sendMessageBox.enabled);
}
function test_joinRoom() {
const sendMessageBox = findChild(pageJoin, 'sendMessageBox');
verify(sendMessageBox);
verify(sendMessageBox.enabled);
}
function test_leaveRoom() {
const sendMessageBox = findChild(pageLeave, 'sendMessageBox');
verify(sendMessageBox);
verify(!sendMessageBox.enabled);
}
function test_receiptableEventId() {
verify(pageJoin.getLastReceiptableEventId(item.roomTimeline, item.roomTimeline.count) === '$event3');
}
function test_paginateBack() {
pageJoin.paginateBackRequested('$1');
tryVerify(() => roomJoin.paginateBackFrom.calledTimes() === 1);
verify(roomJoin.paginateBackFrom.lastArgs()[0] === '$1');
// one pagination under way, do not call it twice
pageJoin.paginateBackRequested('$1');
verify(roomJoin.paginateBackFrom.calledTimes() === 1);
// paginating from another event is not affected
pageJoin.paginateBackRequested('$2');
tryVerify(() => roomJoin.paginateBackFrom.calledTimes() === 2);
verify(roomJoin.paginateBackFrom.lastArgs()[0] === '$2');
// after the promise resolves, we can paginate from this id again
roomJoin.paginateBackFrom.retVals[0].resolve(true);
pageJoin.paginateBackRequested('$1');
tryVerify(() => roomJoin.paginateBackFrom.calledTimes() === 3);
verify(roomJoin.paginateBackFrom.lastArgs()[0] === '$1');
}
function test_pinnedAction() {
verify(!findChild(pageJoin, 'pinnedEventsAction').visible);
verify(!findChild(pageJoin, 'pinnedEventsAction').enabled);
verify(findChild(pageWithPinned, 'pinnedEventsAction').visible);
verify(findChild(pageWithPinned, 'pinnedEventsAction').enabled);
}
}
}
diff --git a/src/tests/quick-tests/tst_RoomPinnedEventsPage.qml b/src/tests/quick-tests/tst_RoomPinnedEventsPage.qml
index 17c18e4..3dbc606 100644
--- a/src/tests/quick-tests/tst_RoomPinnedEventsPage.qml
+++ b/src/tests/quick-tests/tst_RoomPinnedEventsPage.qml
@@ -1,70 +1,65 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2024 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick
import QtQuick.Layouts
import QtTest
import '../../contents/ui' as Kazv
-import 'test-helpers.js' as Helpers
-import 'test-helpers' as TestHelpers
+import 'test-helpers' as QmlHelpers
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
-
- property var mockHelper: TestHelpers.MockHelper {}
property var room: ({
name: 'some room',
pinnedEventsTimeline() {
return item.timeline;
},
})
property var makeTextEvent: (i) => ({
eventId: '$' + i,
sender: '@foo:tusooa.xyz',
type: 'm.room.message',
stateKey: '',
content: {
msgtype: 'm.text',
body: 'some body',
},
formattedTime: '4:06 P.M.',
})
property var timeline: ListModel {
ListElement {}
ListElement {}
function at(index) {
return makeTextEvent(index);
}
}
Kazv.RoomPinnedEventsPage {
anchors.fill: parent
id: pinnedEventsPage
room: item.room
}
TestCase {
id: roomPinnedEventsPageTest
name: 'RoomPinnedEventsPageTest'
when: windowShown
function initTestCase() {
pinnedEventsPage.contentItem.clip = false;
}
function test_pinned() {
const roomTimelineView = findChild(pinnedEventsPage, 'roomTimelineView');
verify(roomTimelineView);
tryVerify(() => roomTimelineView.itemAtIndex(0));
tryVerify(() => roomTimelineView.itemAtIndex(1));
}
}
}
diff --git a/src/tests/quick-tests/tst_RoomSettingsPage.qml b/src/tests/quick-tests/tst_RoomSettingsPage.qml
index f416b04..709c1f8 100644
--- a/src/tests/quick-tests/tst_RoomSettingsPage.qml
+++ b/src/tests/quick-tests/tst_RoomSettingsPage.qml
@@ -1,346 +1,335 @@
/*
* 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 '../../contents/ui/room-settings' as KazvRS
import moe.kazv.mxc.kazv 0.0 as MK
-import 'test-helpers.js' as Helpers
-import 'test-helpers' as TestHelpers
+import 'test-helpers.js' as JsHelpers
+import 'test-helpers' as QmlHelpers
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
- property var mockHelper: TestHelpers.MockHelper {}
-
- property var roomUnencrypted: Helpers.factory.room({
+ property var roomUnencrypted: JsHelpers.factory.room({
membership: MK.MatrixRoom.Join,
encrypted: false,
sendStateEvent: mockHelper.promise(),
})
- property var roomEncrypted: Helpers.factory.room({
+ property var roomEncrypted: JsHelpers.factory.room({
membership: MK.MatrixRoom.Join,
encrypted: true,
})
- property var roomLeft: Helpers.factory.room({
+ property var roomLeft: JsHelpers.factory.room({
membership: MK.MatrixRoom.Leave,
forgetRoom: mockHelper.promise(),
})
- property var roomJoined: Helpers.factory.room({
+ property var roomJoined: JsHelpers.factory.room({
membership: MK.MatrixRoom.Join,
leaveRoom: mockHelper.promise(),
topic: '',
})
- property var roomWithMembers: Helpers.factory.room({
+ property var roomWithMembers: JsHelpers.factory.room({
name: 'some name',
roomId: '!someid:example.com',
members: () => ({
at(index) {
return {
userId: `@u${index}:example.com`,
name: `user ${index}`,
};
},
count: 5
}),
setName: mockHelper.promise(),
})
- property var roomWithoutName: Helpers.factory.room({
+ property var roomWithoutName: JsHelpers.factory.room({
name: '',
roomId: '!someid:example.com',
})
- property var roomWithTopic: Helpers.factory.room({
+ property var roomWithTopic: JsHelpers.factory.room({
membership: MK.MatrixRoom.Join,
topic: 'some topic',
setTopic: mockHelper.promise(),
})
- property var showPassiveNotification: mockHelper.noop()
-
- property var l10n: Helpers.fluentMock
- property var matrixSdk: TestHelpers.MatrixSdkMock {
- property var userId: '@foo:example.org'
- }
- property var sdkVars: ({})
-
ColumnLayout {
KazvRS.RoomSettingsPage {
id: pageUnencrypted
room: item.roomUnencrypted
}
KazvRS.RoomSettingsPage {
id: pageEncrypted
room: item.roomEncrypted
}
KazvRS.RoomSettingsPage {
id: pageLeft
room: item.roomLeft
}
KazvRS.RoomSettingsPage {
id: pageJoined
room: item.roomJoined
}
KazvRS.RoomSettingsPage {
id: pageWithMembers
room: item.roomWithMembers
}
KazvRS.RoomSettingsPage {
id: pageWithoutName
room: item.roomWithoutName
}
KazvRS.RoomSettingsPage {
id: pageWithTopic
room: item.roomWithTopic
}
}
TestCase {
id: roomSettingsPageTest
name: 'RoomSettingsPageTest'
when: windowShown
function initTestCase() {
pageJoined.contentItem.clip = false;
pageWithTopic.contentItem.clip = false;
pageWithMembers.contentItem.clip = false;
+ item.matrixSdk.userId = '@foo:example.org';
}
function init() {
pageJoined.submittingTopic = false;
pageJoined.editingTopic = false;
pageWithTopic.submittingTopic = false;
pageWithTopic.editingTopic = false;
pageWithMembers.submittingName = false;
pageWithMembers.editingName = false;
mockHelper.clearAll();
}
function test_encryptionIndicator() {
compare(findChild(pageUnencrypted, 'encryptionIndicator').text, l10n.get('room-settings-not-encrypted'));
verify(findChild(pageUnencrypted, 'enableEncryptionButton').visible);
compare(findChild(pageEncrypted, 'encryptionIndicator').text, l10n.get('room-settings-encrypted'));
verify(!findChild(pageEncrypted, 'enableEncryptionButton').visible);
}
function test_enableEncryption() {
pageUnencrypted.encryptionPopup.accepted();
tryVerify(() => roomUnencrypted.sendStateEvent.lastArgs()[0].type === 'm.room.encryption');
tryVerify(() => roomUnencrypted.sendStateEvent.lastArgs()[0].state_key === '');
verify(!findChild(pageUnencrypted, 'enableEncryptionButton').enabled);
roomUnencrypted.sendStateEvent.lastRetVal().resolve(true, {});
tryVerify(() => findChild(pageUnencrypted, 'enableEncryptionButton').enabled);
}
function test_forgetRoom() {
const forgetRoomButton = findChild(pageLeft, 'forgetRoomButton');
const confirmPopup = findChild(pageLeft, 'confirmForgetRoomPopup');
verify(forgetRoomButton.visible);
verify(!findChild(pageJoined, 'forgetRoomButton').visible);
confirmPopup.accepted();
tryVerify(() => roomLeft.forgetRoom.calledTimes() === 1);
roomLeft.forgetRoom.lastRetVal().resolve(true, {});
tryVerify(() => item.showPassiveNotification.calledTimes() === 1);
}
function test_forgetRoomFailure() {
const confirmPopup = findChild(pageLeft, 'confirmForgetRoomPopup');
confirmPopup.accepted();
roomLeft.forgetRoom.lastRetVal().resolve(false, {});
tryVerify(() => item.showPassiveNotification.calledTimes() === 1);
}
function test_leaveRoom() {
const leaveRoomButton = findChild(pageJoined, 'leaveRoomButton');
const confirmPopup = findChild(pageJoined, 'confirmLeaveRoomPopup');
verify(leaveRoomButton.visible);
confirmPopup.accepted();
tryVerify(() => roomJoined.leaveRoom.calledTimes() === 1);
roomJoined.leaveRoom.lastRetVal().resolve(true, {});
console.log(roomJoined.membership);
tryVerify(() => item.showPassiveNotification.calledTimes() === 1);
}
function test_leaveRoomFailure() {
const confirmPopup = findChild(pageJoined, 'confirmLeaveRoomPopup');
confirmPopup.accepted();
roomJoined.leaveRoom.lastRetVal().resolve(false, {});
tryVerify(() => item.showPassiveNotification.calledTimes() === 1);
}
function test_roomMembersAvatars() {
const repeater = findChild(pageWithMembers, 'roomMembersAvatarsRepeater');
tryVerify(() => repeater.count === 4);
const more = findChild(pageWithMembers, 'roomMembersAvatarsMore');
verify(more.visible);
}
function test_roomWithName() {
const nameLabel = findChild(pageWithMembers, 'roomNameLabel');
const idLabel = findChild(pageWithMembers, 'roomIdLabel');
verify(nameLabel.text === 'some name');
verify(idLabel.text === '!someid:example.com');
}
function test_roomWithoutName() {
const nameLabel = findChild(pageWithoutName, 'roomNameLabel');
const idLabel = findChild(pageWithMembers, 'roomIdLabel');
compare(nameLabel.text, l10n.get('room-settings-name-missing'));
compare(idLabel.text, '!someid:example.com');
}
function test_roomWithoutTopic() {
const topicLabel = findChild(pageJoined, 'roomTopicLabel');
verify(topicLabel.font.italic);
compare(topicLabel.text, l10n.get('room-settings-topic-missing'));
}
function test_roomWithTopic() {
const topicLabel = findChild(pageWithTopic, 'roomTopicLabel');
verify(!topicLabel.font.italic);
compare(topicLabel.text, 'some topic');
}
function test_editRoomTopic() {
const editButton = findChild(pageWithTopic, 'editTopicButton');
mouseClick(editButton);
const textArea = findChild(pageWithTopic, 'roomTopicEdit');
tryVerify(() => textArea.visible);
verify(textArea.text === 'some topic');
textArea.text = 'other topic';
const saveTopicButton = findChild(pageWithTopic, 'saveTopicButton');
verify(saveTopicButton.visible);
verify(saveTopicButton.enabled);
const discardTopicButton = findChild(pageWithTopic, 'discardTopicButton');
verify(discardTopicButton.visible);
verify(discardTopicButton.enabled);
mouseClick(saveTopicButton);
tryVerify(() => roomWithTopic.setTopic.calledTimes() === 1);
compare(roomWithTopic.setTopic.lastArgs()[0], 'other topic');
verify(!saveTopicButton.enabled);
verify(!discardTopicButton.enabled);
roomWithTopic.setTopic.lastRetVal().resolve(true, {});
tryVerify(() => editButton.visible);
verify(!saveTopicButton.visible);
}
function test_editRoomTopicFailed() {
const editButton = findChild(pageWithTopic, 'editTopicButton');
mouseClick(editButton);
const textArea = findChild(pageWithTopic, 'roomTopicEdit');
tryVerify(() => textArea.visible);
verify(textArea.text === 'some topic');
textArea.text = 'other topic';
const saveTopicButton = findChild(pageWithTopic, 'saveTopicButton');
mouseClick(saveTopicButton);
tryVerify(() => roomWithTopic.setTopic.calledTimes() === 1);
roomWithTopic.setTopic.lastRetVal().resolve(false, {});
verify(saveTopicButton.enabled);
verify(textArea.visible);
}
function test_editRoomTopicDiscard() {
const editButton = findChild(pageWithTopic, 'editTopicButton');
mouseClick(editButton);
const textArea = findChild(pageWithTopic, 'roomTopicEdit');
tryVerify(() => textArea.visible);
verify(textArea.text === 'some topic');
textArea.text = 'other topic';
const discardTopicButton = findChild(pageWithTopic, 'discardTopicButton');
mouseClick(discardTopicButton);
compare(roomWithTopic.setTopic.calledTimes(), 0);
verify(!textArea.visible);
mouseClick(editButton);
tryVerify(() => textArea.visible);
verify(textArea.text === 'some topic');
}
function test_addRoomTopic() {
const editButton = findChild(pageJoined, 'editTopicButton');
mouseClick(editButton);
const textArea = findChild(pageJoined, 'roomTopicEdit');
tryVerify(() => textArea.visible);
verify(textArea.text === '');
}
function test_editRoomName() {
const editButton = findChild(pageWithMembers, 'editNameButton');
mouseClick(editButton);
const textArea = findChild(pageWithMembers, 'roomNameEdit');
tryVerify(() => textArea.visible);
verify(textArea.text === 'some name');
textArea.text = 'other name';
const saveNameButton = findChild(pageWithMembers, 'saveNameButton');
verify(saveNameButton.visible);
verify(saveNameButton.enabled);
const discardNameButton = findChild(pageWithMembers, 'discardNameButton');
verify(discardNameButton.visible);
verify(discardNameButton.enabled);
mouseClick(saveNameButton);
tryVerify(() => roomWithMembers.setName.calledTimes() === 1);
compare(roomWithMembers.setName.lastArgs()[0], 'other name');
verify(!saveNameButton.enabled);
verify(!discardNameButton.enabled);
roomWithMembers.setName.lastRetVal().resolve(true, {});
tryVerify(() => editButton.visible);
verify(!saveNameButton.visible);
}
function test_editRoomNameFailed() {
const editButton = findChild(pageWithMembers, 'editNameButton');
mouseClick(editButton);
const textArea = findChild(pageWithMembers, 'roomNameEdit');
tryVerify(() => textArea.visible);
verify(textArea.text === 'some name');
textArea.text = 'other name';
const saveNameButton = findChild(pageWithMembers, 'saveNameButton');
mouseClick(saveNameButton);
tryVerify(() => roomWithMembers.setName.calledTimes() === 1);
roomWithMembers.setName.lastRetVal().resolve(false, {});
verify(saveNameButton.enabled);
verify(textArea.visible);
}
function test_editRoomNameDiscard() {
const editButton = findChild(pageWithMembers, 'editNameButton');
mouseClick(editButton);
const textArea = findChild(pageWithMembers, 'roomNameEdit');
tryVerify(() => textArea.visible);
verify(textArea.text === 'some name');
textArea.text = 'other name';
const discardNameButton = findChild(pageWithMembers, 'discardNameButton');
mouseClick(discardNameButton);
compare(roomWithMembers.setName.calledTimes(), 0);
verify(!textArea.visible);
mouseClick(editButton);
tryVerify(() => textArea.visible);
verify(textArea.text === 'some name');
}
}
}
diff --git a/src/tests/quick-tests/tst_RoomStickerPackItemDelegate.qml b/src/tests/quick-tests/tst_RoomStickerPackItemDelegate.qml
index df55a37..e0f20f2 100644
--- a/src/tests/quick-tests/tst_RoomStickerPackItemDelegate.qml
+++ b/src/tests/quick-tests/tst_RoomStickerPackItemDelegate.qml
@@ -1,94 +1,87 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2024 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick
import QtQuick.Layouts
import QtTest
import moe.kazv.mxc.kazv as MK
import org.kde.kirigami as Kirigami
import '../../contents/ui/room-settings' as KazvRS
-import 'test-helpers.js' as Helpers
-import 'test-helpers' as TestHelpers
+import 'test-helpers.js' as JsHelpers
+import 'test-helpers' as QmlHelpers
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
-
- property var mockHelper: TestHelpers.MockHelper {}
- property var matrixSdk: TestHelpers.MatrixSdkMock {
- property var sendAccountData: mockHelper.promise()
- }
KazvRS.RoomStickerPackItemDelegate {
id: packItem
}
TestCase {
id: roomStickerPackItemDelegateTest
name: 'RoomStickerPackItemDelegateTest'
when: windowShown
function init() {
item.mockHelper.clearAll();
packItem.stickerPack = {
packName: 'some pack',
stateKey: 'some-pack',
roomId: '!foo:example.com',
isRoomState: true,
};
packItem.stickerRoomsEvent = {
content: {
},
};
}
function test_usePack() {
const usePackAction = findChild(packItem, 'usePackAction');
verify(!usePackAction.checked);
usePackAction.trigger();
tryVerify(() => matrixSdk.sendAccountData.calledTimes() === 1);
- verify(Helpers.deepEqual(
+ verify(JsHelpers.deepEqual(
matrixSdk.sendAccountData.lastArgs()[1],
{
rooms: {
'!foo:example.com': {
'some-pack': {},
},
},
},
));
}
function test_disusePack() {
packItem.stickerRoomsEvent = {
content: {
rooms: {
'!foo:example.com': {
'some-pack': {},
},
},
},
};
const usePackAction = findChild(packItem, 'usePackAction');
verify(usePackAction.checked);
usePackAction.trigger();
tryVerify(() => matrixSdk.sendAccountData.calledTimes() === 1);
- verify(Helpers.deepEqual(
+ verify(JsHelpers.deepEqual(
matrixSdk.sendAccountData.lastArgs()[1],
{
rooms: {
'!foo:example.com': {
},
},
},
));
}
}
}
diff --git a/src/tests/quick-tests/tst_RoomStickerPacksPage.qml b/src/tests/quick-tests/tst_RoomStickerPacksPage.qml
index 51184b6..583eb95 100644
--- a/src/tests/quick-tests/tst_RoomStickerPacksPage.qml
+++ b/src/tests/quick-tests/tst_RoomStickerPacksPage.qml
@@ -1,127 +1,118 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2024 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick
import QtQuick.Layouts
import QtTest
import moe.kazv.mxc.kazv as MK
import org.kde.kirigami as Kirigami
import '../../contents/ui/room-settings' as KazvRS
import '../../js/matrix-helpers.js' as MatrixHelpers
-import 'test-helpers.js' as Helpers
-import 'test-helpers' as TestHelpers
+import 'test-helpers.js' as JsHelpers
+import 'test-helpers' as QmlHelpers
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
-
- property var l10n: Helpers.fluentMock
- property var mockHelper: TestHelpers.MockHelper {}
- property var showPassiveNotification: mockHelper.noop()
- property var matrixSdk: TestHelpers.MatrixSdkMock {
- property var sendAccountData: mockHelper.promise()
- }
KazvRS.RoomStickerPacksPage {
id: page
anchors.fill: parent
room: QtObject {
function state(type, stateKey) {
return {
type,
stateKey,
content: stateKey === 'foo' ? {
images: {
'mew': {},
},
} : stateKey === 'bar' ? {
pack: {
'some': 'others',
},
} : {},
};
}
property var sendStateEvent: mockHelper.promise()
}
}
TestCase {
id: roomStickerPacksPageTest
name: 'RoomStickerPacksPageTest'
when: windowShown
function init() {
item.mockHelper.clearAll();
}
function test_addPack_data() {
return [
{
succ: true,
stateKey: '',
packContent: {
pack: {
display_name: 'some name',
},
},
},
{
succ: false,
stateKey: '',
packContent: {
pack: {
display_name: 'some name',
},
},
},
{
succ: true,
stateKey: 'foo',
packContent: {
images: {
'mew': {},
},
pack: {
display_name: 'some name',
},
},
},
{
succ: true,
stateKey: 'bar',
packContent: {
pack: {
'some': 'others',
display_name: 'some name',
},
},
},
];
}
function test_addPack(data) {
findChild(page, 'addStickerPackAction').trigger();
tryVerify(() => findChild(page, 'stickerPackName').visible);
findChild(page, 'stickerPackName').text = 'some name';
findChild(page, 'stickerPackStateKey').text = data.stateKey;
page.addStickerPackPopup.accept();
tryVerify(() => page.room.sendStateEvent.calledTimes() === 1);
- verify(Helpers.deepEqual(
+ verify(JsHelpers.deepEqual(
page.room.sendStateEvent.lastArgs(),
[{
type: MatrixHelpers.roomImagePackEventType,
state_key: data.stateKey,
content: data.packContent,
}],
));
page.room.sendStateEvent.lastRetVal().resolve(data.succ, {});
compare(item.showPassiveNotification.calledTimes(), 1);
}
}
}
diff --git a/src/tests/quick-tests/tst_RoomTimelineView.qml b/src/tests/quick-tests/tst_RoomTimelineView.qml
index e875d83..8be43d1 100644
--- a/src/tests/quick-tests/tst_RoomTimelineView.qml
+++ b/src/tests/quick-tests/tst_RoomTimelineView.qml
@@ -1,202 +1,194 @@
/*
* 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 QtQuick.Window
import QtQuick.Controls
import QtTest 1.0
import moe.kazv.mxc.kazv 0.0 as MK
import org.kde.kirigami 2.13 as Kirigami
import '../../contents/ui' as Kazv
-import 'test-helpers.js' as Helpers
-import 'test-helpers' as TestHelpers
+import 'test-helpers.js' as JsHelpers
+import 'test-helpers' as QmlHelpers
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
-
- property var mockHelper: TestHelpers.MockHelper {}
- property var l10n: Helpers.fluentMock
- property var matrixSdk: TestHelpers.MatrixSdkMock {}
property var makeLocalEcho: (i) => ({
eventId: '',
sender: '',
type: 'm.room.message',
stateKey: '',
content: {
msgtype: 'm.text',
body: 'some body' + i,
},
encrypted: false,
isState: false,
unsignedData: {},
isLocalEcho: true,
isSending: true,
isFailed: false,
txnId: 'some-txn-id' + i,
})
property var makeTextEvent: (i) => ({
eventId: '$' + i,
sender: '@foo:tusooa.xyz',
type: 'm.room.message',
stateKey: '',
content: {
msgtype: 'm.text',
body: 'some body',
},
formattedTime: '4:06 P.M.',
})
property var room: ({
pinEvents: mockHelper.promise(),
unpinEvents: mockHelper.promise(),
redactEvent: mockHelper.promise(),
removeLocalEcho: mockHelper.promise(),
messageById(id) {
return { eventId: id };
},
localEchoById(id) {
return { txnId: id };
}
})
- property var showPassiveNotification: mockHelper.noop()
-
Kazv.RoomTimelineView {
anchors.fill: parent
id: roomTimelineView
timeline: item.timeline
}
property var timeline: ListModel {
ListElement {}
ListElement {}
function at(index) {
if (index < 1) {
return makeLocalEcho(index);
} else {
return makeTextEvent(index);
}
}
}
TestCase {
id: roomTimelineViewTest
name: 'RoomTimelineViewTest'
when: windowShown
function init() {
mockHelper.clearAll();
}
function test_selected() {
tryVerify(() => roomTimelineView.itemAtIndex(0));
tryVerify(() => roomTimelineView.itemAtIndex(1));
const localEcho = roomTimelineView.itemAtIndex(0);
verify(!localEcho.isSelected);
const sentMessage = roomTimelineView.itemAtIndex(1);
verify(!sentMessage.isSelected);
roomTimelineView.selectedEventId = '$1';
verify(sentMessage.isSelected);
}
function test_pinSuccess() {
roomTimelineView.pinEventRequested('$2');
const popup = findChild(Overlay.overlay, 'pinEventPopup');
verify(popup);
tryVerify(() => popup.opened);
mouseClick(findChild(popup, 'confirmButton'));
verify(room.pinEvents.calledTimes() === 1);
- verify(Helpers.deepEqual(room.pinEvents.lastArgs()[0], ['$2']));
+ verify(JsHelpers.deepEqual(room.pinEvents.lastArgs()[0], ['$2']));
tryVerify(() => !popup.opened);
tryVerify(() => !findChild(Overlay.overlay, 'pinEventPopup'));
room.pinEvents.lastRetVal().resolve(true, {});
compare(showPassiveNotification.calledTimes(), 1);
compare(showPassiveNotification.lastArgs()[0], l10n.get('event-pin-success-prompt'));
}
function test_pinFailure() {
roomTimelineView.pinEventRequested('$2');
const popup = findChild(Overlay.overlay, 'pinEventPopup');
verify(popup);
tryVerify(() => popup.opened);
mouseClick(findChild(popup, 'confirmButton'));
verify(room.pinEvents.calledTimes() === 1);
- verify(Helpers.deepEqual(room.pinEvents.lastArgs()[0], ['$2']));
+ verify(JsHelpers.deepEqual(room.pinEvents.lastArgs()[0], ['$2']));
tryVerify(() => !popup.opened);
tryVerify(() => !findChild(Overlay.overlay, 'pinEventPopup'));
room.pinEvents.lastRetVal().resolve(false, { errorCode: 'M_FORBIDDEN', error: 'You are not allowed to do so' });
compare(showPassiveNotification.calledTimes(), 1);
compare(showPassiveNotification.lastArgs()[0], l10n.get('event-pin-failed-prompt', { errorCode: 'M_FORBIDDEN', errorMsg: 'You are not allowed to do so' }));
}
function test_unpinSuccess() {
roomTimelineView.unpinEventRequested('$2');
const popup = findChild(Overlay.overlay, 'unpinEventPopup');
verify(popup);
tryVerify(() => popup.opened);
mouseClick(findChild(popup, 'confirmButton'));
verify(room.unpinEvents.calledTimes() === 1);
- verify(Helpers.deepEqual(room.unpinEvents.lastArgs()[0], ['$2']));
+ verify(JsHelpers.deepEqual(room.unpinEvents.lastArgs()[0], ['$2']));
tryVerify(() => !popup.opened);
tryVerify(() => !findChild(Overlay.overlay, 'unpinEventPopup'));
room.unpinEvents.lastRetVal().resolve(true, {});
compare(showPassiveNotification.calledTimes(), 1);
compare(showPassiveNotification.lastArgs()[0], l10n.get('event-unpin-success-prompt'));
}
function test_unpinFailure() {
roomTimelineView.unpinEventRequested('$2');
const popup = findChild(Overlay.overlay, 'unpinEventPopup');
verify(popup);
tryVerify(() => popup.opened);
mouseClick(findChild(popup, 'confirmButton'));
verify(room.unpinEvents.calledTimes() === 1);
- verify(Helpers.deepEqual(room.unpinEvents.lastArgs()[0], ['$2']));
+ verify(JsHelpers.deepEqual(room.unpinEvents.lastArgs()[0], ['$2']));
tryVerify(() => !popup.opened);
tryVerify(() => !findChild(Overlay.overlay, 'unpinEventPopup'));
room.unpinEvents.lastRetVal().resolve(false, { errorCode: 'M_FORBIDDEN', error: 'You are not allowed to do so' });
compare(showPassiveNotification.calledTimes(), 1);
compare(showPassiveNotification.lastArgs()[0], l10n.get('event-unpin-failed-prompt', { errorCode: 'M_FORBIDDEN', errorMsg: 'You are not allowed to do so' }));
}
function test_deleteEvent() {
roomTimelineView.deleteEventRequested("some-event-id", false);
const popup = findChild(Overlay.overlay, 'confirmDeletionPopup');
verify(popup);
tryVerify(() => popup.opened);
mouseClick(findChild(popup, 'confirmButton'));
verify(room.redactEvent.calledTimes() === 1);
verify(room.redactEvent.lastArgs()[0], ['some-eventId']);
tryVerify(() => !popup.opened);
tryVerify(() => !findChild(Overlay.overlay, 'confirmDeletionPopup'));
room.redactEvent.lastRetVal().resolve(false, { errorCode: 'M_FORBIDDEN', error: 'You are not allowed to do so' });
compare(showPassiveNotification.calledTimes(), 1);
compare(showPassiveNotification.lastArgs()[0], l10n.get('event-delete-failed', { errorMsg: 'You are not allowed to do so', errorCode: 'M_FORBIDDEN' }));
}
function test_deleteLocalEcho() {
roomTimelineView.deleteEventRequested("some-txnId", true);
const popup = findChild(Overlay.overlay, 'confirmDeletionPopup');
verify(popup);
tryVerify(() => popup.opened);
mouseClick(findChild(popup, 'confirmButton'));
verify(room.removeLocalEcho.calledTimes() === 1);
verify(room.removeLocalEcho.lastArgs()[0], ['some-txnId']);
tryVerify(() => !popup.opened);
tryVerify(() => !findChild(Overlay.overlay, 'confirmDeletionPopup'));
}
}
}
diff --git a/src/tests/quick-tests/tst_SendMessageBox.qml b/src/tests/quick-tests/tst_SendMessageBox.qml
index 6521081..f71c02d 100644
--- a/src/tests/quick-tests/tst_SendMessageBox.qml
+++ b/src/tests/quick-tests/tst_SendMessageBox.qml
@@ -1,269 +1,246 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2020-2024 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import QtTest 1.0
import org.kde.kirigami 2.13 as Kirigami
import '../../contents/ui' as Kazv
-import 'test-helpers.js' as Helpers
-import 'test-helpers' as TestHelpers
+import 'test-helpers.js' as JsHelpers
+import 'test-helpers' as QmlHelpers
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
- property var mockHelper: TestHelpers.MockHelper {}
function makeRoom () {
return {
timeline () {
return {
count: 0,
eventIds: [],
gaps: [],
at () { return {}; },
};
},
messageById () { return {}; },
member () { return {}; },
localDraft: '',
setLocalDraft (localDraft) {
this.localDraft = localDraft;
},
updateLocalDraftNow () {
},
members () {
return membersModel;
},
setTyping: mockHelper.noop(),
sendTextMessage: mockHelper.noop(),
roomId: '!some-event-id',
encrypted: true,
};
}
property var room: makeRoom()
property var membersModel: ListModel {
ListElement { userId: '@foo:example.com' }
ListElement { userId: '@bar:example.com' }
property string filter
property var count: 2
function at(index) {
return get(index);
}
}
- property var l10n: Helpers.fluentMock
- property var matrixSdk: TestHelpers.MatrixSdkMock {
- property var serverUrl: "https://example.com"
- property var token: "token"
- }
- property var kazvIOManager: TestHelpers.KazvIOManagerMock {
- property var startNewUploadJob: mockHelper.noop([
- 'serverUrl',
- 'fileUrl',
- 'token',
- 'roomId',
- 'roomList',
- 'encrypted',
- 'draftRelType',
- 'draftRelatedTo'
- ])
- }
- property var sdkVars: ({
- roomList: {}
- })
Kazv.SendMessageBox {
id: sendMessageBox
y: 400
room: item.room
}
TestCase {
id: sendMessageBoxTest
name: 'SendMessageBoxTest'
when: windowShown
function init() {
membersModel.count = 2;
findChild(sendMessageBox, 'draftMessage').text = '';
mockHelper.clearAll();
}
function test_empty() {
const textArea = findChild(sendMessageBox, 'draftMessage');
sendMessageBox.mentionUser('@foo:example.com');
tryVerify(() => textArea.text === '@foo:example.com ');
verify(textArea.cursorPosition === textArea.text.length);
}
function test_cursorAtEnd() {
const textArea = findChild(sendMessageBox, 'draftMessage');
textArea.text = 'some test';
textArea.cursorPosition = textArea.text.length;
sendMessageBox.mentionUser('@foo:example.com');
tryVerify(() => textArea.text === 'some test @foo:example.com ');
verify(textArea.cursorPosition === textArea.text.length);
}
function test_cursorAtEndSpacingBefore() {
const textArea = findChild(sendMessageBox, 'draftMessage');
textArea.text = 'some test\n';
textArea.cursorPosition = textArea.text.length;
sendMessageBox.mentionUser('@foo:example.com');
tryVerify(() => textArea.text === 'some test\n@foo:example.com ');
verify(textArea.cursorPosition === textArea.text.length);
}
function test_cursorAtBeginning() {
const textArea = findChild(sendMessageBox, 'draftMessage');
textArea.text = 'some test';
textArea.cursorPosition = 0;
sendMessageBox.mentionUser('@foo:example.com');
tryVerify(() => textArea.text === '@foo:example.com some test');
verify(textArea.cursorPosition === '@foo:example.com '.length);
}
function test_cursorAtBeginningSpacingAfter() {
const textArea = findChild(sendMessageBox, 'draftMessage');
textArea.text = '\nsome test';
textArea.cursorPosition = 0;
sendMessageBox.mentionUser('@foo:example.com');
tryVerify(() => textArea.text === '@foo:example.com\nsome test');
verify(textArea.cursorPosition === '@foo:example.com\n'.length);
}
function test_cursorInMiddleNoSpacing() {
const textArea = findChild(sendMessageBox, 'draftMessage');
textArea.text = 'some\ntest';
textArea.cursorPosition = 1;
sendMessageBox.mentionUser('@foo:example.com');
tryVerify(() => textArea.text === 's @foo:example.com ome\ntest');
verify(textArea.cursorPosition === 's @foo:example.com '.length);
}
function test_cursorInMiddleSpacingBefore() {
const textArea = findChild(sendMessageBox, 'draftMessage');
textArea.text = 'some\ntest';
textArea.cursorPosition = 5;
sendMessageBox.mentionUser('@foo:example.com');
tryVerify(() => textArea.text === 'some\n@foo:example.com test');
verify(textArea.cursorPosition === 'some\n@foo:example.com '.length);
}
function test_cursorInMiddleSpacingAfter() {
const textArea = findChild(sendMessageBox, 'draftMessage');
textArea.text = 'some\ntest';
textArea.cursorPosition = 4;
sendMessageBox.mentionUser('@foo:example.com');
tryVerify(() => textArea.text === 'some @foo:example.com\ntest');
verify(textArea.cursorPosition === 'some @foo:example.com\n'.length);
}
function test_cursorInMiddleSpacingAround() {
const textArea = findChild(sendMessageBox, 'draftMessage');
textArea.text = 'some\n\ntest';
textArea.cursorPosition = 5;
sendMessageBox.mentionUser('@foo:example.com');
tryVerify(() => textArea.text === 'some\n@foo:example.com\ntest');
verify(textArea.cursorPosition === 'some\n@foo:example.com\n'.length);
}
function test_filter() {
const data = [
['some\n\ntest', 5, ''],
['some\n\n@test\n', 11, '@test'],
['some\n\n@test\n', 10, '@tes'],
['some\n\n@test喵 ', 12, '@test喵'],
// separated by a whitespace
['some\n\n@test\n', 12, ''],
['some\n\n@test\t', 12, ''],
['some\n\n@test ', 12, ''],
// multiple @s
['@test@233', 9, '@233'],
];
const textArea = findChild(sendMessageBox, 'draftMessage');
data.forEach(([text, pos, expected]) => {
textArea.text = text;
textArea.cursorPosition = pos;
compare(textArea.filter, expected);
});
}
function test_completion() {
const textArea = findChild(sendMessageBox, 'draftMessage');
textArea.text = '@ex';
textArea.cursorPosition = 3;
const completionPopup = findChild(sendMessageBox, 'completionPopup');
tryVerify(() => completionPopup.opened);
const listView = findChild(completionPopup, 'completionListView');
tryVerify(() => listView);
tryVerify(() => findChild(listView, 'completionItem0'));
tryVerify(() => findChild(listView, 'completionItem1'));
const first = findChild(listView, 'completionItem0');
const second = findChild(listView, 'completionItem1');
verify(findChild(first, 'userIdLabel').text === '@foo:example.com');
verify(findChild(second, 'userIdLabel').text === '@bar:example.com');
mouseClick(second);
tryVerify(() => !completionPopup.opened);
const expected = '@bar:example.com ';
tryCompare(textArea, 'text', expected);
compare(textArea.cursorPosition, expected.length);
}
function test_zeroCompletion() {
membersModel.count = 0;
const textArea = findChild(sendMessageBox, 'draftMessage');
textArea.text = '@ex';
textArea.cursorPosition = 3;
const completionPopup = findChild(sendMessageBox, 'completionPopup');
tryVerify(() => !completionPopup.opened);
}
function test_emptySend() {
mouseClick(findChild(sendMessageBox, 'sendButton'));
verify(room.sendTextMessage.calledTimes() === 0);
const textArea = findChild(sendMessageBox, 'draftMessage');
mouseClick(textArea);
tryVerify(() => textArea.activeFocus);
keySequence('Ctrl+Enter');
verify(room.sendTextMessage.calledTimes() === 0);
keySequence('Ctrl+Return');
verify(room.sendTextMessage.calledTimes() === 0);
}
function test_replyWithFile() {
sendMessageBox.draftRelType = 'm.in_reply_to';
sendMessageBox.draftRelatedTo = '!some-event-id';
const sendFileButton = findChild(sendMessageBox, 'sendMediaFileButton');
const fileDialog = findChild(sendMessageBox, 'fileDialog');
verify(sendFileButton.enabled);
verify(!fileDialog.visible);
mouseClick(sendFileButton);
verify(fileDialog.visible);
fileDialog.accept();
verify(!fileDialog.visible);
compare(kazvIOManager.startNewUploadJob.calledTimes(), 1);
- verify(Helpers.deepEqual(kazvIOManager.startNewUploadJob.lastArgs(), {
+ verify(JsHelpers.deepEqual(kazvIOManager.startNewUploadJob.lastArgs(), {
serverUrl: matrixSdk.serverUrl,
fileUrl: Qt.url(''),
token: matrixSdk.token,
roomId: room.roomId,
roomList: sdkVars.roomList,
encrypted: room.encrypted,
draftRelType: 'm.in_reply_to',
draftRelatedTo: '!some-event-id'
}));
}
}
}
diff --git a/src/tests/quick-tests/tst_SendMessageBoxDrafts.qml b/src/tests/quick-tests/tst_SendMessageBoxDrafts.qml
index 4b9d532..edefa28 100644
--- a/src/tests/quick-tests/tst_SendMessageBoxDrafts.qml
+++ b/src/tests/quick-tests/tst_SendMessageBoxDrafts.qml
@@ -1,128 +1,119 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2020-2024 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import QtTest 1.0
import org.kde.kirigami 2.13 as Kirigami
import '../../contents/ui' as Kazv
-import 'test-helpers.js' as Helpers
-import 'test-helpers' as TestHelpers
+import 'test-helpers.js' as JsHelpers
+import 'test-helpers' as QmlHelpers
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
- property var mockHelper: TestHelpers.MockHelper {}
function makeRoom () {
return {
timeline () {
return {
count: 0,
eventIds: [],
gaps: [],
at () { return {}; },
};
},
messageById () { return {}; },
member () { return {}; },
localDraft: '',
setLocalDraft: mockHelper.noop(),
updateLocalDraftNow: mockHelper.func(function () {
this.localDraft = this.setLocalDraft.lastArgs()[0];
}),
};
}
property var room: makeRoom()
property var room2: makeRoom()
property var sendMessageBoxComp: Component {
id: comp
Kirigami.Page {
- property var l10n: Helpers.fluentMock
- property var matrixSdk: TestHelpers.MatrixSdkMock {}
- property var kazvIOManager: TestHelpers.KazvIOManagerMock {}
id: page
Label {
text: 'room 1'
}
footer: Item {
height: childrenRect.height
width: parent.width
Kazv.SendMessageBox {
room: item.room
}
}
}
}
property var sendMessageBoxComp2: Component {
id: comp2
Kirigami.Page {
- property var l10n: Helpers.fluentMock
- property var matrixSdk: TestHelpers.MatrixSdkMock {}
- property var kazvIOManager: TestHelpers.KazvIOManagerMock {}
id: page
Label {
text: 'room 2'
}
footer: Item {
height: childrenRect.height
width: parent.width
Kazv.SendMessageBox {
room: item.room2
}
}
}
}
property var mockMainPageComp: Component {
id: mockMainPageComp
Kirigami.Page {}
}
Kirigami.ApplicationWindow {
id: window
}
TestCase {
id: sendMessageBoxDraftsTest
name: 'SendMessageBoxDraftsTest'
when: windowShown
function test_saveDraftsOnSwitching() {
// simulates the MainPage when starting up kazv
window.pageStack.push(mockMainPageComp);
// a room page is pushed, here we simulate it with only the send
// message box, as other things are unrelevant
window.pageStack.push(comp);
const textArea = findChild(window.pageStack, 'draftMessage');
verify(textArea);
// change text
textArea.text = 'foo';
// verify that the draft is saved internally but not propagated
verify(item.room.localDraft === '');
verify(item.room.setLocalDraft.lastArgs()[0] === 'foo');
// go back to MainPage
window.pageStack.goBack();
verify(window.pageStack.currentIndex === 0);
// push another room page
window.pageStack.push(comp2);
verify(window.pageStack.currentIndex === 1);
// should be the draft for that room, so it is empty
tryVerify(() => findChild(window.pageStack, 'draftMessage').text === '', 1000);
// verify that the draft is propagated
tryVerify(() => item.room.localDraft === 'foo', 1000);
verify(item.room.updateLocalDraftNow.calledTimes() === 1);
}
}
}
diff --git a/src/tests/quick-tests/tst_StickerPackNameProvider.qml b/src/tests/quick-tests/tst_StickerPackNameProvider.qml
index 9cb1652..3a9c40c 100644
--- a/src/tests/quick-tests/tst_StickerPackNameProvider.qml
+++ b/src/tests/quick-tests/tst_StickerPackNameProvider.qml
@@ -1,108 +1,107 @@
/*
* 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
+import 'test-helpers.js' as JsHelpers
TestCase {
id: stickerPackNameProviderTest
name: 'StickerPackNameProviderTest'
when: true
property var sdkVars: QtObject {
property var userGivenNicknameMap: QtObject {
property var map: ({})
}
property var roomList: QtObject {
function room(roomId) {
return stickerPackNameProviderTest.roomComp.createObject(stickerPackNameProviderTest, {
roomId,
name: `Some room ${roomId}`,
heroEvents: [],
});
}
}
}
- property var l10n: Helpers.fluentMock
+ property var l10n: JsHelpers.fluentMock
property var providerFunctional: Kazv.StickerPackNameProvider {}
property var providerReactive: Kazv.StickerPackNameProvider {}
property var roomComp: Component {
QtObject {
property var name
property var heroEvents
property var roomId
}
}
property var packComp: Component {
QtObject {
property var packName
property var isAccountData
property var isState
property var stateKey
property var roomId
}
}
function init() {
}
function test_functional() {
compare(
providerFunctional.getName({ packName: 'some name' }),
'some name');
compare(providerFunctional.getName({
packName: '',
isAccountData: true,
}), l10n.get('sticker-picker-user-stickers'));
verify(
providerFunctional.getName({
packName: '',
isState: true,
stateKey: '',
}).includes('sticker-picker-room-default-sticker-pack-name'));
}
function test_reactiveAgainstPack() {
providerReactive.pack = stickerPackNameProviderTest.packComp.createObject(stickerPackNameProviderTest, {
packName: 'some name',
roomId: '!example:example.com',
isState: true,
isAccountData: false,
});
compare(providerReactive.name, 'some name');
providerReactive.pack.packName = 'some other name';
compare(providerReactive.name, 'some other name');
providerReactive.pack.packName = '';
verify(providerReactive.name.includes('Some room !example:example.com'));
providerReactive.pack.isAccountData = true;
providerReactive.pack.isState = false;
compare(providerReactive.name, l10n.get('sticker-picker-user-stickers'));
}
function test_reactiveAgainstRoom() {
providerReactive.pack = packComp.createObject(stickerPackNameProviderTest, {
packName: '',
roomId: '!example:example.com',
isState: true,
isAccountData: false,
});
providerReactive.roomNameProvider.room.name = 'Some other room';
verify(providerReactive.name.includes('Some other room'));
}
}
diff --git a/src/tests/quick-tests/tst_StickerPicker.qml b/src/tests/quick-tests/tst_StickerPicker.qml
index e943d6d..428c46d 100644
--- a/src/tests/quick-tests/tst_StickerPicker.qml
+++ b/src/tests/quick-tests/tst_StickerPicker.qml
@@ -1,126 +1,120 @@
/*
* 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 'test-helpers.js' as JsHelpers
+import 'test-helpers' as QmlHelpers
import moe.kazv.mxc.kazv 0.0 as MK
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
-
- property var l10n: Helpers.fluentMock
- property var matrixSdk: TestHelpers.MatrixSdkMock {}
- property var sdkVars: ({})
function makeSticker(sticker) {
return {
type: 'm.sticker',
content: {
body: sticker.body,
url: sticker.mxcUri,
info: sticker.info,
},
};
}
property list<ListModel> stickerPacks: [
ListModel {
id: stickerPack0
ListElement {
shortCode: 'some'
body: 'some'
mxcUri: 'mxc://example.org/some'
makeEventJson: () => makeSticker(stickerPack0.get(0))
}
ListElement {
shortCode: 'some1'
body: 'some1'
mxcUri: 'mxc://example.org/some1'
makeEventJson: () => makeSticker(stickerPack0.get(1))
}
function at(index) {
return stickerPack0.get(index);
}
},
ListModel {
id: stickerPack1
ListElement {
shortCode: 'some2'
body: 'some2'
mxcUri: 'mxc://example.org/some2'
makeEventJson: () => makeSticker(stickerPack1.get(0))
}
ListElement {
shortCode: 'some3'
body: 'some3'
mxcUri: 'mxc://example.org/some3'
makeEventJson: () => makeSticker(stickerPack1.get(1))
}
function at(index) {
return stickerPack1.get(index);
}
}
]
SignalSpy {
id: sendMessageRequestedSpy
signalName: 'sendMessageRequested'
}
Kazv.StickerPicker {
id: stickerPicker
stickerPackList: ListModel {
id: stickerPackListModel
ListElement {
}
ListElement {
}
function at(index) {
return stickerPacks[index];
}
}
}
TestCase {
id: stickerPickerTest
name: 'StickerPickerTest'
when: windowShown
function init() {
sendMessageRequestedSpy.clear();
sendMessageRequestedSpy.target = stickerPicker;
}
function test_stickerPicker() {
verify(findChild(stickerPicker, 'stickerPack0'));
verify(findChild(stickerPicker, 'stickerPack1'));
verify(findChild(stickerPicker, 'sticker0'));
verify(findChild(stickerPicker, 'sticker1'));
const stickerButton = findChild(stickerPicker, 'sticker1');
mouseClick(stickerButton);
tryVerify(() => sendMessageRequestedSpy.count === 1, 1000);
- verify(Helpers.deepEqual(sendMessageRequestedSpy.signalArguments[0][0], makeSticker(stickerPack0.get(1))));
+ verify(JsHelpers.deepEqual(sendMessageRequestedSpy.signalArguments[0][0], makeSticker(stickerPack0.get(1))));
mouseClick(findChild(stickerPicker, 'stickerPack1'));
tryVerify(() => findChild(stickerPicker, 'sticker0').sticker.mxcUri === 'mxc://example.org/some2');
mouseClick(findChild(stickerPicker, 'sticker0'));
tryVerify(() => sendMessageRequestedSpy.count === 2, 1000);
- verify(Helpers.deepEqual(sendMessageRequestedSpy.signalArguments[1][0], makeSticker(stickerPack1.get(0))));
+ verify(JsHelpers.deepEqual(sendMessageRequestedSpy.signalArguments[1][0], makeSticker(stickerPack1.get(0))));
}
}
}
diff --git a/src/tests/quick-tests/tst_TypingIndicator.qml b/src/tests/quick-tests/tst_TypingIndicator.qml
index 3f71ef8..bf1e47b 100644
--- a/src/tests/quick-tests/tst_TypingIndicator.qml
+++ b/src/tests/quick-tests/tst_TypingIndicator.qml
@@ -1,80 +1,70 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.3
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 'test-helpers.js' as JsHelpers
+import 'test-helpers' as QmlHelpers
-Item {
+QmlHelpers.TestItem {
id: item
- width: 800
- height: 600
property var user1: ({
name: 'some name',
userId: '@some:tusooa.xyz',
})
property var user2: ({
name: '',
userId: '@some2:tusooa.xyz',
})
property var user3: ({
name: 'xxx',
userId: '@some3:tusooa.xyz',
})
property var typingUserModel: ({
_users: [user1, user2, user3],
at: function (index) {
return this._users[index]
},
count: 3,
})
- property var l10n: Helpers.fluentMock
-
- property var sdkVars: QtObject {
- property var userGivenNicknameMap: QtObject {
- property var map: ({})
- }
- }
-
ColumnLayout {
Kazv.TypingIndicator {
id: ind0
}
Kazv.TypingIndicator {
id: ind3
typingUsers: typingUserModel
}
}
TestCase {
id: typingIndicatorTest
name: 'typingIndicatorTest'
when: windowShown
function test_ind0() {
verify(!ind0.visible);
}
function test_ind3() {
verify(ind3.visible);
verify(ind3.text === l10n.get('typing-indicator', {
otherNum: 2,
typingUser: user1.name,
secondTypingUser: user2.userId,
}))
}
}
}
diff --git a/src/tests/quick-tests/tst_UserNameProvider.qml b/src/tests/quick-tests/tst_UserNameProvider.qml
index 73e4755..8f0d2a9 100644
--- a/src/tests/quick-tests/tst_UserNameProvider.qml
+++ b/src/tests/quick-tests/tst_UserNameProvider.qml
@@ -1,108 +1,108 @@
/*
* 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
+import './test-helpers' as QmlHelpers
+import 'test-helpers.js' as JsHelpers
TestCase {
id: userNameProviderTest
name: 'UserNameProviderTest'
when: true
property var sdkVars: QtObject {
property var userGivenNicknameMap: QtObject {
property var map: ({})
}
}
- property var l10n: Helpers.fluentMock
+ property var l10n: JsHelpers.fluentMock
property var userOverrided: ({
name: 'foo',
userId: '@foo:tusooa.xyz'
})
property var userNotOverrided: ({
name: 'bar',
userId: '@bar:tusooa.xyz'
})
property var userIdOnly: ({ userId: '@bar:tusooa.xyz' })
property var providerFunctional: Kazv.UserNameProvider {}
property var providerReactive: Kazv.UserNameProvider {}
property var userComp: Component {
QtObject {
property var name: 'bar'
property var userId: '@bar:tusooa.xyz'
}
}
function init() {
sdkVars.userGivenNicknameMap.map = {
'@foo:tusooa.xyz': 'something',
};
}
function test_functional() {
compare(
providerFunctional.getName(userOverrided),
l10n.get(
'user-name-overrided', { overridedName: 'something', globalName: 'foo' }));
compare(providerFunctional.getOverridedName(userOverrided), 'something');
compare(
providerFunctional.getName(userNotOverrided),
'bar'
);
compare(providerFunctional.getOverridedName(userNotOverrided), '');
compare(
providerFunctional.getName(userIdOnly),
'@bar:tusooa.xyz'
);
}
function test_reactiveAgainstUser() {
providerReactive.user = userComp.createObject(userNameProviderTest);
compare(providerReactive.name, 'bar');
compare(providerReactive.overridedName, '');
providerReactive.user.userId = '@foo:tusooa.xyz';
compare(
providerReactive.name,
l10n.get(
'user-name-overrided', { overridedName: 'something', globalName: 'bar' }));
compare(providerReactive.overridedName, 'something');
providerReactive.user = userComp.createObject(userNameProviderTest, {
userId: '@foo:tusooa.xyz',
name: 'foo',
});
compare(
providerReactive.name,
l10n.get(
'user-name-overrided', { overridedName: 'something', globalName: 'foo' }));
compare(providerReactive.overridedName, 'something');
}
function test_reactiveAgainstOverrides() {
providerReactive.user = userComp.createObject(userNameProviderTest);
compare(providerReactive.name, 'bar');
compare(providerReactive.overridedName, '');
sdkVars.userGivenNicknameMap.map = {
'@bar:tusooa.xyz': 'something',
};
compare(
providerReactive.name,
l10n.get(
'user-name-overrided', { overridedName: 'something', globalName: 'bar' }));
compare(providerReactive.overridedName, 'something');
}
}
diff --git a/src/tests/quick-tests/tst_UserPage.qml b/src/tests/quick-tests/tst_UserPage.qml
index 34e2600..64dedf2 100644
--- a/src/tests/quick-tests/tst_UserPage.qml
+++ b/src/tests/quick-tests/tst_UserPage.qml
@@ -1,416 +1,402 @@
/*
* 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' as QmlHelpers
import 'test-helpers.js' as JsHelpers
import moe.kazv.mxc.kazv 0.0 as MK
-Item {
+QmlHelpers.TestItem {
id: upper
- width: 800
- height: 600
- property var l10n: JsHelpers.fluentMock
- 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()
+ readonly property var gnMap: upper.sdkVars.userGivenNicknameMap
property var powerLevelMapping: ({
'@mew:example.com': 100,
})
property var room: QtObject {
signal onPowerLevelsChanged()
function userPowerLevel(userId) {
return powerLevelMapping[userId];
}
property var membership: MK.MatrixRoom.Join
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()
property var setSelfName: mockHelper.promise()
}
property var userPage: null
property var userPageComp: Component {
Kazv.UserPage {
userId: '@mew:example.com'
user: ({ userId: '@mew:example.com', name: 'mew' })
room: upper.room
}
}
property var userPageWithoutName: null
property var userPageWithoutNameComp: Component {
Kazv.UserPage {
userId: '@mew:example.com'
user: ({ userId: '@mew:example.com', name: '' })
}
}
ColumnLayout {
id: layout
}
TestCase {
id: userPageTest
name: 'UserPageTest'
when: windowShown
function init() {
+ upper.matrixSdk.userId = '@foo:example.com';
+ gnMap.map = {};
mockHelper.clearAll();
room.membership = MK.MatrixRoom.Join;
userPage = userPageComp.createObject(layout);
userPageWithoutName = userPageWithoutNameComp.createObject(layout);
layout.children = [userPage, userPageWithoutName];
if (MK.KazvUtil.kfQtMajorVersion === 6) {
userPage.contentItem.clip = false;
}
}
function cleanup() {
layout.children = [];
userPage.destroy();
userPage = null;
- gnMap.map = {};
}
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.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);
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);
verify(textField.readOnly);
verify(room.setUserPowerLevel.lastArgs()[0] === '@mew:example.com');
verify(room.setUserPowerLevel.lastArgs()[1] === 50);
// the buttons are disabled until the request responded
verify(!saveButton.enabled);
verify(!findChild(userPage, 'discardPowerLevelButton').enabled);
room.setUserPowerLevel.lastRetVal().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.ensureStateEvent.retVals[1], 1000);
userPage.room.ensureStateEvent.retVals[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.setUserPowerLevel.lastRetVal(), 1000);
// Text field is not closed until the request succeeded
room.setUserPowerLevel.lastRetVal().resolve(false, {});
// text field is no longer readonly if failed
tryVerify(() => !textField.readOnly, 1000);
// show error message
verify(upper.showPassiveNotification.calledTimes());
// the buttons are enabled when the request responded
verify(saveButton.enabled);
verify(findChild(userPage, 'discardPowerLevelButton').enabled);
}
function test_banUser() {
// Ban user is only available if membership ! = "ban"
userPage.user = ({ membership: "join", userId: '@mew:example.com' });
const banButton = findChild(userPage, 'banUserButton');
verify(banButton.visible);
verify(banButton.enabled);
const reasonDialog = findChild(userPage, 'banUserReasonDialog');
verify(!reasonDialog.opened);
const textField = findChild(userPage, 'banUserReasonInput');
mouseClick(banButton);
verify(!reasonDialog.opened);
verify(textField.visible);
verify(!textField.readOnly);
textField.text = 'some reason';
reasonDialog.accept();
tryVerify(() => !reasonDialog.opened, 1000);
tryVerify(() => !banButton.enabled, 1000);
tryVerify(() => room.banUser.lastRetVal(), 1000);
verify(room.banUser.lastArgs()[0] === '@mew:example.com');
verify(room.banUser.lastArgs()[1] === 'some reason');
room.banUser.lastRetVal().resolve(true, {});
tryVerify(() => textField.text === '', 1000);
tryVerify(() => banButton.enabled, 1000);
}
function test_banUserFailure() {
// Ban user is only available if membership ! = "ban"
userPage.user = ({ membership: "join" });
const banButton = findChild(userPage, 'banUserButton');
verify(banButton.visible);
verify(banButton.enabled);
const reasonDialog = findChild(userPage, 'banUserReasonDialog');
verify(!reasonDialog.opened);
const textField = findChild(userPage, 'banUserReasonInput');
mouseClick(banButton);
verify(!reasonDialog.opened);
verify(textField.visible);
verify(!textField.readOnly);
textField.text = 'some reason';
reasonDialog.accept();
tryVerify(() => !reasonDialog.opened, 1000);
tryVerify(() => !banButton.enabled, 1000);
tryVerify(() => room.banUser.lastRetVal(), 1000);
verify(room.banUser.lastArgs()[0] === '@mew:example.com');
verify(room.banUser.lastArgs()[1] === 'some reason');
room.banUser.lastRetVal().resolve(false, {});
tryVerify(() => upper.showPassiveNotification.calledTimes(), 1000);
// text field is not cleared when failed
tryVerify(() => textField.text === 'some reason', 1000);
tryVerify(() => banButton.enabled, 1000);
}
function test_unbanUser() {
// Unban user is only available if membership == "ban"
userPage.user = ({ membership: "ban" });
const unbanButton = findChild(userPage, 'unbanUserButton');
verify(unbanButton.visible);
verify(unbanButton.enabled);
mouseClick(unbanButton);
tryVerify(() => !unbanButton.enabled, 1000);
verify(room.unbanUser.lastArgs()[0] == '@mew:example.com');
verify(room.unbanUser.lastRetVal());
room.unbanUser.lastRetVal().resolve(true, {});
tryVerify(() => unbanButton.enabled, 1000);
}
function test_unbanUserFailure() {
// Unban user is only available if membership == "ban"
userPage.user = ({ membership: "ban" });
const unbanButton = findChild(userPage, 'unbanUserButton');
verify(unbanButton.visible);
verify(unbanButton.enabled);
mouseClick(unbanButton);
tryVerify(() => !unbanButton.enabled, 1000);
verify(room.unbanUser.lastArgs()[0] == '@mew:example.com');
verify(room.unbanUser.lastRetVal());
room.unbanUser.lastRetVal().resolve(false, {});
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.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_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_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);
}
function test_showUserNameAndId() {
const nameLabel = findChild(userPage, 'userNameLabel');
const idLabel = findChild(userPage, 'userIdLabel');
verify(nameLabel.text === 'mew');
verify(idLabel.text === '@mew:example.com');
verify(idLabel.visible);
}
function test_showUserIdOnly() {
const nameLabel = findChild(userPageWithoutName, 'userNameLabel');
const idLabel = findChild(userPageWithoutName, 'userIdLabel');
verify(nameLabel.text === '@mew:example.com');
verify(!idLabel.visible);
}
function test_nonSelfName() {
const selfNameInput = findChild(userPage, 'selfNameInput');
verify(!selfNameInput.visible);
}
function test_nonJoinedRoomSelfName() {
userPage.userId = '@foo:example.com';
userPage.user.userId = '@foo:example.com';
upper.room.membership = MK.MatrixRoom.Invite;
const selfNameInput = findChild(userPage, 'selfNameInput');
verify(!selfNameInput.visible);
}
function test_selfName() {
userPage.userId = '@foo:example.com';
userPage.user.userId = '@foo:example.com';
const selfNameInput = findChild(userPage, 'selfNameInput');
verify(selfNameInput.visible);
verify(selfNameInput.text === 'mew');
selfNameInput.text = 'some others';
const button = findChild(userPage, 'saveSelfNameButton');
verify(button.enabled);
mouseClick(button);
tryVerify(() => room.setSelfName.calledTimes() === 1);
verify(!button.enabled);
verify(!selfNameInput.enabled);
verify(room.setSelfName.lastArgs()[0] === 'some others');
room.setSelfName.lastRetVal().resolve(/* succ = */ true, {});
tryVerify(() => button.enabled);
verify(selfNameInput.enabled);
}
function test_updateSelfNameFailed() {
userPage.userId = '@foo:example.com';
userPage.user.userId = '@foo:example.com';
const selfNameInput = findChild(userPage, 'selfNameInput');
selfNameInput.text = 'some others';
const button = findChild(userPage, 'saveSelfNameButton');
verify(button.enabled);
mouseClick(button);
tryVerify(() => room.setSelfName.calledTimes() === 1);
room.setSelfName.lastRetVal().resolve(/* succ = */ false, {});
tryVerify(() => button.enabled);
verify(selfNameInput.enabled);
verify(showPassiveNotification.calledTimes() === 1);
}
}
}

File Metadata

Mime Type
text/x-diff
Expires
Sun, Jan 19, 11:51 PM (1 d, 4 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55524
Default Alt Text
(169 KB)

Event Timeline