Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit15f7d35

Browse files
committed
RED: add unit tests for AccountForm username field
1 parente44f7ad commit15f7d35

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import{screen}from"@testing-library/react"
2+
import{MockUser2}from"../../testHelpers/entities"
3+
import{render}from"../../testHelpers/renderHelpers"
4+
import{AccountForm,AccountFormValues}from"./SettingsAccountForm"
5+
6+
// NOTE: it does not matter what the role props of MockUser are set to,
7+
// only that editable is set to true or false. This is passed from
8+
// the call to /authorization done by authXService
9+
describe("AccountForm",()=>{
10+
describe("for owners",()=>{
11+
it("allows updating username",async()=>{
12+
// Given
13+
constmockInitialValues:AccountFormValues={
14+
username:MockUser2.username,
15+
editable:true,
16+
}
17+
18+
// When
19+
render(
20+
<AccountForm
21+
email={MockUser2.email}
22+
initialValues={mockInitialValues}
23+
isLoading={false}
24+
onSubmit={()=>{
25+
return
26+
}}
27+
/>,
28+
)
29+
30+
// Then
31+
constel=awaitscreen.findByLabelText("Username")
32+
expect(el).toBeEnabled()
33+
})
34+
})
35+
36+
describe("for user admins",()=>{
37+
it("allows updating username",async()=>{
38+
// Given
39+
constmockInitialValues:AccountFormValues={
40+
username:MockUser2.username,
41+
editable:true,
42+
}
43+
44+
// When
45+
render(
46+
<AccountForm
47+
email={MockUser2.email}
48+
initialValues={mockInitialValues}
49+
isLoading={false}
50+
onSubmit={()=>{
51+
return
52+
}}
53+
/>,
54+
)
55+
56+
// Then
57+
constel=awaitscreen.findByLabelText("Username")
58+
expect(el).toBeEnabled()
59+
})
60+
})
61+
62+
describe("for members",()=>{
63+
it("allows updating username",async()=>{
64+
// Given
65+
constmockInitialValues:AccountFormValues={
66+
username:MockUser2.username,
67+
editable:false,
68+
}
69+
70+
// When
71+
render(
72+
<AccountForm
73+
email={MockUser2.email}
74+
initialValues={mockInitialValues}
75+
isLoading={false}
76+
onSubmit={()=>{
77+
return
78+
}}
79+
/>,
80+
)
81+
82+
// Then
83+
constel=awaitscreen.findByLabelText("Username")
84+
expect(el).toBeDisabled()
85+
})
86+
})
87+
})

‎site/src/components/SettingsAccountForm/SettingsAccountForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getFormHelpersWithError, nameValidator, onChangeTrimmed } from "../../u
77
import{LoadingButton}from"../LoadingButton/LoadingButton"
88
import{Stack}from"../Stack/Stack"
99

10-
interfaceAccountFormValues{
10+
exportinterfaceAccountFormValues{
1111
username:string
1212
}
1313

‎site/src/testHelpers/entities.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ export const MockUser: TypesGen.User = {
6161
roles:[MockOwnerRole],
6262
}
6363

64+
exportconstMockUserAdmin:TypesGen.User={
65+
id:"test-user",
66+
username:"TestUser",
67+
email:"test@coder.com",
68+
created_at:"",
69+
status:"active",
70+
organization_ids:["fc0774ce-cc9e-48d4-80ae-88f7a4d4a8b0"],
71+
roles:[MockUserAdminRole],
72+
}
73+
6474
exportconstMockUser2:TypesGen.User={
6575
id:"test-user-2",
6676
username:"TestUser2",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp