1
+ import * as puppeteer from "puppeteer" ;
2
+ import { Screenshot , setupCredentials , enterCredentials } from "../../../e2eTestUtils/TestUtils" ;
3
+ import { LabClient } from "../../../e2eTestUtils/LabClient" ;
4
+ import { LabApiQueryParams } from "../../../e2eTestUtils/LabApiQueryParams" ;
5
+ import { AzureEnvironments , AppTypes } from "../../../e2eTestUtils/Constants" ;
6
+ import { BrowserCacheUtils } from "../../../e2eTestUtils/BrowserCacheTestUtils" ;
7
+
8
+ const SCREENSHOT_BASE_FOLDER_NAME = `${ __dirname } /screenshots/detail-tests` ;
9
+
10
+ async function verifyTokenStore ( BrowserCache : BrowserCacheUtils , scopes : string [ ] ) : Promise < void > {
11
+ const tokenStore = await BrowserCache . getTokens ( ) ;
12
+ expect ( tokenStore . idTokens . length ) . toBe ( 1 ) ;
13
+ expect ( tokenStore . accessTokens . length ) . toBe ( 1 ) ;
14
+ expect ( tokenStore . refreshTokens . length ) . toBe ( 1 ) ;
15
+ expect ( await BrowserCache . getAccountFromCache ( tokenStore . idTokens [ 0 ] ) ) . not . toBeNull ( ) ;
16
+ expect ( await BrowserCache . accessTokenForScopesExists ( tokenStore . accessTokens , scopes ) ) . toBeTruthy ;
17
+ const storage = await BrowserCache . getWindowStorage ( ) ;
18
+ expect ( Object . keys ( storage ) . length ) . toBe ( 5 ) ;
19
+ }
20
+
21
+ describe ( '/ (Detail Page)' , ( ) => {
22
+ let browser : puppeteer . Browser ;
23
+ let context : puppeteer . BrowserContext ;
24
+ let page : puppeteer . Page ;
25
+ let port : number ;
26
+ let username : string ;
27
+ let accountPwd : string ;
28
+ let BrowserCache : BrowserCacheUtils ;
29
+
30
+ beforeAll ( async ( ) => {
31
+ // @ts -ignore
32
+ browser = await global . __BROWSER__ ;
33
+ // @ts -ignore
34
+ port = global . __PORT__ ;
35
+
36
+ const labApiParams : LabApiQueryParams = {
37
+ azureEnvironment : AzureEnvironments . PPE ,
38
+ appType : AppTypes . CLOUD
39
+ } ;
40
+
41
+ const labClient = new LabClient ( ) ;
42
+ const envResponse = await labClient . getVarsByCloudEnvironment ( labApiParams ) ;
43
+
44
+ [ username , accountPwd ] = await setupCredentials ( envResponse [ 0 ] , labClient ) ;
45
+ } ) ;
46
+
47
+ beforeEach ( async ( ) => {
48
+ context = await browser . createIncognitoBrowserContext ( ) ;
49
+ page = await context . newPage ( ) ;
50
+ BrowserCache = new BrowserCacheUtils ( page , "localStorage" ) ;
51
+ await page . goto ( `http://localhost:${ port } ` ) ;
52
+ } ) ;
53
+
54
+ afterEach ( async ( ) => {
55
+ await page . close ( ) ;
56
+ await context . close ( ) ;
57
+ } ) ;
58
+
59
+ it ( "Detail page - children are rendered after clicking profile, logging in with redirect, and detail buttons clicked" , async ( ) => {
60
+ const testName = "detailsBaseCase" ;
61
+ const screenshot = new Screenshot ( `${ SCREENSHOT_BASE_FOLDER_NAME } /${ testName } ` ) ;
62
+ await screenshot . takeScreenshot ( page , "Page loaded" ) ;
63
+
64
+ // Initiate Login via MsalGuard by clicking Profile
65
+ const [ profileButton ] = await page . $x ( "//span[contains(., 'Profile')]" ) ;
66
+ await profileButton . click ( ) ;
67
+
68
+ await enterCredentials ( page , screenshot , username , accountPwd ) ;
69
+
70
+ // Verify UI now displays logged in content
71
+ const [ logoutButtons ] = await page . $x ( "//button[contains(., 'Logout')]" ) ;
72
+ expect ( logoutButtons ) . toBeDefined ( ) ;
73
+ await screenshot . takeScreenshot ( page , "Profile page signed in" ) ;
74
+
75
+ // Verify tokens are in cache
76
+ await verifyTokenStore ( BrowserCache , [ "User.Read" ] ) ;
77
+
78
+ // Verify displays profile page
79
+ const [ profileFirstName ] = await page . $x ( "//strong[contains(., 'First Name: ')]" ) ;
80
+ expect ( profileFirstName ) . toBeDefined ( ) ;
81
+
82
+ // Navigate to details page
83
+ const [ detailsButton ] = await page . $x ( "//a[contains(., 'details')]" ) ;
84
+ await detailsButton . click ( ) ;
85
+ await screenshot . takeScreenshot ( page , "Details page" ) ;
86
+
87
+ // Wait for Graph data to display
88
+ await page . waitForXPath ( "//p[contains(., 'Details for: ')]" , { timeout : 5000 } ) ;
89
+ await screenshot . takeScreenshot ( page , "Graph data acquired" ) ;
90
+
91
+ // Verify displays details page
92
+ const [ detailsFor ] = await page . $x ( "//p[contains(., 'Details for: ')]" ) ;
93
+ expect ( detailsFor ) . toBeDefined ( ) ;
94
+ } ) ;
95
+ }
96
+ ) ;
0 commit comments