Image support!
Some checks failed
Test / test (push) Failing after 5s
Build and Deploy Nuxt / build (push) Successful in 1m46s

This commit is contained in:
2026-11-20 19:10:28 +01:00
parent d61659cfdd
commit fe662bb351
11 changed files with 119 additions and 21 deletions

View File

@@ -61,6 +61,14 @@ test("every named note, actor, item and map becomes a suggestion, sorted by labe
]);
});
test("an uploaded file is offered like any other entry, under its name", () => {
const suggestions = autocomplete.BuildLinkSuggestions({
media: [{ _id: "f1", name: "harbour.png" }, { _id: "f2", file: "no-name.png" }],
});
assert.deepEqual(suggestions, [{ id: "f1", label: "harbour.png", type: "media" }]);
});
test("entries without a name are left out, and a repeated label is offered once", () => {
const suggestions = autocomplete.BuildLinkSuggestions({
notes: [{ _id: "n1", title: "The Inn" }, { _id: "n2", title: "The Inn" }, { _id: "n3" }],
@@ -133,18 +141,19 @@ function wiringTests() {
assert.match(note, /@select="applySuggestion"/);
});
test("the entries a note can link to are the campaign's four lists", () => {
for (const path of ["/note/all", "/actor/list", "/item/list", "/map/list"]) {
test("the entries a note can link to are the campaign's lists", () => {
for (const path of ["/note/all", "/actor/list", "/item/list", "/map/list", "/media/list"]) {
assert.ok(targets.includes(path), `the link entries do not read ${path}`);
}
assert.match(targets, /CACHE_TTL/, "the four lists are cached instead of fetched per keystroke");
assert.match(targets, /CACHE_TTL/, "the lists are cached instead of fetched per keystroke");
});
test("the link menu names its section in every locale", () => {
for (const locale of ["en", "es", "ca"]) {
const sections = JSON.parse(readRepoFile("frontend", "i18n", "locales", locale, "campaigns.json")).sections;
for (const type of ["note", "actor", "item", "map"]) {
assert.ok(sections[`${type}s`], `${locale} has no label for the ${type} section`);
for (const type of ["note", "actor", "item", "map", "media"]) {
const key = type === "media" ? "media" : `${type}s`;
assert.ok(sections[key], `${locale} has no label for the ${type} section`);
}
}
});

View File

@@ -46,7 +46,7 @@ function loadRoutes(file, models) {
};
}
function loadMediaRoutes({ ownsCampaign = true, media = null, folderOk = true } = {}) {
function loadMediaRoutes({ ownsCampaign = true, media = null, folderOk = true, list = [] } = {}) {
const deleted = [];
const api = loadRoutes("media.js", {
"../models/Campaign": { findOne: () => ({ lean: async () => (ownsCampaign ? { _id: "campaign-1" } : null) }) },
@@ -55,6 +55,11 @@ function loadMediaRoutes({ ownsCampaign = true, media = null, folderOk = true }
function Media(data) { Object.assign(this, { _id: "media-new", save: async () => {} }, data); },
{
findById: async () => media,
find: (filter) => ({
select() { return this; },
sort() { return this; },
lean: async () => (filter.campaign === "campaign-1" ? list : []),
}),
deleteOne: async (filter) => { deleted.push(filter); return { deletedCount: 1 }; },
}
),
@@ -95,6 +100,22 @@ test("an upload into another campaign is refused", async () => {
assert.equal(response.msg, "unauthorized");
});
test("a campaign's media can be listed so a note can link to it", async () => {
const list = [{ _id: "media-1", name: "harbour.png", file: "file-1.png", mimeType: "image/png" }];
const { api } = loadMediaRoutes({ list });
const response = await api("GET /list", { query: { campaign: "campaign-1" } });
assert.equal(response.status, "ok");
assert.deepEqual(response.media, list);
});
test("the media list of another campaign is refused", async () => {
const { api } = loadMediaRoutes({ ownsCampaign: false });
const response = await api("GET /list", { query: { campaign: "campaign-1" } });
assert.equal(response.msg, "unauthorized");
});
test("a media file only stands in a note folder", async () => {
const { api } = loadMediaRoutes({ folderOk: false });
const response = await api("POST /upload", {
@@ -187,6 +208,17 @@ test("a media window is registered and reads the file from /api/public", () => {
assert.match(viewer, /getBaseUrl\(\)\}\/public\/\$\{media\.file\}/);
});
test("an embedded image from the media list is drawn in the note", () => {
const embed = read("frontend", "app", "components", "viewer", "content", "EmbeddedEntry.vue");
assert.match(embed, /target\.value\?\.type === 'media'/, "media becomes an embed target");
assert.match(embed, /startsWith\('image\/'\)/, "only an image is drawn as a picture");
assert.match(embed, /getBaseUrl\(\)\}\/public\/\$\{entry\.value\.file\}/, "the upload is served from /api/public");
assert.match(embed, /class="embed-image"/);
const note = read("frontend", "app", "components", "viewer", "content", "Note.vue");
assert.match(note, /CreateWindow\('media_viewer'/, "a plain link to a media file opens its window");
});
test("every locale names the upload and the media window", () => {
for (const locale of ["en", "es", "ca"]) {
const campaigns = JSON.parse(read("frontend", "i18n", "locales", locale, "campaigns.json"));