1
1
import { expect , test } from "@playwright/test" ;
2
2
import { ROOT_SRC } from "../util/constants" ;
3
3
import path from "path" ;
4
+
4
5
const clickAndAssertTab = async ( page , tabName , urlFragment , textToAssert ) => {
5
6
await page . getByRole ( "button" , { name : tabName } ) . click ( ) ;
6
7
expect ( page . url ( ) ) . toContain ( urlFragment ) ;
7
8
await page . waitForTimeout ( 1000 ) ;
8
9
if ( textToAssert ) {
9
- expect ( page . getByText ( textToAssert , { exact : true } ) ) . toBeVisible ( ) ;
10
+ await expect ( page . getByText ( textToAssert ) . nth ( 0 ) ) . toBeVisible ( {
11
+ timeout : 10000 ,
12
+ } ) ;
10
13
}
11
14
} ;
12
15
@@ -17,15 +20,15 @@ test.describe("All tabs must be visible and redirected to respective pages", ()
17
20
} ) ;
18
21
19
22
test ( "All Feed" , async ( { page } ) => {
20
- await clickAndAssertTab ( page , "All" , "?page=activity&tab=all" , "All Feed " ) ;
23
+ await clickAndAssertTab ( page , "All" , "?page=activity&tab=all" , "All" ) ;
21
24
} ) ;
22
25
23
26
test ( "Updates" , async ( { page } ) => {
24
27
await clickAndAssertTab (
25
28
page ,
26
29
"Updates" ,
27
30
"?page=activity&tab=updates" ,
28
- "Updates Feed " ,
31
+ "Updates" ,
29
32
) ;
30
33
} ) ;
31
34
@@ -34,25 +37,20 @@ test.describe("All tabs must be visible and redirected to respective pages", ()
34
37
page ,
35
38
"Question" ,
36
39
"?page=activity&tab=question" ,
37
- "Question Feed " ,
40
+ "Question" ,
38
41
) ;
39
42
} ) ;
40
43
41
44
test ( "Idea" , async ( { page } ) => {
42
- await clickAndAssertTab (
43
- page ,
44
- "Idea" ,
45
- "?page=activity&tab=idea" ,
46
- "Idea Feed" ,
47
- ) ;
45
+ await clickAndAssertTab ( page , "Idea" , "?page=activity&tab=idea" , "Idea" ) ;
48
46
} ) ;
49
47
50
48
test ( "Feedback" , async ( { page } ) => {
51
49
await clickAndAssertTab (
52
50
page ,
53
51
"Feedback" ,
54
52
"?page=activity&tab=feedback" ,
55
- "Feedback Feed " ,
53
+ "Feedback" ,
56
54
) ;
57
55
} ) ;
58
56
@@ -76,7 +74,7 @@ test.describe("All tabs must be visible and redirected to respective pages", ()
76
74
page ,
77
75
"Request" ,
78
76
"?page=activity&tab=request" ,
79
- "Request Feed " ,
77
+ "Request" ,
80
78
) ;
81
79
} ) ;
82
80
@@ -380,7 +378,6 @@ test.describe("User is logged in", () => {
380
378
} ) ;
381
379
382
380
test ( "Edit a post and Save" , async ( { page } ) => {
383
- await clickAndAssertTab ( page , "All" , "?page=activity&tab=all" , "All Feed" ) ;
384
381
await page . waitForTimeout ( 1000 ) ;
385
382
const dropdown = page . locator ( ".bi.bi-three-dots-vertical" ) . nth ( 1 ) ;
386
383
await dropdown . click ( ) ;
@@ -412,7 +409,6 @@ test.describe("User is logged in", () => {
412
409
} ) ;
413
410
414
411
test ( "Bookmark a Post" , async ( { page } ) => {
415
- await clickAndAssertTab ( page , "All" , "?page=activity&tab=all" , "All Feed" ) ;
416
412
await page . waitForTimeout ( 1000 ) ;
417
413
const bookmarkIcon = await page . getByTitle ( "Bookmark" ) . nth ( 1 ) ;
418
414
await bookmarkIcon . click ( ) ;
@@ -446,7 +442,6 @@ test.describe("User is logged in", () => {
446
442
expect ( transactionObj ) . toMatchObject ( expectedTransactionData ) ;
447
443
} ) ;
448
444
test ( "Like a Post" , async ( { page } ) => {
449
- await clickAndAssertTab ( page , "All" , "?page=activity&tab=all" , "All Feed" ) ;
450
445
await page . waitForTimeout ( 1000 ) ;
451
446
const likeIcon = await page . getByTitle ( "Like" ) . nth ( 1 ) ;
452
447
await page . waitForTimeout ( 1000 ) ;
@@ -471,7 +466,6 @@ test.describe("User is logged in", () => {
471
466
expect ( transactionObj ) . toMatchObject ( expectedTransactionData ) ;
472
467
} ) ;
473
468
test ( "Repost a Post" , async ( { page } ) => {
474
- await clickAndAssertTab ( page , "All" , "?page=activity&tab=all" , "All Feed" ) ;
475
469
await page . waitForTimeout ( 1000 ) ;
476
470
const repostIcon = await page . getByTitle ( "Repost" ) . nth ( 1 ) ;
477
471
await page . waitForTimeout ( 1000 ) ;
@@ -502,7 +496,6 @@ test.describe("User is logged in", () => {
502
496
} ) ;
503
497
504
498
test ( "Comment on a post" , async ( { page } ) => {
505
- await clickAndAssertTab ( page , "All" , "?page=activity&tab=all" , "All Feed" ) ;
506
499
await page . waitForTimeout ( 1000 ) ;
507
500
const commentIcon = await page . getByTitle ( "Comment" ) . nth ( 1 ) ;
508
501
await page . waitForTimeout ( 1000 ) ;
@@ -533,8 +526,40 @@ test.describe("User is logged in", () => {
533
526
} ;
534
527
expect ( transactionObj ) . toMatchObject ( expectedTransactionData ) ;
535
528
} ) ;
529
+
530
+ test . describe ( "All tabs must be visible and redirected to respective pages" , ( ) => {
531
+ test . beforeEach ( async ( { page } ) => {
532
+ await page . waitForTimeout ( 1000 ) ;
533
+ const shareBtn = await page . getByTitle ( "Share" ) . nth ( 1 ) ;
534
+ await shareBtn . click ( ) ;
535
+ } ) ;
536
+
537
+ test ( "should copy post link to clipboard" , async ( { page } ) => {
538
+ await page . getByRole ( "button" , { name : "Copy link to post" } ) . click ( ) ;
539
+ await page . waitForTimeout ( 1000 ) ;
540
+ const handle = await page . evaluateHandle ( ( ) =>
541
+ navigator . clipboard . readText ( ) ,
542
+ ) ;
543
+ expect ( ( await handle . jsonValue ( ) ) . includes ( "MainPage.N.Post.Page" ) ) ;
544
+ } ) ;
545
+
546
+ test ( "should share post link via email" , async ( { page } ) => {
547
+ await page . waitForTimeout ( 1000 ) ;
548
+ // mailto opens email app, couldn't find a way to test opening of that app
549
+ const emailLink = page . getByRole ( "link" , { name : " Share by email" } ) ;
550
+ await expect ( emailLink ) . toHaveAttribute ( "href" , / ^ m a i l t o : / ) ;
551
+ } ) ;
552
+
553
+ test ( "should share post link via twitter" , async ( { page } ) => {
554
+ const [ newPage ] = await Promise . all ( [
555
+ page . waitForEvent ( "popup" ) ,
556
+ page . getByRole ( "link" , { name : " Share on Twitter" } ) . click ( ) ,
557
+ ] ) ;
558
+ await newPage . waitForLoadState ( "domcontentloaded" ) ;
559
+ expect ( newPage . url ( ) ) . toContain ( "https://x.com/intent" ) ;
560
+ } ) ;
561
+ } ) ;
536
562
test ( "Convert post into proposal" , async ( { page } ) => {
537
- await clickAndAssertTab ( page , "All" , "?page=activity&tab=all" , "All Feed" ) ;
538
563
await page . waitForTimeout ( 1000 ) ;
539
564
const dropdown = page . locator ( ".bi.bi-three-dots-vertical" ) . nth ( 1 ) ;
540
565
await dropdown . click ( ) ;
0 commit comments