Skip to content

Commit ebb5dfb

Browse files
authored
Merge pull request #2034 from maxberger/master
UI: Stability improvements
2 parents 6c7987a + 01b9df4 commit ebb5dfb

File tree

4 files changed

+96
-7
lines changed

4 files changed

+96
-7
lines changed

integ_tests/test_download.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# This file is part of Radicale - CalDAV and CardDAV server
2+
# Copyright © 2026-2026 Max Berger <max@berger.name>
3+
#
4+
# This library is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# This library is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with Radicale. If not, see <http://www.gnu.org/licenses/>.
16+
17+
"""
18+
Integration tests for download page
19+
"""
20+
21+
import pathlib
22+
from typing import Any, Generator
23+
24+
import pytest
25+
from playwright.sync_api import Page
26+
27+
from integ_tests.common import login, start_radicale_server
28+
29+
30+
@pytest.fixture
31+
def radicale_server(tmp_path: pathlib.Path) -> Generator[str, Any, None]:
32+
yield from start_radicale_server(tmp_path)
33+
34+
35+
def test_download_addressbook(page: Page, radicale_server: str) -> None:
36+
login(page, radicale_server)
37+
page.click('.fabcontainer a[data-name="new"]')
38+
39+
# an address book is created
40+
page.select_option('#createcollectionscene select[data-name="type"]', "ADDRESSBOOK")
41+
page.locator('#createcollectionscene input[data-name="displayname"]').fill("Abname")
42+
page.click('#createcollectionscene button[data-name="submit"]')
43+
44+
# Start waiting for the download
45+
with page.expect_download() as download_info:
46+
# Perform the action that initiates download
47+
page.hover("article:not(.hidden)")
48+
page.click('article:not(.hidden) a[data-name="download"]')
49+
50+
download = download_info.value
51+
assert download.suggested_filename == "Abname.vcf"
52+
53+
54+
def test_download_calendar_uses_displayname_ics(
55+
page: Page, radicale_server: str
56+
) -> None:
57+
login(page, radicale_server)
58+
page.click('.fabcontainer a[data-name="new"]')
59+
60+
# a calendar is created
61+
page.select_option('#createcollectionscene select[data-name="type"]', "CALENDAR")
62+
page.locator('#createcollectionscene input[data-name="displayname"]').fill(
63+
"Calname"
64+
)
65+
page.click('#createcollectionscene button[data-name="submit"]')
66+
67+
# Start waiting for the download
68+
with page.expect_download() as download_info:
69+
# Perform the action that initiates download
70+
page.hover("article:not(.hidden)")
71+
page.click('article:not(.hidden) a[data-name="download"]')
72+
73+
download = download_info.value
74+
assert download.suggested_filename == "Calname.ics"

radicale/web/internal_data/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ <h1>Sign in</h1>
5454
</section>
5555

5656
<section id="collectionsscene" class="hidden">
57+
<div class="error hidden" data-name="collectionsscene_error"></div>
5758
<div class="fabcontainer">
5859
<a href="" class="green" data-name="new" title="Create a new addressbook or calendar">
5960
<img src="css/icons/new.svg" class="icon" alt="">

