@@ -3,27 +3,35 @@ import { test, expect } from '@playwright/test';
33test . use ( { baseURL : process . env . STORE_ADMIN_URL } ) ;
44
55test ( 'can add product ' , async ( { page } ) => {
6- await page . goto ( '/' ) ;
7-
8- await page . getByRole ( 'link' , { name : 'Products' } ) . click ( ) ;
9- await page . getByRole ( 'button' , { name : 'Add Product' } ) . click ( ) ;
10-
11- await page . getByPlaceholder ( 'Product Name' ) . fill ( 'Bear Snacks' ) ;
12- await page . getByPlaceholder ( 'Price' ) . fill ( '29.99' ) ;
13- await page . getByPlaceholder ( 'Product Keywords' ) . fill ( 'dog, snack, treat, courage, ghosts' ) ;
14-
15- const askOpenAI = page . getByRole ( 'button' , { name : 'Ask OpenAI' } ) ;
16-
17- if ( await askOpenAI . isVisible ( ) ) {
18- const aiApiCall = page . waitForResponse ( '/ai/generate/description' ) ;
19- await askOpenAI . click ( ) ;
20- await aiApiCall ;
21- }
22- else {
23- await page . getByPlaceholder ( 'Product Description' ) . fill ( 'Something tasty for the pups' ) ;
24- }
25-
26- await page . getByRole ( 'button' , { name : 'Save Product' } ) . click ( ) ;
27- await expect ( page . getByRole ( 'heading' , { name : 'Bear Snacks - 29.99' } ) ) . toBeVisible ( ) ;
28- await expect ( page . getByRole ( 'button' , { name : 'Edit Product' } ) ) . toBeVisible ( ) ;
6+ await page . goto ( '/' ) ;
7+
8+ await page . getByRole ( 'link' , { name : 'Products' } ) . click ( ) ;
9+ await page . getByRole ( 'button' , { name : 'Add Product' } ) . click ( ) ;
10+
11+ await page . getByPlaceholder ( 'Product Name' ) . fill ( 'Bear Snacks' ) ;
12+ await page . getByPlaceholder ( 'Price' ) . fill ( '29.99' ) ;
13+ await page . getByPlaceholder ( 'Product Keywords' ) . fill ( 'dog, snack, treat, courage, ghosts' ) ;
14+
15+ const askOpenAI = page . getByRole ( 'button' , { name : 'Ask OpenAI' } ) ;
16+
17+ if ( await askOpenAI . isVisible ( ) ) {
18+ const aiApiCall = page . waitForResponse ( '/ai/generate/description' ) ;
19+ await askOpenAI . click ( ) ;
20+ await aiApiCall ;
21+ }
22+ else {
23+ await page . getByPlaceholder ( 'Product Description' ) . fill ( 'Something tasty for the pups' ) ;
24+ }
25+
26+ await page . getByRole ( 'button' , { name : 'Save Product' } ) . click ( ) ;
27+
28+ page . on ( 'dialog' , async dialog => {
29+ expect ( dialog . type ( ) ) . toBe ( 'alert' ) ;
30+ expect ( dialog . message ( ) ) . toBe ( 'Product saved successfully' ) ;
31+ await dialog . accept ( ) ;
2932 } ) ;
33+
34+ await expect ( page ) . toHaveURL ( / \/ p r o d u c t \/ \d + / ) ;
35+ await expect ( page . getByRole ( 'heading' , { name : 'Bear Snacks - 29.99' } ) ) . toBeVisible ( ) ;
36+ await expect ( page . getByRole ( 'button' , { name : 'Edit Product' } ) ) . toBeVisible ( ) ;
37+ } ) ;
0 commit comments