Skip to content

Commit 71cab51

Browse files
authored
feat: create e2e tests for user profile (#5386)
1 parent 015e684 commit 71cab51

File tree

9 files changed

+590
-13
lines changed

9 files changed

+590
-13
lines changed

cypress/e2e/cloud/userProfile.ts

Lines changed: 524 additions & 0 deletions
Large diffs are not rendered by default.

src/identity/components/GlobalHeader/GlobalHeaderDropdown/GlobalHeaderTypeAheadMenu.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type Props = {
1010
typeAheadPlaceHolder: string
1111
typeAheadMenuOptions: TypeAheadMenuItem[]
1212
onSelectOption: (item: TypeAheadMenuItem) => void
13+
testID: string
1314
}
1415

1516
type State = {
@@ -96,7 +97,7 @@ export class GlobalHeaderTypeAheadMenu extends React.Component<Props, State> {
9697
placeholder={typeAheadPlaceHolder}
9798
onChange={this.handleInputChange}
9899
value={searchTerm}
99-
testID="dropdown-input-typeAhead"
100+
testID={this.props.testID}
100101
onClear={this.clearFilter}
101102
onFocus={this.selectAllTextInInput}
102103
className="global-header--typeahead-input"

src/identity/components/GlobalHeader/GlobalHeaderDropdown/index.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,22 @@ export interface TypeAheadMenuItem {
3333

3434
export interface Props extends StandardFunctionProps {
3535
defaultButtonText?: string
36+
defaultTestID?: string
3637
dropdownButtonSize?: ComponentSize
3738
dropdownButtonIcon?: IconFont
3839
dropdownMenuStyle?: React.CSSProperties
3940
dropdownMenuTheme?: DropdownMenuTheme
4041
mainMenuHeaderText?: string
4142
mainMenuHeaderIcon?: IconFont
4243
mainMenuOptions: MainMenuItem[]
44+
mainMenuTestID?: string
4345
onlyRenderSubmenu?: boolean
46+
testID?: string
4447
typeAheadSelectedOption?: TypeAheadMenuItem
4548
typeAheadMenuOptions: TypeAheadMenuItem[]
4649
typeAheadInputPlaceholder?: string
4750
typeAheadOnSelectOption?: (item: TypeAheadMenuItem | null) => void
51+
typeAheadTestID?: string
4852
}
4953

5054
type State = {
@@ -75,6 +79,7 @@ export class GlobalHeaderDropdown extends React.Component<Props, State> {
7579
) => {
7680
const {
7781
defaultButtonText,
82+
defaultTestID,
7883
dropdownButtonSize,
7984
dropdownButtonIcon,
8085
} = this.props
@@ -86,6 +91,7 @@ export class GlobalHeaderDropdown extends React.Component<Props, State> {
8691
size={dropdownButtonSize}
8792
trailingIcon={dropdownButtonIcon || IconFont.DoubleCaretVertical}
8893
className="global-header--dropdown-button"
94+
testID={defaultTestID}
8995
>
9096
{selectedItem?.name || defaultButtonText}
9197
</Dropdown.Button>
@@ -110,6 +116,7 @@ export class GlobalHeaderDropdown extends React.Component<Props, State> {
110116
key={value.name}
111117
href={value.href}
112118
className="global-header--align-center"
119+
testID={`${this.props.mainMenuTestID}-${value.name}`}
113120
>
114121
{iconEl}
115122
{textEl}
@@ -135,6 +142,7 @@ export class GlobalHeaderDropdown extends React.Component<Props, State> {
135142
onSelectOption={typeAheadOnSelectOption}
136143
style={dropdownMenuStyle}
137144
defaultSelectedItem={selectedItem}
145+
testID={this.props.typeAheadTestID}
138146
/>
139147
)
140148
}
@@ -157,7 +165,11 @@ export class GlobalHeaderDropdown extends React.Component<Props, State> {
157165
/>
158166
)
159167
return (
160-
<Dropdown.Menu theme={dropdownMenuTheme} style={dropdownMenuStyle}>
168+
<Dropdown.Menu
169+
style={dropdownMenuStyle}
170+
theme={dropdownMenuTheme}
171+
testID={this.props.mainMenuTestID}
172+
>
161173
{/* Multi-org UI tickets #4051 and #4047, when user only has 1 account or 1 org, switch button is disabled */}
162174
{!onlyRenderSubmenu && typeAheadMenuOptions.length > 1 && (
163175
<Dropdown.Item onClick={this.toggleShowTypeAheadMenu}>
@@ -196,6 +208,7 @@ export class GlobalHeaderDropdown extends React.Component<Props, State> {
196208
disableAutoFocus
197209
button={this.dropdownButton}
198210
menu={this.renderMenu}
211+
testID={this.props.testID}
199212
/>
200213
)
201214
}

src/identity/components/userprofile/DefaultAccountForm.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const DefaultAccountForm: FC<Props> = ({
4040
weight={FontWeight.Bold}
4141
element={HeadingElement.H4}
4242
className="change-default-account-org--header"
43+
testID="user-profile--change-account-header"
4344
>
4445
Default Account
4546
</Heading>
@@ -50,8 +51,10 @@ export const DefaultAccountForm: FC<Props> = ({
5051
<DefaultDropdown
5152
entityLabel={EntityLabel.DefaultAccount}
5253
defaultEntity={selectedAccount}
54+
defaultTestID="user-profile--change-account-dropdown"
5355
entityList={accounts}
5456
changeSelectedEntity={setSelectedAccount}
57+
headerTestID="user-profile--change-account-dropdown-header"
5558
/>
5659
)}
5760
</FlexBox>

src/identity/components/userprofile/DefaultDropdown.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,21 @@ import 'src/identity/components/userprofile/UserProfile.scss'
2626
const globalHeaderStyle = {width: '368px', backgroundColor: '#232533'}
2727

2828
interface Props {
29-
entityLabel: string
29+
changeSelectedEntity: (action: SetStateAction<any>) => void
3030
defaultEntity: Entity
31+
defaultTestID: string
3132
entityList: Entity[]
32-
changeSelectedEntity: (action: SetStateAction<any>) => void
33+
entityLabel: string
34+
headerTestID: string
3335
}
3436

3537
export const DefaultDropdown: FC<Props> = ({
36-
entityLabel,
37-
entityList,
3838
changeSelectedEntity,
3939
defaultEntity,
40+
defaultTestID,
41+
entityList,
42+
entityLabel,
43+
headerTestID,
4044
}) => {
4145
return (
4246
<FlexBox
@@ -48,15 +52,17 @@ export const DefaultDropdown: FC<Props> = ({
4852
<Form.Element
4953
label={`Default ${entityLabel}`}
5054
className="user-profile-page--form-element"
55+
testID={headerTestID}
5156
>
5257
<GlobalHeaderDropdown
58+
defaultTestID={defaultTestID}
5359
mainMenuOptions={[]}
5460
onlyRenderSubmenu={true}
61+
style={globalHeaderStyle}
5562
typeAheadMenuOptions={entityList}
5663
typeAheadInputPlaceholder={`Search ${entityLabel}s ...`}
5764
typeAheadSelectedOption={defaultEntity}
5865
typeAheadOnSelectOption={changeSelectedEntity}
59-
style={globalHeaderStyle}
6066
/>
6167
</Form.Element>
6268
</FlexBox>

src/identity/components/userprofile/DefaultOrgForm.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const DefaultOrgForm: FC<Props> = ({
4848
weight={FontWeight.Bold}
4949
element={HeadingElement.H4}
5050
className="change-default-account-org--header"
51+
testID="user-defaults-change-org--header"
5152
>
5253
Default Organization
5354
</Heading>
@@ -64,17 +65,21 @@ export const DefaultOrgForm: FC<Props> = ({
6465
>
6566
{accounts && (
6667
<UserProfileInput
67-
status={ComponentStatus.Disabled}
6868
header="Account"
69+
inputTestID="user-profile--current-account-input"
70+
status={ComponentStatus.Disabled}
6971
text={loggedInAccount.name}
72+
testID="user-profile--current-account-header"
7073
/>
7174
)}
7275
{orgs && (
7376
<DefaultDropdown
74-
entityLabel={EntityLabel.DefaultOrg}
7577
defaultEntity={selectedOrg}
78+
defaultTestID="user-profile--default-org-dropdown"
79+
entityLabel={EntityLabel.DefaultOrg}
7680
entityList={orgs}
7781
changeSelectedEntity={setSelectedOrg}
82+
headerTestID="user-profile--default-org-header"
7883
/>
7984
)}
8085
</FlexBox>

src/identity/components/userprofile/UserDefaults.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export const UserDefaults: FC = () => {
141141
size={ComponentSize.Small}
142142
type={ButtonType.Submit}
143143
className="user-profile-page--save-button"
144+
testID="user-profile--save-button"
144145
/>
145146
</Form>
146147
)

src/identity/components/userprofile/UserDetails.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const UserDetails: FC = () => {
3131
weight={FontWeight.Bold}
3232
element={HeadingElement.H4}
3333
className="user-details-container--header"
34+
testID="user-profile--user-details-header"
3435
>
3536
User Details
3637
</Heading>
@@ -39,6 +40,8 @@ export const UserDetails: FC = () => {
3940
<UserProfileInput
4041
status={ComponentStatus.Disabled}
4142
header="Email"
43+
inputTestID="user-profile--email-input"
44+
testID="user-profile--email"
4245
text={user.email}
4346
/>
4447
<FlexBox
@@ -49,11 +52,15 @@ export const UserDetails: FC = () => {
4952
<UserProfileInput
5053
status={ComponentStatus.Disabled}
5154
header="First name"
55+
inputTestID="user-profile--firstname-input"
56+
testID="user-profile--firstname"
5257
text={user.firstName}
5358
/>
5459
<UserProfileInput
5560
status={ComponentStatus.Disabled}
5661
header="Last name"
62+
inputTestID="user-profile--lastname-input"
63+
testID="user-profile--lastname"
5764
text={user.lastName}
5865
/>
5966
</FlexBox>

src/identity/components/userprofile/UserProfileInput.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import {ComponentStatus, InfluxColors, Input, Form} from '@influxdata/clockface'
88
import 'src/identity/components/userprofile/UserProfile.scss'
99

1010
interface Props {
11-
status: ComponentStatus
1211
header: string
12+
inputTestID: string
13+
status: ComponentStatus
14+
testID: string
1315
text: string
1416
}
1517

@@ -19,8 +21,23 @@ const inputStyle = {
1921
color: InfluxColors.White,
2022
}
2123

22-
export const UserProfileInput: FC<Props> = ({status, header, text}) => (
23-
<Form.Element label={header} className="user-profile-page--form-element">
24-
<Input status={status} value={text} inputStyle={inputStyle} />
24+
export const UserProfileInput: FC<Props> = ({
25+
header,
26+
inputTestID,
27+
status,
28+
testID,
29+
text,
30+
}) => (
31+
<Form.Element
32+
label={header}
33+
className="user-profile-page--form-element"
34+
testID={testID}
35+
>
36+
<Input
37+
status={status}
38+
value={text}
39+
inputStyle={inputStyle}
40+
testID={inputTestID}
41+
/>
2542
</Form.Element>
2643
)

0 commit comments

Comments
 (0)