Image support!
This commit is contained in:
@@ -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"));
|
||||
|
||||
Reference in New Issue
Block a user