11import { describe , expect , it , vi } from 'vitest' ;
22import { render } from 'vitest-browser-svelte' ;
3+ import { page } from '@vitest/browser/context' ;
34import Bluesky from './bluesky.svelte' ;
45
56describe ( 'Bluesky' , ( ) => {
@@ -12,45 +13,45 @@ describe('Bluesky', () => {
1213 } ) ;
1314
1415 it ( 'renders iframe with correct embed url' , async ( ) => {
15- const { getByTestId } = render ( Bluesky , {
16+ render ( Bluesky , {
1617 post_id : test_post_id ,
1718 } ) ;
1819
19- const iframe = getByTestId ( 'bluesky-embed' ) ;
20+ const iframe = page . getByTestId ( 'bluesky-embed' ) ;
2021 const expected_src = `https://embed.bsky.app/embed/${ test_post_id } ` ;
2122 await expect . element ( iframe ) . toHaveAttribute ( 'src' , expected_src ) ;
2223 } ) ;
2324
2425 it ( 'renders with custom width' , async ( ) => {
25- const { getByTestId } = render ( Bluesky , {
26+ render ( Bluesky , {
2627 post_id : test_post_id ,
2728 width : '50%' ,
2829 } ) ;
2930
30- const iframe = getByTestId ( 'bluesky-embed' ) ;
31+ const iframe = page . getByTestId ( 'bluesky-embed' ) ;
3132 await expect . element ( iframe ) . toHaveAttribute ( 'width' , '50%' ) ;
3233 } ) ;
3334
3435 it ( 'applies custom iframe styles' , async ( ) => {
3536 const custom_styles = 'border-radius: 8px; background: #f0f0f0;' ;
36- const { getByTestId } = render ( Bluesky , {
37+ render ( Bluesky , {
3738 post_id : test_post_id ,
3839 iframe_styles : custom_styles ,
3940 } ) ;
4041
41- const iframe = getByTestId ( 'bluesky-embed' ) ;
42+ const iframe = page . getByTestId ( 'bluesky-embed' ) ;
4243 const element = iframe . element ( ) ;
4344 const style_text = element . style . cssText . toLowerCase ( ) ;
4445 expect ( style_text ) . toContain ( 'border-radius: 8px' ) ;
4546 expect ( style_text ) . toContain ( 'background: rgb(240, 240, 240)' ) ;
4647 } ) ;
4748
4849 it ( 'has correct default styles' , async ( ) => {
49- const { getByTestId } = render ( Bluesky , {
50+ render ( Bluesky , {
5051 post_id : test_post_id ,
5152 } ) ;
5253
53- const iframe = getByTestId ( 'bluesky-embed' ) ;
54+ const iframe = page . getByTestId ( 'bluesky-embed' ) ;
5455 const element = iframe . element ( ) ;
5556 const style_text = element . style . cssText . toLowerCase ( ) ;
5657 expect ( style_text ) . toContain ( 'position: absolute' ) ;
@@ -65,12 +66,12 @@ describe('Bluesky', () => {
6566
6667 it ( 'combines default and custom iframe styles correctly' , async ( ) => {
6768 const custom_styles = 'border-radius: 8px; margin: 10px;' ;
68- const { getByTestId } = render ( Bluesky , {
69+ render ( Bluesky , {
6970 post_id : test_post_id ,
7071 iframe_styles : custom_styles ,
7172 } ) ;
7273
73- const iframe = getByTestId ( 'bluesky-embed' ) ;
74+ const iframe = page . getByTestId ( 'bluesky-embed' ) ;
7475 const element = iframe . element ( ) ;
7576 const style_text = element . style . cssText . toLowerCase ( ) ;
7677
@@ -86,7 +87,7 @@ describe('Bluesky', () => {
8687 } ) ;
8788
8889 it ( 'updates height when receiving message from iframe' , async ( ) => {
89- const { getByTestId } = render ( Bluesky , {
90+ render ( Bluesky , {
9091 post_id : test_post_id ,
9192 } ) ;
9293
@@ -97,18 +98,18 @@ describe('Bluesky', () => {
9798
9899 window . dispatchEvent ( message_event ) ;
99100
100- const iframe = getByTestId ( 'bluesky-embed' ) ;
101+ const iframe = page . getByTestId ( 'bluesky-embed' ) ;
101102 const element = iframe . element ( ) ;
102103 expect ( element . style . height ) . toBe ( '100%' ) ;
103104 } ) ;
104105
105106 // Edge Cases and Comprehensive Coverage
106107 it ( 'should handle empty post_id gracefully' , async ( ) => {
107- const { getByTestId } = render ( Bluesky , {
108+ render ( Bluesky , {
108109 post_id : '' ,
109110 } ) ;
110111
111- const iframe = getByTestId ( 'bluesky-embed' ) ;
112+ const iframe = page . getByTestId ( 'bluesky-embed' ) ;
112113 const expected_src = 'https://embed.bsky.app/embed/' ;
113114 await expect . element ( iframe ) . toHaveAttribute ( 'src' , expected_src ) ;
114115 } ) ;
@@ -219,11 +220,11 @@ describe('Bluesky', () => {
219220 'a' . repeat ( 100 ) +
220221 '/app.bsky.feed.post/' +
221222 'b' . repeat ( 100 ) ;
222- const { getByTestId } = render ( Bluesky , {
223+ render ( Bluesky , {
223224 post_id : long_post_id ,
224225 } ) ;
225226
226- const iframe = getByTestId ( 'bluesky-embed' ) ;
227+ const iframe = page . getByTestId ( 'bluesky-embed' ) ;
227228 const expected_src = `https://embed.bsky.app/embed/${ long_post_id } ` ;
228229 await expect . element ( iframe ) . toHaveAttribute ( 'src' , expected_src ) ;
229230 } ) ;
@@ -248,7 +249,7 @@ describe('Bluesky', () => {
248249 expect ( wrapper ?. classList . contains ( 'bluesky-wrapper' ) ) . toBe ( true ) ;
249250
250251 // Check iframe is within the correct structure
251- const iframe = getByTestId ( 'bluesky-embed' ) ;
252+ const iframe = page . getByTestId ( 'bluesky-embed' ) ;
252253 expect (
253254 iframe
254255 . element ( )
@@ -258,21 +259,21 @@ describe('Bluesky', () => {
258259
259260 it ( 'should handle numeric width values' , async ( ) => {
260261 // Even though TypeScript interface expects string, test component robustness
261- const { getByTestId } = render ( Bluesky , {
262+ render ( Bluesky , {
262263 post_id : test_post_id ,
263264 width : '500px' , // Using string as per interface
264265 } ) ;
265266
266- const iframe = getByTestId ( 'bluesky-embed' ) ;
267+ const iframe = page . getByTestId ( 'bluesky-embed' ) ;
267268 await expect . element ( iframe ) . toHaveAttribute ( 'width' , '500px' ) ;
268269 } ) ;
269270
270271 it ( 'should have proper iframe accessibility attributes' , async ( ) => {
271- const { getByTestId } = render ( Bluesky , {
272+ render ( Bluesky , {
272273 post_id : test_post_id ,
273274 } ) ;
274275
275- const iframe = getByTestId ( 'bluesky-embed' ) ;
276+ const iframe = page . getByTestId ( 'bluesky-embed' ) ;
276277
277278 // Test accessibility attributes
278279 await expect
@@ -290,22 +291,22 @@ describe('Bluesky', () => {
290291 it ( 'should handle special characters in post_id' , async ( ) => {
291292 const special_post_id =
292293 'did:plc:user-with_special.chars@example/app.bsky.feed.post/post-with-special_chars.123' ;
293- const { getByTestId } = render ( Bluesky , {
294+ render ( Bluesky , {
294295 post_id : special_post_id ,
295296 } ) ;
296297
297- const iframe = getByTestId ( 'bluesky-embed' ) ;
298+ const iframe = page . getByTestId ( 'bluesky-embed' ) ;
298299 const expected_src = `https://embed.bsky.app/embed/${ special_post_id } ` ;
299300 await expect . element ( iframe ) . toHaveAttribute ( 'src' , expected_src ) ;
300301 } ) ;
301302
302303 // Additional comprehensive tests for edge cases
303304 it ( 'should handle default width when not specified' , async ( ) => {
304- const { getByTestId } = render ( Bluesky , {
305+ render ( Bluesky , {
305306 post_id : test_post_id ,
306307 } ) ;
307308
308- const iframe = getByTestId ( 'bluesky-embed' ) ;
309+ const iframe = page . getByTestId ( 'bluesky-embed' ) ;
309310 await expect . element ( iframe ) . toHaveAttribute ( 'width' , '100%' ) ;
310311 } ) ;
311312
0 commit comments