diff --git a/impro-plugin/main.js b/impro-plugin/main.js index dbedc7c5..e69a3ecf 100644 --- a/impro-plugin/main.js +++ b/impro-plugin/main.js @@ -709,6 +709,28 @@ class IconComponent { } } +class BlobImageComponent { + constructor(containerEl) { + this.el = containerEl.createEl("plugin-blob-image"); + } + setDid(did) { + this.el.setAttr("did", did); + return this; + } + setCid(cid) { + this.el.setAttr("cid", cid); + return this; + } + setAlt(alt) { + this.el.setAttr("alt", alt); + return this; + } + setCdnPrefix(prefix) { + this.el.setAttr("cdn-prefix", prefix); + return this; + } +} + class ProfilesListComponent { constructor(containerEl) { this.el = containerEl.createEl("plugin-profiles-list"); @@ -866,6 +888,12 @@ export class VirtualEl { return component; } + createBlobImage(callback) { + const component = new BlobImageComponent(this); + if (typeof callback === "function") callback(component); + return component; + } + _serialize() { const serialized = { type: "element", diff --git a/impro-plugin/package.json b/impro-plugin/package.json index fdaaabcc..43a109dc 100644 --- a/impro-plugin/package.json +++ b/impro-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@impro.social/impro-plugin", - "version": "0.0.14", + "version": "0.0.15", "type": "module", "main": "main.js", "license": "0BSD", diff --git a/tests/unit/specs/plugins/pluginWorker.test.js b/tests/unit/specs/plugins/pluginWorker.test.js index 6ab372b2..d6df0eaf 100644 --- a/tests/unit/specs/plugins/pluginWorker.test.js +++ b/tests/unit/specs/plugins/pluginWorker.test.js @@ -863,6 +863,54 @@ describe("Setting components", () => { const child = container.children[0]._serialize(); assert.deepEqual(child.attrs.dids, "did:plc:a,did:plc:b"); }); + + it("createPostsFeed builds a plugin-posts-feed with array uris", () => { + const container = makeVirtualEl(); + container.createPostsFeed((feed) => + feed + .setUris([ + "at://did:plc:a/app.bsky.feed.post/1", + "at://did:plc:b/app.bsky.feed.post/2", + ]) + .setEmptyMessage("Nothing to show."), + ); + const child = container.children[0]._serialize(); + assert.deepEqual(child.tag, "plugin-posts-feed"); + assert.deepEqual( + child.attrs.uris, + "at://did:plc:a/app.bsky.feed.post/1,at://did:plc:b/app.bsky.feed.post/2", + ); + assert.deepEqual(child.attrs["empty-message"], "Nothing to show."); + }); + + it("createPostsFeed accepts a pre-joined string of uris", () => { + const container = makeVirtualEl(); + container.createPostsFeed((feed) => + feed.setUris("at://did:plc:a/app.bsky.feed.post/1"), + ); + const child = container.children[0]._serialize(); + assert.deepEqual(child.attrs.uris, "at://did:plc:a/app.bsky.feed.post/1"); + }); + + it("createBlobImage builds a plugin-blob-image with did/cid/alt/cdn-prefix", () => { + const container = makeVirtualEl(); + container.createBlobImage((image) => + image + .setDid("did:plc:abc") + .setCid("bafkreiabcdefghijklmnopqrstuvwxyz234567") + .setAlt("A cat") + .setCdnPrefix("avatar"), + ); + const child = container.children[0]._serialize(); + assert.deepEqual(child.tag, "plugin-blob-image"); + assert.deepEqual(child.attrs.did, "did:plc:abc"); + assert.deepEqual( + child.attrs.cid, + "bafkreiabcdefghijklmnopqrstuvwxyz234567", + ); + assert.deepEqual(child.attrs.alt, "A cat"); + assert.deepEqual(child.attrs["cdn-prefix"], "avatar"); + }); }); describe("fetch — header serialization", () => {