Changeset View
Changeset View
Standalone View
Standalone View
src/tests/quick-tests/tst_UserPage.qml
| Show All 36 Lines | property var powerLevelMapping: ({ | ||||
| '@mew:example.com': 100, | '@mew:example.com': 100, | ||||
| }) | }) | ||||
| property var room: QtObject { | property var room: QtObject { | ||||
| signal onPowerLevelsChanged() | signal onPowerLevelsChanged() | ||||
| function userPowerLevel(userId) { | function userPowerLevel(userId) { | ||||
| return powerLevelMapping[userId]; | return powerLevelMapping[userId]; | ||||
| } | } | ||||
| property var membership: MK.MatrixRoom.Join | |||||
| property var setUserPowerLevel: mockHelper.promise() | property var setUserPowerLevel: mockHelper.promise() | ||||
| property var ensureStateEvent: mockHelper.promise() | property var ensureStateEvent: mockHelper.promise() | ||||
| property var kickUser: mockHelper.promise() | property var kickUser: mockHelper.promise() | ||||
| property var banUser: mockHelper.promise() | property var banUser: mockHelper.promise() | ||||
| property var unbanUser: mockHelper.promise() | property var unbanUser: mockHelper.promise() | ||||
| property var setSelfName: mockHelper.promise() | |||||
| } | } | ||||
| property var userPage: null | property var userPage: null | ||||
| property var userPageComp: Component { | property var userPageComp: Component { | ||||
| Kazv.UserPage { | Kazv.UserPage { | ||||
| userId: '@mew:example.com' | userId: '@mew:example.com' | ||||
| user: ({ userId: '@mew:example.com', name: 'mew' }) | user: ({ userId: '@mew:example.com', name: 'mew' }) | ||||
| room: upper.room | room: upper.room | ||||
| Show All 14 Lines | Item { | ||||
| TestCase { | TestCase { | ||||
| id: userPageTest | id: userPageTest | ||||
| name: 'UserPageTest' | name: 'UserPageTest' | ||||
| when: windowShown | when: windowShown | ||||
| function init() { | function init() { | ||||
| mockHelper.clearAll(); | mockHelper.clearAll(); | ||||
| room.membership = MK.MatrixRoom.Join; | |||||
| userPage = userPageComp.createObject(layout); | userPage = userPageComp.createObject(layout); | ||||
| userPageWithoutName = userPageWithoutNameComp.createObject(layout); | userPageWithoutName = userPageWithoutNameComp.createObject(layout); | ||||
| layout.children = [userPage, userPageWithoutName]; | layout.children = [userPage, userPageWithoutName]; | ||||
| if (MK.KazvUtil.kfQtMajorVersion === 6) { | if (MK.KazvUtil.kfQtMajorVersion === 6) { | ||||
| userPage.contentItem.clip = false; | userPage.contentItem.clip = false; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 268 Lines • ▼ Show 20 Lines | function test_showUserNameAndId() { | ||||
| verify(idLabel.visible); | verify(idLabel.visible); | ||||
| } | } | ||||
| function test_showUserIdOnly() { | function test_showUserIdOnly() { | ||||
| const nameLabel = findChild(userPageWithoutName, 'userNameLabel'); | const nameLabel = findChild(userPageWithoutName, 'userNameLabel'); | ||||
| const idLabel = findChild(userPageWithoutName, 'userIdLabel'); | const idLabel = findChild(userPageWithoutName, 'userIdLabel'); | ||||
| verify(nameLabel.text === '@mew:example.com'); | verify(nameLabel.text === '@mew:example.com'); | ||||
| verify(!idLabel.visible); | 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); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||