radicale/web/internal_data/js/scenes/CollectionsScene.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { delete_collection } from "../api/api.js";
2323
import { SERVER } from "../constants.js";
2424
import { Collection, CollectionType } from "../models/collection.js";
2525
import { collectionsCache } from "../utils/collections_cache.js";
26+
import { ErrorHandler } from "../utils/error.js";
2627
import { bytesToHumanReadable } from "../utils/misc.js";
2728
import { CreateEditCollectionScene } from "./CreateEditCollectionScene.js";
2829
import { DeleteConfirmationScene } from "./DeleteConfirmationScene.js";
@@ -48,8 +49,10 @@ export class CollectionsScene {
4849
/** @type {HTMLElement} */ let new_btn = html_scene.querySelector("[data-name=new]");
4950
/** @type {HTMLElement} */ let upload_btn = html_scene.querySelector("[data-name=upload]");
5051
/** @type {HTMLElement} */ let incomingshares_btn = html_scene.querySelector("[data-name=incomingshares]");
52+
/** @type {HTMLElement} */ let error_div = html_scene.querySelector("[data-name=collectionsscene_error]");
5153

5254
/** @type {Array<HTMLElement>} */ let nodes = [];
55+
let errorHandler = new ErrorHandler(error_div);
5356

5457
function onnew() {
5558
try {
@@ -126,13 +129,18 @@ export class CollectionsScene {
126129
/**
127130
* @param {any[]} collections
128131
* @param {import("../api/sharing.js").Share[]} shares
132+
* @param {boolean} clear_error
129133
*/
130-
function show_collections(collections, shares) {
134+
function show_collections(collections, shares, clear_error) {
131135
/** @type {HTMLElement} */ let navBar = document.querySelector("#logoutview");
132136
let heightOfNavBar = navBar.offsetHeight + "px";
133137
html_scene.style.marginTop = heightOfNavBar;
134138
html_scene.style.height = "calc(100vh - " + heightOfNavBar + ")";
135139

140+
if (clear_error) {
141+
errorHandler.clearError();
142+
}
143+
136144
// Clear old nodes
137145
nodes.forEach(function (node) {
138146
node.parentNode.removeChild(node);
@@ -223,14 +231,18 @@ export class CollectionsScene {
223231
});
224232
}
225233

234+
this.errorwrapper = function (/** @type {string} */ error) {
235+
errorHandler.setError(error);
236+
if (onerror) onerror(error);
237+
};
226238

227239
this.show = function () {
228240
html_scene.classList.remove("hidden");
229241
new_btn.onclick = onnew;
230242
upload_btn.onclick = onupload;
231243
incomingshares_btn.onclick = onincomingshares;
232-
collectionsCache.getChildCollections(user, password, principal_collection, onerror, show_collections);
233-
collectionsCache.getServerFeatures(user, password, null, maybe_enable_sharing_options);
244+
collectionsCache.getChildCollections(user, password, principal_collection, this.errorwrapper, show_collections);
245+
collectionsCache.getServerFeatures(user, password, this.errorwrapper, maybe_enable_sharing_options);
234246
};
235247
this.hide = function () {
236248
html_scene.classList.add("hidden");

radicale/web/internal_data/js/utils/collections_cache.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { is_current_scene, pop_scene, push_scene } from "../scenes/scene_manager
2626

2727
class CollectionsCache {
2828
constructor() {
29-
this.child_collections = null;
29+
/** @type {?Array<import("../models/collection.js").Collection>} */ this.child_collections = null;
3030
/** @type {?Array<import("../api/sharing.js").Share>} */ this.incoming_shares = null;
3131
this.server_features = null;
3232
/** @type {?XMLHttpRequest} */ this.collections_req = null;
@@ -52,11 +52,11 @@ class CollectionsCache {
5252
* @param {string} password
5353
* @param {import("../models/collection.js").Collection} principal_collection
5454
* @param {function(string):void} onerror
55-
* @param {function(Array<import("../models/collection.js").Collection>, Array<import("../api/sharing.js").Share>):void} displayData
55+
* @param {function(Array<import("../models/collection.js").Collection>, Array<import("../api/sharing.js").Share>, boolean):void} displayData
5656
*/
5757
getChildCollections(user, password, principal_collection, onerror, displayData) {
5858
if (this.child_collections !== null && this.incoming_shares !== null) {
59-
displayData(this.child_collections, this.incoming_shares);
59+
displayData(this.child_collections, this.incoming_shares, false);
6060
return;
6161
}
6262

@@ -73,11 +73,13 @@ class CollectionsCache {
7373
}
7474
if (error) {
7575
onerror(error);
76+
this.child_collections = [];
77+
this.incoming_shares = [];
7678
pop_scene();
7779
} else if (collections !== null && shares !== null) {
7880
this.child_collections = collections;
7981
this.incoming_shares = shares;
80-
displayData(this.child_collections, this.incoming_shares);
82+
displayData(this.child_collections, this.incoming_shares, true);
8183
pop_scene();
8284
}
8385
};

0 commit comments

Comments
 (0)