Skip to content

Commit 366312a

Browse files
committed
Added e2e tests to manage notifications following user actions
1 parent 0772363 commit 366312a

File tree

1 file changed

+112
-28
lines changed

1 file changed

+112
-28
lines changed

tests/e2e/notifications.spec.ts

Lines changed: 112 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { join } from "path";
12
import { execSync } from "child_process";
23
import { test, expect } from "@playwright/test";
34

@@ -6,65 +7,148 @@ import { test, expect } from "@playwright/test";
67
//
78
test( "Vérification du contrôle des notifications", async ( { page } ) =>
89
{
9-
// Ce test est désactivé car il ne fonctionne pas sur les navigateurs mobiles.
10-
test.skip();
11-
1210
// Réinitialisation des comptes utilisateurs factices.
1311
execSync( "node scripts/create-fake-accounts.js" );
1412

15-
// Accès à la page d'authentification.
13+
// Authentification et accès au tableau de bord.
1614
await page.goto( "/authentication" );
17-
18-
// Clic sur l'onglet « Connexion ».
1915
await page.getByRole( "tab", { name: "Login" } ).click();
20-
21-
// Remplissage des champs de saisie de l'adresse électronique et du mot de passe.
2216
await page.getByPlaceholder( "[email protected]" ).fill( "[email protected]" );
2317
await page.getByPlaceholder( "@MyPassword123!" ).fill( "Florian4016" );
24-
25-
// Clic sur le bouton de connexion.
2618
await page.getByText( "Log in by password" ).click();
27-
28-
// Attente de la redirection vers la page du tableau de bord.
2919
await expect( page ).toHaveURL( "/dashboard" );
3020

31-
// Première mise à jour des informations du compte utilisateur.
32-
// Note : une notification est envoyée pour indiquer que le mot de passe a été modifié.
33-
await page.goto( "/settings/user" );
34-
await page.getByPlaceholder( "@MyPassword123!" ).fill( "Florian4017" );
35-
await page.getByRole( "button", { name: "Update" } ).click();
21+
// Téléversement de deux fichiers quelconques.
22+
await page.locator( "button" ).filter( { hasText: "Add a file" } ).click();
23+
await page
24+
.getByRole( "textbox", { name: "File Upload" } )
25+
.setInputFiles( [
26+
join( __dirname, "static/cat.jpg" ),
27+
join( __dirname, "static/duck.jpg" )
28+
] );
29+
await page.getByRole( "button", { name: "Upload" } ).click();
3630
await expect(
3731
page.locator( "[data-sonner-toast][data-type = success]" )
3832
).toHaveCount( 1 );
3933

40-
// Mise à jour des préférences de notification.
41-
await page.goto( "/settings/notifications" );
42-
await page.getByRole( "switch" ).last().click();
43-
await page.getByRole( "button", { name: "Update" } ).click();
34+
// Ajout d'un utilisateur en partage en écriture sur le
35+
// premier fichier téléversé.
36+
await page
37+
.getByRole( "button", { name: "Open action menu" } )
38+
.first()
39+
.click();
40+
await page.getByRole( "menuitem", { name: "Manage Shares" } ).click();
41+
await page.getByPlaceholder( "Search..." ).fill( "[email protected]" );
42+
await page
43+
.locator( "li" )
44+
.filter( { hasText: "[email protected]" } )
45+
.getByRole( "button" )
46+
.click();
47+
await expect(
48+
page.locator( "[data-sonner-toast][data-type = success]" )
49+
).toHaveCount( 1 );
50+
await page.getByRole( "combobox" ).click();
51+
await page.getByLabel( "Write" ).click();
52+
await expect(
53+
page.locator( "[data-sonner-toast][data-type = success]" )
54+
).toHaveCount( 1 );
55+
56+
// Rechargement de la page pour fermer le menu des actions.
57+
// Source : https://github.com/radix-ui/primitives/issues/1836#issuecomment-1674338372
58+
await page.reload();
59+
60+
// Ajout d'un utilisateur en partage en écriture sur le
61+
// deuxième fichier téléversé.
62+
await page.getByRole( "button", { name: "Open action menu" } ).last().click();
63+
await page.getByRole( "menuitem", { name: "Manage Shares" } ).click();
64+
await page.getByPlaceholder( "Search..." ).fill( "[email protected]" );
65+
await page
66+
.locator( "li" )
67+
.filter( { hasText: "[email protected]" } )
68+
.getByRole( "button" )
69+
.click();
4470
await expect(
4571
page.locator( "[data-sonner-toast][data-type = success]" )
4672
).toHaveCount( 1 );
73+
await page.getByRole( "combobox" ).click();
74+
await page.getByLabel( "Write" ).click();
75+
await expect(
76+
page.locator( "[data-sonner-toast][data-type = success]" )
77+
).toHaveCount( 1 );
78+
79+
// Rechargement de la page pour fermer le menu des actions.
80+
// Source : https://github.com/radix-ui/primitives/issues/1836#issuecomment-1674338372
81+
await page.reload();
82+
83+
// Déconnexion du compte utilisateur actuel.
84+
await page.locator( "header aside button:last-of-type" ).click();
85+
await page.getByText( "Logout" ).click();
86+
await expect( page ).toHaveURL( "/" );
87+
88+
// Connexion avec le compte utilisateur partagé en écriture.
89+
await page.goto( "/authentication" );
90+
await page.getByRole( "tab", { name: "Login" } ).click();
91+
await page.getByPlaceholder( "[email protected]" ).fill( "[email protected]" );
92+
await page.getByPlaceholder( "@MyPassword123!" ).fill( "Florian4016" );
93+
await page.getByText( "Log in by password" ).click();
94+
await expect( page ).toHaveURL( "/dashboard" );
4795

4896
// Réception des notifications et marquage de toutes comme lues.
97+
await page.locator( ".lucide-bell-ring" ).click();
98+
await expect( page.getByText( "Folder Sharing" ) ).toHaveCount( 2 );
99+
await page.getByRole( "button", { name: "Mark All as Read" } ).click();
100+
await expect(
101+
page.locator( "[data-sonner-toast][data-type = success]" )
102+
).toHaveCount( 1 );
103+
104+
// Suppression du partage en écriture du premier fichier partagé.
105+
await page.goto( "/dashboard" );
106+
await page
107+
.getByRole( "button", { name: "Open action menu" } )
108+
.first()
109+
.click();
110+
await page.getByRole( "menuitem", { name: "Manage Shares" } ).click();
111+
await page.getByRole( "button", { name: "Permanently Delete" } ).click();
112+
await expect(
113+
page.locator( "[data-sonner-toast][data-type = success]" )
114+
).toHaveCount( 1 );
115+
116+
// Rechargement de la page pour fermer le menu des actions.
117+
// Source : https://github.com/radix-ui/primitives/issues/1836#issuecomment-1674338372
49118
await page.reload();
119+
120+
// Réception des notifications et vérification de la notification
121+
// de suppression du partage.
122+
await expect( page ).toHaveURL( "/dashboard" );
50123
await page.locator( ".lucide-bell-ring" ).click();
51-
await expect( page.getByText( "Password Change" ) ).toHaveCount( 1 );
124+
await expect( page.getByText( "Deletion of a Shared File" ) ).toHaveCount( 1 );
52125
await page.getByRole( "button", { name: "Mark All as Read" } ).click();
53126
await expect(
54127
page.locator( "[data-sonner-toast][data-type = success]" )
55128
).toHaveCount( 1 );
56129

57-
// Deuxième mise à jour des informations du compte utilisateur.
58-
// Note : la notification ne doit pas être envoyée cette fois-ci.
59-
await page.goto( "/settings/user" );
60-
await page.getByPlaceholder( "@MyPassword123!" ).fill( "Florian4018" );
130+
// Mise à jour des préférences de notification (désactivation totale).
131+
await page.goto( "/settings/notifications" );
132+
await page.getByRole( "switch" ).last().click();
61133
await page.getByRole( "button", { name: "Update" } ).click();
62134
await expect(
63135
page.locator( "[data-sonner-toast][data-type = success]" )
64136
).toHaveCount( 1 );
65137

66-
// Attente de la réception des notifications et vérification des notifications.
138+
// Suppression du partage en écriture du deuxième fichier partagé.
139+
await page.goto( "/dashboard" );
140+
await page.getByRole( "button", { name: "Open action menu" } ).click();
141+
await page.getByRole( "menuitem", { name: "Manage Shares" } ).click();
142+
await page.getByRole( "button", { name: "Permanently Delete" } ).click();
143+
await expect(
144+
page.locator( "[data-sonner-toast][data-type = success]" )
145+
).toHaveCount( 1 );
146+
147+
// Rechargement de la page pour fermer le menu des actions.
148+
// Source : https://github.com/radix-ui/primitives/issues/1836#issuecomment-1674338372
67149
await page.reload();
150+
151+
// Attente de la réception des notifications et vérification des notifications.
68152
await page.locator( ".lucide-bell-ring" ).click();
69-
await expect( page.getByText( "Password Change" ) ).toHaveCount( 0 );
153+
await expect( page.getByText( "Deletion of a Shared File" ) ).toHaveCount( 0 );
70154
} );

0 commit comments

Comments
 (0)