Skip to content

Commit 0463045

Browse files
authored
feat: add e2e tests for user profile avatar (#5381)
1 parent 0ecc0d4 commit 0463045

File tree

3 files changed

+76
-10
lines changed

3 files changed

+76
-10
lines changed

cypress/e2e/cloud/globalHeader.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
describe('multi-account multi-org global header', () => {
2+
const globalHeaderFeatureFlags = {
3+
quartzIdentity: true,
4+
multiOrg: true,
5+
}
6+
7+
beforeEach(() => {
8+
// Maintain the same session for all tests so that further logins aren't required.
9+
Cypress.Cookies.preserveOnce('sid')
10+
})
11+
12+
before(() => {
13+
cy.flush().then(() =>
14+
cy.signin().then(() => {
15+
cy.get('@org').then(() => {
16+
cy.getByTestID('home-page--header').should('be.visible')
17+
cy.setFeatureFlags(globalHeaderFeatureFlags).then(() => {
18+
// cy.wait is necessary to ensure sufficient time for the feature flag override.
19+
// We cannot cy.wait an intercepted route because this isn't a network request.
20+
cy.wait(400).then(() => {
21+
cy.visit('/')
22+
})
23+
})
24+
})
25+
})
26+
)
27+
})
28+
29+
describe('user profile avatar', () => {
30+
it('navigates to the `user profile` page', () => {
31+
cy.getByTestID('global-header--user-avatar')
32+
.should('be.visible')
33+
.click({scrollBehavior: false})
34+
35+
cy.getByTestID('global-header--user-popover-profile-button')
36+
.should('be.visible')
37+
.click({scrollBehavior: false})
38+
39+
cy.getByTestID('user-profile--page').should('be.visible')
40+
41+
cy.getByTestID('global-header--user-avatar')
42+
.should('be.visible')
43+
.click({scrollBehavior: false})
44+
})
45+
46+
it('allows the user to log out', () => {
47+
cy.getByTestID('global-header--user-avatar')
48+
.should('be.visible')
49+
.click({scrollBehavior: false})
50+
51+
cy.getByTestID('global-header--user-popover-logout-button')
52+
.should('be.visible')
53+
.click({
54+
scrollBehavior: false,
55+
})
56+
// Logout in remocal looks like a 404 because there is no quartz. This tests the logout URL.
57+
cy.location('pathname').should('eq', '/logout')
58+
})
59+
})
60+
})

src/identity/components/GlobalHeader/IdentityUserAvatar.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@ class IdentityUserAvatar extends React.Component<Props, State> {
6868
<Icon
6969
glyph={IconFont.User}
7070
className="user-popover-footer--button-icon"
71+
testID="global-header--user-popover-profile-button"
7172
/>
7273
Profile
7374
</Link>
7475
<Link className="user-popover-footer--button" to="/logout">
7576
<Icon
7677
glyph={IconFont.Logout}
7778
className="user-popover-footer--button-icon"
79+
testID="global-header--user-popover-logout-button"
7880
/>
7981
Log Out
8082
</Link>
@@ -98,18 +100,22 @@ class IdentityUserAvatar extends React.Component<Props, State> {
98100
<div>
99101
{/* Button shape is ButtonShape.Square to make the height and width the same
100102
so we can use the border radius to make it a circle */}
101-
<Button
102-
text={this.getInitials()}
103-
shape={ButtonShape.Square}
104-
color={
105-
isPopoverOpen ? ComponentColor.Default : ComponentColor.Tertiary
106-
}
107-
onClick={this.togglePopoverState}
108-
className={userAvatarButtonClassName}
109-
/>
103+
{this.getInitials() && (
104+
<Button
105+
text={this.getInitials()}
106+
shape={ButtonShape.Square}
107+
color={
108+
isPopoverOpen ? ComponentColor.Default : ComponentColor.Tertiary
109+
}
110+
onClick={this.togglePopoverState}
111+
className={userAvatarButtonClassName}
112+
testID="global-header--user-avatar"
113+
/>
114+
)}
110115
<FlexBox
111116
className={userPopoverClassName}
112117
direction={FlexDirection.Column}
118+
testID="global-header--user-popover"
113119
>
114120
{this.getUserPopoverContents()}
115121
</FlexBox>

src/identity/components/userprofile/UserProfilePage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const UserProfilePage: FC = () => {
1717
return (
1818
<Page titleTag={pageTitleSuffixer(['User Profile'])}>
1919
<Page.Header fullWidth={true}>
20-
<Page.Title title="User Profile" />
20+
<Page.Title title="User Profile" testID="user-profile--page" />
2121
</Page.Header>
2222
<Page.Contents fullWidth={true}>
2323
<UserDetails />

0 commit comments

Comments
 (0)