This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('AltTextBot', () => { | |
const postUri = 'postUri'; | |
let bot: AltTextBot; | |
beforeEach(async () => { | |
resetAtpAgentMock(); | |
bot = new AltTextBot(); | |
}); | |
it('should initialize a new instance', async () => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "alt-text-game", | |
"version": "1.0.0", | |
"main": "index.js", | |
"scripts": { | |
"test": "vitest", | |
"start": "vite" | |
}, | |
"keywords": [], | |
"author": "", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AltTextBot } from './find-altless-posts.js'; | |
let mockAtpAgent; | |
const resetAtpAgentMock = () => { | |
mockAtpAgent = { | |
getPost: vi.fn(), | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference types="vitest/globals" /> | |
import { defineConfig } from 'vitest/config' | |
export default defineConfig({ | |
root: './src', | |
server: { | |
open: true | |
}, | |
test: { | |
globals: true, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getAllNestedShadowRootsParents(element) { | |
const nestedShadowRoots = []; | |
function traverseShadowRoot(node) { | |
if (node.shadowRoot) { | |
nestedShadowRoots.push(node); | |
node.shadowRoot.querySelectorAll('*').forEach(child => { | |
traverseShadowRoot(child); | |
}); | |
} else { |