From 1614fea76a6fc1f4d70ddb14b95e3004c79365ef Mon Sep 17 00:00:00 2001 From: Kit La Touche Date: Mon, 4 Nov 2024 22:31:27 -0500 Subject: Set up framework for testing touch events This includes a change to tools/run that exposes the dev server on my local network. This change should not make it into the final form of this branch. This is so I can use actual for real touch events on my actual for real phone, hooked up for remote debugging to my computer so I can see console events etc. --- ui/routes/(app)/+layout.svelte | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'ui') diff --git a/ui/routes/(app)/+layout.svelte b/ui/routes/(app)/+layout.svelte index ae3dc6a..acaea53 100644 --- a/ui/routes/(app)/+layout.svelte +++ b/ui/routes/(app)/+layout.svelte @@ -25,6 +25,40 @@ messages.update((value) => value.setMessages(boot.messages)); } + function setTouchEvents() { + document.addEventListener("touchstart", processTouchStart); + document.addEventListener("touchmove", processTouchMove); + document.addEventListener("touchcancel", processTouchCancel); + document.addEventListener("touchend", processTouchEnd); + } + + function processTouchStart(ev) { + ev.preventDefault(); + switch (ev.touches.length) { + case 1: + console.log("touch: single"); + break; + case 2: + console.log("touch: double"); + break; + case 3: + console.log("touch: triple"); + break; + default: + console.log("touch: unsupported"); + break; + } + } + + function processTouchMove(ev) { + } + + function processTouchCancel(ev) { + } + + function processTouchEnd(ev) { + } + onMount(async () => { let response = await boot(); switch (response.status) { @@ -45,6 +79,7 @@ break; } loading = false; + setTouchEvents(); }); onDestroy(async () => { -- cgit v1.2.3 From b13b5b617022a679d93128bbee6032ea1bb31147 Mon Sep 17 00:00:00 2001 From: Kit La Touche Date: Thu, 14 Nov 2024 16:59:24 -0500 Subject: Add in start of tests --- package-lock.json | 362 +++++++++++++++++++++ package.json | 1 + .../lib/components/ChangePassword.svelte.test.js | 28 ++ .../components/CreateChannelForm.svelte.test.js | 1 + ui/tests/lib/components/Invite.svelte.test.js | 1 + ui/tests/lib/components/LogOut.svelte.test.js | 1 + ui/tests/lib/components/Message.svelte.test.js | 2 + .../lib/components/MessageInput.svelte.test.js | 2 + vite.config.js | 6 + 9 files changed, 404 insertions(+) create mode 100644 ui/tests/lib/components/ChangePassword.svelte.test.js create mode 100644 ui/tests/lib/components/CreateChannelForm.svelte.test.js create mode 100644 ui/tests/lib/components/Invite.svelte.test.js create mode 100644 ui/tests/lib/components/LogOut.svelte.test.js create mode 100644 ui/tests/lib/components/Message.svelte.test.js create mode 100644 ui/tests/lib/components/MessageInput.svelte.test.js (limited to 'ui') diff --git a/package-lock.json b/package-lock.json index ebc307d..335880f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,6 +26,7 @@ "eslint-config-prettier": "^9.1.0", "eslint-plugin-svelte": "^2.46.0", "globals": "^15.11.0", + "jsdom": "^25.0.1", "postcss": "^8.4.47", "prettier": "^3.3.3", "prettier-plugin-svelte": "^3.2.7", @@ -911,6 +912,19 @@ "acorn": ">=8.9.0" } }, + "node_modules/agent-base": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", + "integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==", + "dev": true, + "license": "MIT", + "dependencies": { + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -1374,6 +1388,33 @@ "node": ">=4" } }, + "node_modules/cssstyle": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-4.1.0.tgz", + "integrity": "sha512-h66W1URKpBS5YMI/V8PyXvTMFT8SupJ1IzoIV8IeBC/ji8WVmrO8dGlTi+2dh6whmdk6BiKJLD/ZBkhWbcg6nA==", + "dev": true, + "license": "MIT", + "dependencies": { + "rrweb-cssom": "^0.7.1" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/data-urls": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-5.0.0.tgz", + "integrity": "sha512-ZYP5VBHshaDAiVZxjbRVcFJpc+4xGgT0bK3vzy1HLN8jTO975HEbuYzZJcHoQEY5K1a0z8YayJkyVETa08eNTg==", + "dev": true, + "license": "MIT", + "dependencies": { + "whatwg-mimetype": "^4.0.0", + "whatwg-url": "^14.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/debug": { "version": "4.3.7", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", @@ -1392,6 +1433,13 @@ } } }, + "node_modules/decimal.js": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.4.3.tgz", + "integrity": "sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA==", + "dev": true, + "license": "MIT" + }, "node_modules/deep-eql": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-5.0.2.tgz", @@ -1476,6 +1524,19 @@ "dev": true, "license": "MIT" }, + "node_modules/entities": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", + "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=0.12" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, "node_modules/esbuild": { "version": "0.21.5", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.21.5.tgz", @@ -2120,6 +2181,19 @@ "node": ">= 0.4" } }, + "node_modules/html-encoding-sniffer": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-4.0.0.tgz", + "integrity": "sha512-Y22oTqIU4uuPgEemfz7NDJz6OeKf12Lsu+QC+s3BVpda64lTiMYCyGwg5ki4vFxkMwQdeZDl2adZoqUgdFuTgQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "whatwg-encoding": "^3.1.1" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/html-escaper": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", @@ -2127,6 +2201,47 @@ "dev": true, "license": "MIT" }, + "node_modules/http-proxy-agent": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-7.0.2.tgz", + "integrity": "sha512-T1gkAiYYDWYx3V5Bmyu7HcfcvL7mUrTWiM6yOfa3PIphViJ/gFPbvidQ+veqSOHci/PxBcDabeUNCzpOODJZig==", + "dev": true, + "license": "MIT", + "dependencies": { + "agent-base": "^7.1.0", + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/https-proxy-agent": { + "version": "7.0.5", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.5.tgz", + "integrity": "sha512-1e4Wqeblerz+tMKPIq2EMGiiWW1dIjZOksyHWSUm1rmuvw/how9hBHZ38lAGj5ID4Ik6EdkOw7NmWPy6LAwalw==", + "dev": true, + "license": "MIT", + "dependencies": { + "agent-base": "^7.0.2", + "debug": "4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "dev": true, + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/ignore": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", @@ -2247,6 +2362,13 @@ "node": ">=0.12.0" } }, + "node_modules/is-potential-custom-element-name": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz", + "integrity": "sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==", + "dev": true, + "license": "MIT" + }, "node_modules/is-reference": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-3.0.2.tgz", @@ -2357,6 +2479,47 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/jsdom": { + "version": "25.0.1", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-25.0.1.tgz", + "integrity": "sha512-8i7LzZj7BF8uplX+ZyOlIz86V6TAsSs+np6m1kpW9u0JWi4z/1t+FzcK1aek+ybTnAC4KhBL4uXCNT0wcUIeCw==", + "dev": true, + "license": "MIT", + "dependencies": { + "cssstyle": "^4.1.0", + "data-urls": "^5.0.0", + "decimal.js": "^10.4.3", + "form-data": "^4.0.0", + "html-encoding-sniffer": "^4.0.0", + "http-proxy-agent": "^7.0.2", + "https-proxy-agent": "^7.0.5", + "is-potential-custom-element-name": "^1.0.1", + "nwsapi": "^2.2.12", + "parse5": "^7.1.2", + "rrweb-cssom": "^0.7.1", + "saxes": "^6.0.0", + "symbol-tree": "^3.2.4", + "tough-cookie": "^5.0.0", + "w3c-xmlserializer": "^5.0.0", + "webidl-conversions": "^7.0.0", + "whatwg-encoding": "^3.1.1", + "whatwg-mimetype": "^4.0.0", + "whatwg-url": "^14.0.0", + "ws": "^8.18.0", + "xml-name-validator": "^5.0.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "canvas": "^2.11.2" + }, + "peerDependenciesMeta": { + "canvas": { + "optional": true + } + } + }, "node_modules/json-buffer": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", @@ -2700,6 +2863,13 @@ "node": ">=0.10.0" } }, + "node_modules/nwsapi": { + "version": "2.2.13", + "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.13.tgz", + "integrity": "sha512-cTGB9ptp9dY9A5VbMSe7fQBcl/tt22Vcqdq8+eN93rblOuE0aCFu4aZ2vMwct/2t+lFnosm8RkQW1I0Omb1UtQ==", + "dev": true, + "license": "MIT" + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -2790,6 +2960,19 @@ "node": ">=6" } }, + "node_modules/parse5": { + "version": "7.2.1", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.2.1.tgz", + "integrity": "sha512-BuBYQYlv1ckiPdQi/ohiivi9Sagc9JG+Ozs0r7b/0iK3sKmrb0b9FdWdBbOdx6hBCM/F9Ir82ofnBhtZOjCRPQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "entities": "^4.5.0" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -3251,6 +3434,13 @@ "fsevents": "~2.3.2" } }, + "node_modules/rrweb-cssom": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.7.1.tgz", + "integrity": "sha512-TrEMa7JGdVm0UThDJSx7ddw5nVm3UJS9o9CCIZ72B1vSyEZoziDqBYP3XIoi/12lKrJR8rE3jeFHMok2F/Mnsg==", + "dev": true, + "license": "MIT" + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -3288,6 +3478,26 @@ "node": ">=6" } }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "dev": true, + "license": "MIT" + }, + "node_modules/saxes": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/saxes/-/saxes-6.0.0.tgz", + "integrity": "sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==", + "dev": true, + "license": "ISC", + "dependencies": { + "xmlchars": "^2.2.0" + }, + "engines": { + "node": ">=v12.22.7" + } + }, "node_modules/semver": { "version": "7.6.3", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", @@ -3657,6 +3867,13 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/symbol-tree": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz", + "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==", + "dev": true, + "license": "MIT" + }, "node_modules/tailwindcss": { "version": "3.4.14", "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.14.tgz", @@ -3883,6 +4100,26 @@ "node": ">=14.0.0" } }, + "node_modules/tldts": { + "version": "6.1.60", + "resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.60.tgz", + "integrity": "sha512-TYVHm7G9NCnhgqOsFalbX6MG1Po5F4efF+tLfoeiOGQq48Oqgwcgz8upY2R1BHWa4aDrj28RYx0dkYJ63qCFMg==", + "dev": true, + "license": "MIT", + "dependencies": { + "tldts-core": "^6.1.60" + }, + "bin": { + "tldts": "bin/cli.js" + } + }, + "node_modules/tldts-core": { + "version": "6.1.60", + "resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-6.1.60.tgz", + "integrity": "sha512-XHjoxak8SFQnHnmYHb3PcnW5TZ+9ErLZemZei3azuIRhQLw4IExsVbL3VZJdHcLeNaXq6NqawgpDPpjBOg4B5g==", + "dev": true, + "license": "MIT" + }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -3906,6 +4143,32 @@ "node": ">=6" } }, + "node_modules/tough-cookie": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-5.0.0.tgz", + "integrity": "sha512-FRKsF7cz96xIIeMZ82ehjC3xW2E+O2+v11udrDYewUbszngYhsGa8z6YUMMzO9QJZzzyd0nGGXnML/TReX6W8Q==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "tldts": "^6.1.32" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/tr46": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.0.0.tgz", + "integrity": "sha512-tk2G5R2KRwBd+ZN0zaEXpmzdKyOYksXwywulIX95MBODjSzMIuQnQ3m8JxgbhnL1LeVo7lqQKsYa1O3Htl7K5g==", + "dev": true, + "license": "MIT", + "dependencies": { + "punycode": "^2.3.1" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/ts-interface-checker": { "version": "0.1.13", "resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz", @@ -4141,6 +4404,66 @@ } } }, + "node_modules/w3c-xmlserializer": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-5.0.0.tgz", + "integrity": "sha512-o8qghlI8NZHU1lLPrpi2+Uq7abh4GGPpYANlalzWxyWteJOCsr/P+oPBA49TOLu5FTZO4d3F9MnWJfiMo4BkmA==", + "dev": true, + "license": "MIT", + "dependencies": { + "xml-name-validator": "^5.0.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + } + }, + "node_modules/whatwg-encoding": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-3.1.1.tgz", + "integrity": "sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "iconv-lite": "0.6.3" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/whatwg-mimetype": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-4.0.0.tgz", + "integrity": "sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/whatwg-url": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.0.0.tgz", + "integrity": "sha512-1lfMEm2IEr7RIV+f4lUNPOqfFL+pO+Xw3fJSqmjX9AbXcXcYOkCe1P6+9VBZB6n94af16NfZf+sSk0JCBZC9aw==", + "dev": true, + "license": "MIT", + "dependencies": { + "tr46": "^5.0.0", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -4279,6 +4602,45 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/ws": { + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", + "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, + "node_modules/xml-name-validator": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-5.0.0.tgz", + "integrity": "sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18" + } + }, + "node_modules/xmlchars": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", + "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==", + "dev": true, + "license": "MIT" + }, "node_modules/yaml": { "version": "1.10.2", "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz", diff --git a/package.json b/package.json index 7e36802..18a80f4 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "eslint-config-prettier": "^9.1.0", "eslint-plugin-svelte": "^2.46.0", "globals": "^15.11.0", + "jsdom": "^25.0.1", "postcss": "^8.4.47", "prettier": "^3.3.3", "prettier-plugin-svelte": "^3.2.7", diff --git a/ui/tests/lib/components/ChangePassword.svelte.test.js b/ui/tests/lib/components/ChangePassword.svelte.test.js new file mode 100644 index 0000000..6e0e652 --- /dev/null +++ b/ui/tests/lib/components/ChangePassword.svelte.test.js @@ -0,0 +1,28 @@ +// async onsubmit(event) +// +// Example: +/* */ +import { flushSync, mount, unmount } from 'svelte'; +import { expect, test } from 'vitest'; +import ChangePassword from '$lib/components/ChangePassword.svelte'; + + +test('ChangePassword', () => { + // Instantiate the component using Svelte's `mount` API + const component = mount(ChangePassword, { + target: document.body, // `document` exists because of jsdom + props: { initial: 0 } + }); + + expect(document.body.innerHTML).toBe(''); + + // Click the button, then flush the changes so you can synchronously write expectations + document.body.querySelector('button').click(); + flushSync(); + + expect(document.body.innerHTML).toBe(''); + + // Remove the component from the DOM + unmount(component); +}); +/* */ diff --git a/ui/tests/lib/components/CreateChannelForm.svelte.test.js b/ui/tests/lib/components/CreateChannelForm.svelte.test.js new file mode 100644 index 0000000..0380e01 --- /dev/null +++ b/ui/tests/lib/components/CreateChannelForm.svelte.test.js @@ -0,0 +1 @@ +// async handleSubmit(event) diff --git a/ui/tests/lib/components/Invite.svelte.test.js b/ui/tests/lib/components/Invite.svelte.test.js new file mode 100644 index 0000000..e4383cc --- /dev/null +++ b/ui/tests/lib/components/Invite.svelte.test.js @@ -0,0 +1 @@ +// async onsubmit(event) diff --git a/ui/tests/lib/components/LogOut.svelte.test.js b/ui/tests/lib/components/LogOut.svelte.test.js new file mode 100644 index 0000000..e4383cc --- /dev/null +++ b/ui/tests/lib/components/LogOut.svelte.test.js @@ -0,0 +1 @@ +// async onsubmit(event) diff --git a/ui/tests/lib/components/Message.svelte.test.js b/ui/tests/lib/components/Message.svelte.test.js new file mode 100644 index 0000000..d29a371 --- /dev/null +++ b/ui/tests/lib/components/Message.svelte.test.js @@ -0,0 +1,2 @@ +// onDelete(event) +// onmouseleave() diff --git a/ui/tests/lib/components/MessageInput.svelte.test.js b/ui/tests/lib/components/MessageInput.svelte.test.js new file mode 100644 index 0000000..7c7f9aa --- /dev/null +++ b/ui/tests/lib/components/MessageInput.svelte.test.js @@ -0,0 +1,2 @@ +// async onSubmit(event) +// onKeyDown(event) diff --git a/vite.config.js b/vite.config.js index 61ba597..8d6866d 100644 --- a/vite.config.js +++ b/vite.config.js @@ -3,6 +3,12 @@ import { defineConfig } from 'vite'; export default defineConfig({ plugins: [sveltekit()], + test: { + // If you are testing components client-side, you need to setup a DOM environment. + // If not all your files should have this environment, you can use a + // `// @vitest-environment jsdom` comment at the top of the test files instead. + environment: 'jsdom' + }, // Tell Vitest to use the `browser` entry points in `package.json` files, // even though it's running in Node resolve: process.env.VITEST ? { conditions: ['browser'] } : undefined, -- cgit v1.2.3 From 3a89459f8b48449b341469776a37d8b225e956f2 Mon Sep 17 00:00:00 2001 From: Kit La Touche Date: Thu, 14 Nov 2024 23:28:19 -0500 Subject: Stub in tests --- .../lib/components/ChangePassword.svelte.test.js | 45 +++++++++++++--------- .../components/CreateChannelForm.svelte.test.js | 7 ++++ ui/tests/lib/components/Invite.svelte.test.js | 7 ++++ ui/tests/lib/components/LogOut.svelte.test.js | 7 ++++ ui/tests/lib/components/Message.svelte.test.js | 7 ++++ .../lib/components/MessageInput.svelte.test.js | 7 ++++ 6 files changed, 61 insertions(+), 19 deletions(-) (limited to 'ui') diff --git a/ui/tests/lib/components/ChangePassword.svelte.test.js b/ui/tests/lib/components/ChangePassword.svelte.test.js index 6e0e652..09aa992 100644 --- a/ui/tests/lib/components/ChangePassword.svelte.test.js +++ b/ui/tests/lib/components/ChangePassword.svelte.test.js @@ -1,28 +1,35 @@ -// async onsubmit(event) -// -// Example: -/* */ import { flushSync, mount, unmount } from 'svelte'; -import { expect, test } from 'vitest'; +import { afterEach, describe, beforeEach, expect, test, vi } from 'vitest'; import ChangePassword from '$lib/components/ChangePassword.svelte'; +import axios from 'axios'; +vi.mock('axios'); -test('ChangePassword', () => { - // Instantiate the component using Svelte's `mount` API - const component = mount(ChangePassword, { - target: document.body, // `document` exists because of jsdom - props: { initial: 0 } - }); +describe('ChangePassword', () => { + afterEach(() => { + vi.restoreAllMocks(); + }); - expect(document.body.innerHTML).toBe(''); + test('onsubmit happy path', async () => { + axios.post.mockResolvedValue({ status: 200 }); - // Click the button, then flush the changes so you can synchronously write expectations - document.body.querySelector('button').click(); - flushSync(); + // Instantiate the component using Svelte's `mount` API + const component = mount(ChangePassword, { + target: document.body, // `document` exists because of jsdom + }); + flushSync(); - expect(document.body.innerHTML).toBe(''); + // Set value in all three inputs at once: + const inputs = document.body.querySelectorAll('input[type=password]'); + inputs.value = 'pass'; + // Click the button, then flush the changes so you can synchronously write expectations + document.body.querySelector('button[type=submit]').click(); + flushSync(); - // Remove the component from the DOM - unmount(component); + // expect(axios.post).toHaveBeenCalledWith('/password', { password: 'pass', to: 'pass' }); + expect(Array.from(inputs.values()).map((i) => i.value)).toEqual(['', '', '']); + + // Remove the component from the DOM + unmount(component); + }); }); -/* */ diff --git a/ui/tests/lib/components/CreateChannelForm.svelte.test.js b/ui/tests/lib/components/CreateChannelForm.svelte.test.js index 0380e01..31f7462 100644 --- a/ui/tests/lib/components/CreateChannelForm.svelte.test.js +++ b/ui/tests/lib/components/CreateChannelForm.svelte.test.js @@ -1 +1,8 @@ // async handleSubmit(event) +import { describe, expect, test } from 'vitest'; + +describe('CreateChannelForm', () => { + test('stub', async () => { + expect(true).toBeTruthy(); + }); +}); diff --git a/ui/tests/lib/components/Invite.svelte.test.js b/ui/tests/lib/components/Invite.svelte.test.js index e4383cc..5d5742e 100644 --- a/ui/tests/lib/components/Invite.svelte.test.js +++ b/ui/tests/lib/components/Invite.svelte.test.js @@ -1 +1,8 @@ // async onsubmit(event) +import { describe, expect, test } from 'vitest'; + +describe('Invite', () => { + test('stub', async () => { + expect(true).toBeTruthy(); + }); +}); diff --git a/ui/tests/lib/components/LogOut.svelte.test.js b/ui/tests/lib/components/LogOut.svelte.test.js index e4383cc..65d78a9 100644 --- a/ui/tests/lib/components/LogOut.svelte.test.js +++ b/ui/tests/lib/components/LogOut.svelte.test.js @@ -1 +1,8 @@ // async onsubmit(event) +import { describe, expect, test } from 'vitest'; + +describe('LogOut', () => { + test('stub', async () => { + expect(true).toBeTruthy(); + }); +}); diff --git a/ui/tests/lib/components/Message.svelte.test.js b/ui/tests/lib/components/Message.svelte.test.js index d29a371..2ca0b85 100644 --- a/ui/tests/lib/components/Message.svelte.test.js +++ b/ui/tests/lib/components/Message.svelte.test.js @@ -1,2 +1,9 @@ // onDelete(event) // onmouseleave() +import { describe, expect, test } from 'vitest'; + +describe('Message', () => { + test('stub', async () => { + expect(true).toBeTruthy(); + }); +}); diff --git a/ui/tests/lib/components/MessageInput.svelte.test.js b/ui/tests/lib/components/MessageInput.svelte.test.js index 7c7f9aa..597f0c3 100644 --- a/ui/tests/lib/components/MessageInput.svelte.test.js +++ b/ui/tests/lib/components/MessageInput.svelte.test.js @@ -1,2 +1,9 @@ // async onSubmit(event) // onKeyDown(event) +import { describe, expect, test } from 'vitest'; + +describe('MessageInput', () => { + test('stub', async () => { + expect(true).toBeTruthy(); + }); +}); -- cgit v1.2.3 From 122ecb5769e20173c99033ade0057d38e12cb384 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Fri, 15 Nov 2024 01:18:41 -0500 Subject: HTML-ify message bodies once, on receipt, and not every time the message is rendered. ~16% of the `hi development` channel's rendering time was taken up on this. --- ui/lib/components/Message.svelte | 6 +----- ui/lib/components/MessageRun.svelte | 4 ++-- ui/lib/store/messages.svelte.js | 6 +++++- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'ui') diff --git a/ui/lib/components/Message.svelte b/ui/lib/components/Message.svelte index 0c8eeec..fddeecd 100644 --- a/ui/lib/components/Message.svelte +++ b/ui/lib/components/Message.svelte @@ -1,15 +1,11 @@ @@ -113,12 +100,23 @@ {/if}