daydream

A small matrix web client written in rust
git clone git://archive.git.mtrnord.blog/daydream-mx/daydream.git
Log | Files | Refs | README | LICENSE

commit 1a497bd457897955f0687e7ab8c83cd25f81d05c
parent b80a3ffacc25c79e3411c4226ae7a09a2c0184ae
Author: Marcel <mtrnord1@gmail.com>
Date:   Sat, 13 Jun 2020 23:41:15 +0200

Add roomlist tests and restructe some test parts

Took 32 minutes

Diffstat:
Mcypress/integration/login_spec.js | 226+++----------------------------------------------------------------------------
Acypress/integration/matrix-fake-api.js | 191+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acypress/integration/roomlist_spec.js | 41+++++++++++++++++++++++++++++++++++++++++
Acypress/integration/utils.js | 21+++++++++++++++++++++
4 files changed, 261 insertions(+), 218 deletions(-)

diff --git a/cypress/integration/login_spec.js b/cypress/integration/login_spec.js @@ -1,3 +1,5 @@ +import {fake_matrix_api_handler} from './matrix-fake-api'; +import {login} from "./utils"; describe('LoginPage', () => { beforeEach(function () { @@ -7,229 +9,17 @@ describe('LoginPage', () => { onBeforeLoad(win) { let fetch = win.fetch; cy.stub(win, 'fetch') - .callsFake((arg) => { - if (typeof arg === "string") { - console.log("REQUESTED: " + arg); - if (arg == 'daydream.wasm') { - return fetch(arg); - } - } else if (typeof arg === "object") { - console.log("REQUESTED: ", arg); - if (arg["url"] === "http://localhost:8448/_matrix/client/r0/login") { - console.log("handling login"); - return new Promise((resolve, reject) => { - const resp_data = { - "user_id": "@carl:example.com", - "access_token": "123456", - "device_id": "KCZFUCGSLZ" - }; - const resp = new Blob([JSON.stringify(resp_data, null, 2)], {type: 'application/json'}); - - const init = { - "status": 200, - "statusText": "Ok", - headers: {'Content-type': 'application/json'} - }; - const response = new win.Response(resp, init); - Object.defineProperty(response, "url", {value: arg["url"]}); - resolve(response) - } - ) - } else { - console.log("handling sync"); - return new Promise((resolve, reject) => { - const resp_data = { - "next_batch": "s72595_4483_1934", - "rooms": { - "join": { - "!726s6s6q:example.com": { - "unread_notifications": { - "highlight_count": 0, - "notification_count": 0, - }, - "summary": { - "m.heroes": [ - "@alice:example.com", - "@bob:example.com" - ], - "m.joined_member_count": 2, - "m.invited_member_count": 0 - }, - "state": { - "events": [ - { - "content": { - "membership": "join", - "avatar_url": "mxc://example.org/SEsfnsuifSDFSSEF", - "displayname": "Alice Margatroid" - }, - "type": "m.room.member", - "event_id": "$143273582443PhrSn:example.org", - "room_id": "!726s6s6q:example.com", - "sender": "@example:example.org", - "origin_server_ts": 1432735824653, - "unsigned": { - "age": 1234 - }, - "state_key": "@alice:example.org" - } - ] - }, - "timeline": { - "events": [ - { - "content": { - "membership": "join", - "avatar_url": "mxc://example.org/SEsfnsuifSDFSSEF", - "displayname": "Alice Margatroid" - }, - "type": "m.room.member", - "event_id": "$143273582443PhrSn:example.org", - "room_id": "!726s6s6q:example.com", - "sender": "@example:example.org", - "origin_server_ts": 1432735824653, - "unsigned": { - "age": 1234 - }, - "state_key": "@alice:example.org" - }, - { - "content": { - "body": "This is an example text message", - "msgtype": "m.text", - "format": "org.matrix.custom.html", - "formatted_body": "<b>This is an example text message</b>" - }, - "type": "m.room.message", - "event_id": "$143273582443PhrSn:example.org", - "room_id": "!726s6s6q:example.com", - "sender": "@example:example.org", - "origin_server_ts": 1432735824653, - "unsigned": { - "age": 1234 - } - } - ], - "limited": true, - "prev_batch": "t34-23535_0_0" - }, - "ephemeral": { - "events": [ - { - "content": { - "user_ids": [ - "@alice:matrix.org", - "@bob:example.com" - ] - }, - "type": "m.typing", - "room_id": "!jEsUZKDJdhlrceRyVU:example.org" - } - ] - }, - "account_data": { - "events": [ - { - "content": { - "tags": { - "u.work": { - "order": 0.9 - } - } - }, - "type": "m.tag" - }, - { - "type": "org.example.custom.room.config", - "content": { - "custom_config_key": "custom_config_value" - } - } - ] - } - } - }, - "invite": { - "!696r7674:example.com": { - "invite_state": { - "events": [ - { - "sender": "@alice:example.com", - "type": "m.room.name", - "state_key": "", - "content": { - "name": "My Room Name" - } - }, - { - "sender": "@alice:example.com", - "type": "m.room.member", - "state_key": "@bob:example.com", - "content": { - "membership": "invite" - } - } - ] - } - } - }, - "leave": {} - } - }; - const resp = new Blob([JSON.stringify(resp_data, null, 2)], {type: 'application/json'}); - - const init = { - "status": 200, - "statusText": "Ok", - headers: {'Content-type': 'application/json'} - }; - const response = new win.Response(resp, init); - Object.defineProperty(response, "url", {value: arg["url"]}); - resolve(response) - } - ) - } - } - - }); + .callsFake(args => fake_matrix_api_handler(args, fetch, win)); }, }) }) - /* beforeEach(function () { - cy.server(); - - cy.fixture('login.json').as('loginJSON') - cy.route('POST', '/_matrix/client/r0/login', '@loginJSON') - cy.route({ - method: 'OPTIONS', // Route all OPTION requests - url: '/_matrix/*', - response: {} - }); - - // We use cy.visit({onBeforeLoad: ...}) to spy on - // window.fetch before any app code runs - cy.visit('/') - - })*/ it('Does login', () => { - cy.get('form#login_form').within(() => { - // Set homeserverurl - const homeserver_url = "http://localhost:8448"; - cy.get('input#homeserver').type(homeserver_url); - cy.get('input#homeserver').should('have.value', homeserver_url); - - // Set username - const username = "@carl:example.com"; - cy.get('input#username').type(username); - cy.get('input#username').should('have.value', username); - - // Set password - const password = "12345"; - cy.get('input#password').type(username); - cy.get('input#password').should('have.value', username); - }); - cy.get('form#login_form').submit(); + login() + // First show spinner + cy.get('span[uk-spinner]').should('be.visible'); + // Now it should be gone and instead we see the roomlist + cy.get('span[uk-spinner]').should('not.be.visible'); cy.get('ul.scrollable').should('be.visible'); }) }) diff --git a/cypress/integration/matrix-fake-api.js b/cypress/integration/matrix-fake-api.js @@ -0,0 +1,191 @@ +const fake_matrix_api_handler = (arg, fetch, win) => { + if (typeof arg === "string") { + console.log("REQUESTED: " + arg); + if (arg == 'daydream.wasm') { + return fetch(arg); + } + } else if (typeof arg === "object") { + console.log("REQUESTED: ", arg); + if (arg["url"] === "http://localhost:8448/_matrix/client/r0/login") { + console.log("handling login"); + return new Promise((resolve, reject) => { + const resp_data = { + "user_id": "@carl:example.com", + "access_token": "123456", + "device_id": "KCZFUCGSLZ" + }; + const resp = new Blob([JSON.stringify(resp_data, null, 2)], {type: 'application/json'}); + + const init = { + "status": 200, + "statusText": "Ok", + headers: {'Content-type': 'application/json'} + }; + const response = new win.Response(resp, init); + Object.defineProperty(response, "url", {value: arg["url"]}); + resolve(response) + } + ) + } else { + // TODO handle different test states + console.log("handling sync"); + return new Promise((resolve, reject) => { + const resp_data = { + "next_batch": "s72595_4483_1934", + "rooms": { + "join": { + "!726s6s6q:example.com": { + "unread_notifications": { + "highlight_count": 0, + "notification_count": 0, + }, + "summary": { + "m.heroes": [ + "@alice:example.com", + "@bob:example.com" + ], + "m.joined_member_count": 2, + "m.invited_member_count": 0 + }, + "state": { + "events": [ + { + "content": { + "membership": "join", + "avatar_url": "mxc://example.org/SEsfnsuifSDFSSEF", + "displayname": "Alice Margatroid" + }, + "type": "m.room.member", + "event_id": "$143273582443PhrSn:example.org", + "room_id": "!726s6s6q:example.com", + "sender": "@example:example.org", + "origin_server_ts": 1432735824653, + "unsigned": { + "age": 1234 + }, + "state_key": "@alice:example.org" + } + ] + }, + "timeline": { + "events": [ + { + "content": { + "membership": "join", + "avatar_url": "mxc://example.org/SEsfnsuifSDFSSEF", + "displayname": "Alice Margatroid" + }, + "type": "m.room.member", + "event_id": "$143273582443PhrSn:example.org", + "room_id": "!726s6s6q:example.com", + "sender": "@example:example.org", + "origin_server_ts": 1432735824653, + "unsigned": { + "age": 1234 + }, + "state_key": "@alice:example.org" + }, + { + "content": { + "body": "This is an example text message", + "msgtype": "m.text", + "format": "org.matrix.custom.html", + "formatted_body": "<b>This is an example text message</b>" + }, + "type": "m.room.message", + "event_id": "$143273582443PhrSn:example.org", + "room_id": "!726s6s6q:example.com", + "sender": "@example:example.org", + "origin_server_ts": 1432735824653, + "unsigned": { + "age": 1234 + } + } + ], + "limited": true, + "prev_batch": "t34-23535_0_0" + }, + "ephemeral": { + "events": [ + { + "content": { + "user_ids": [ + "@alice:matrix.org", + "@bob:example.com" + ] + }, + "type": "m.typing", + "room_id": "!jEsUZKDJdhlrceRyVU:example.org" + } + ] + }, + "account_data": { + "events": [ + { + "content": { + "tags": { + "u.work": { + "order": 0.9 + } + } + }, + "type": "m.tag" + }, + { + "type": "org.example.custom.room.config", + "content": { + "custom_config_key": "custom_config_value" + } + } + ] + } + } + }, + "invite": { + "!696r7674:example.com": { + "invite_state": { + "events": [ + { + "sender": "@alice:example.com", + "type": "m.room.name", + "state_key": "", + "content": { + "name": "My Room Name" + } + }, + { + "sender": "@alice:example.com", + "type": "m.room.member", + "state_key": "@bob:example.com", + "content": { + "membership": "invite" + } + } + ] + } + } + }, + "leave": {} + } + }; + const resp = new Blob([JSON.stringify(resp_data, null, 2)], {type: 'application/json'}); + + const init = { + "status": 200, + "statusText": "Ok", + headers: {'Content-type': 'application/json'} + }; + const response = new win.Response(resp, init); + Object.defineProperty(response, "url", {value: arg["url"]}); + // Lets wait 2 sec to get a chance to see a spinner + setTimeout(() => { + resolve(response) + }, 2000); + } + ) + } + } + +} +export {fake_matrix_api_handler} +export default fake_matrix_api_handler diff --git a/cypress/integration/roomlist_spec.js b/cypress/integration/roomlist_spec.js @@ -0,0 +1,41 @@ +import {fake_matrix_api_handler} from "./matrix-fake-api"; +import {login} from "./utils"; + +describe('RoomList', () => { + const name_of_user = "Alice Margatroid"; + beforeEach(function () { + // We use cy.visit({onBeforeLoad: ...}) to stub + // window.fetch before any app code runs + cy.visit('/', { + onBeforeLoad(win) { + let fetch = win.fetch; + cy.stub(win, 'fetch') + .callsFake(args => fake_matrix_api_handler(args, fetch, win)); + }, + }) + }); + + it("does allow clicking a room", () => { + login(); + cy.get('ul.scrollable').contains(name_of_user).click(); + + cy.log('check if the room title is shown after click'); + cy.get('h1').contains(name_of_user).should('be.visible'); + }); + + it("should allow searching", () => { + login(); + + cy.log('check if the room is not shown if anything else is in the search'); + cy.get('input.uk-search-input').clear().type("blub"); + cy.get("ul.scrollable").contains(name_of_user).should("not.exist"); + + cy.log('check if the room is shown if a part of the name is in the search'); + cy.get('input.uk-search-input').clear().type("Alice"); + cy.get("ul.scrollable").contains(name_of_user).should("exist").should("be.visible"); + + cy.log('check if the room is shown if the full name is in the search'); + cy.get('input.uk-search-input').clear().type(name_of_user); + cy.get("ul.scrollable").contains(name_of_user).should("exist").should("be.visible"); + }); +}) diff --git a/cypress/integration/utils.js b/cypress/integration/utils.js @@ -0,0 +1,21 @@ +const login = () => { + cy.get('form#login_form').within(() => { + // Set homeserverurl + const homeserver_url = "http://localhost:8448"; + cy.get('input#homeserver').type(homeserver_url); + cy.get('input#homeserver').should('have.value', homeserver_url); + + // Set username + const username = "@carl:example.com"; + cy.get('input#username').type(username); + cy.get('input#username').should('have.value', username); + + // Set password + const password = "12345"; + cy.get('input#password').type(username); + cy.get('input#password').should('have.value', username); + }); + cy.get('form#login_form').submit(); +} + +export {login}