Skip to content

Instantly share code, notes, and snippets.

it('should return the post with altLess images list', async () => {
const imageWithoutAlt = { alt: '' };
const imageWithAlt = { alt: 'I have Alt text!' };
const post = {
uri: 'postUri',
cid: 'postCid',
value: {
embed: {
images: [imageWithoutAlt, imageWithAlt, imageWithoutAlt],
$type: 'image'
async function parsePostUri(uri: string, agent: AtpAgent): Promise<{ repo: string; collection: string; rkey: string; } | boolean> {
// Extract handle and post ID
const match = uri.match(/profile\/([^/]+)\/post\/([^/]+)/);
if (!match) {
return false;
}
const [, handle, rkey] = match;
// Get the did
const { data: { did: repo }} = await agent.resolveHandle({handle});
it('should get the post using atpAgent', async () => {
const postUri = 'https://bsky.app/profile/yonatankra.com/post/3lczalvz7uk2l';
mockAtpAgent.getPost.mockResolvedValueOnce(postUri);
await bot.checkSinglePost(postUri);
expect(mockAtpAgent.getPost).toHaveBeenCalledWith({
"collection": "app.bsky.feed.post",
"repo": "handle-did",
"rkey": "3lczalvz7uk2l",
describe('AltTextBot', () => {
const postUri = 'postUri';
let bot: AltTextBot;
beforeEach(async () => {
resetAtpAgentMock();
bot = new AltTextBot();
});
it('should initialize a new instance', async () => {
import { AtpAgent } from "@atproto/api";
export class AltTextBot {
#agent = new AtpAgent({ service: 'https://bsky.social' });
async checkSinglePost(postUri: string) {
try {
await this.#agent.getPost(await parsePostUri(postUri, this.#agent));
} catch (e) {
return e;
}
{
"name": "alt-text-game",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "vitest",
"start": "vite"
},
"keywords": [],
"author": "",
@YonatanKra
YonatanKra / find-altless-posts.spec.ts
Last active December 15, 2024 12:06
First test for our AltTextBot
import { AltTextBot } from './find-altless-posts.js';
let mockAtpAgent;
const resetAtpAgentMock = () => {
mockAtpAgent = {
getPost: vi.fn(),
};
}
@YonatanKra
YonatanKra / vite.config.ts
Created December 15, 2024 09:12
Basic Vite configuration
/// <reference types="vitest/globals" />
import { defineConfig } from 'vitest/config'
export default defineConfig({
root: './src',
server: {
open: true
},
test: {
globals: true,
function getAllNestedShadowRootsParents(element) {
const nestedShadowRoots = [];
function traverseShadowRoot(node) {
if (node.shadowRoot) {
nestedShadowRoots.push(node);
node.shadowRoot.querySelectorAll('*').forEach(child => {
traverseShadowRoot(child);
});
} else {
<vwc-button icon="facebook-color" label="ghost" appearance="ghost"></vwc-button>
<vwc-button icon="linkedin-color" label="ghost-light" appearance="ghost-light"></vwc-button>
<vwc-button icon="twitter-color" label="filled" appearance="filled"></vwc-button>
<vwc-button icon="instagram-color" label="outlined" appearance="outlined"></vwc-button>