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

Commit214c5f7

Browse files
committed
Use Storybook for non-redirect org settings tests
1 parent7f520e7 commit214c5f7

File tree

2 files changed

+76
-64
lines changed

2 files changed

+76
-64
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
importtype{Meta,StoryObj}from"@storybook/react";
2+
import{reactRouterParameters}from"storybook-addon-remix-react-router";
3+
import{
4+
MockDefaultOrganization,
5+
MockOrganization2,
6+
MockUser,
7+
}from"testHelpers/entities";
8+
import{organizationsKey}from"api/queries/organizations"
9+
import{permissionsToCheck}from"contexts/auth/permissions";
10+
import{withAuthProvider,withDashboardProvider}from"testHelpers/storybook";
11+
importOrganizationSettingsPagefrom"./OrganizationSettingsPage";
12+
13+
constmeta:Meta<typeofOrganizationSettingsPage>={
14+
title:"pages/OrganizationSettingsPage",
15+
component:OrganizationSettingsPage,
16+
decorators:[
17+
withAuthProvider,
18+
withDashboardProvider,
19+
],
20+
parameters:{
21+
user:MockUser,
22+
permissions:{viewDeploymentValues:true},
23+
queries:[
24+
{
25+
key:["organizations",[MockDefaultOrganization.id],"permissions"],
26+
data:{},
27+
},
28+
],
29+
},
30+
};
31+
32+
exportdefaultmeta;
33+
typeStory=StoryObj<typeofOrganizationSettingsPage>;
34+
35+
exportconstNoRedirectableOrganizations:Story={};
36+
37+
exportconstOrganizationDoesNotExist:Story={
38+
parameters:{
39+
reactRouter:reactRouterParameters({
40+
location:{pathParams:{organization:"does-not-exist"}},
41+
routing:{path:"/organizations/:organization"},
42+
}),
43+
},
44+
};
45+
46+
exportconstCannotEditOrganization:Story={
47+
parameters:{
48+
reactRouter:reactRouterParameters({
49+
location:{pathParams:{organization:MockDefaultOrganization.name}},
50+
routing:{path:"/organizations/:organization"},
51+
}),
52+
},
53+
};
54+
55+
exportconstCanEditOrganization:Story={
56+
parameters:{
57+
reactRouter:reactRouterParameters({
58+
location:{pathParams:{organization:MockDefaultOrganization.name}},
59+
routing:{path:"/organizations/:organization"},
60+
}),
61+
queries:[
62+
{
63+
key:["organizations",[MockDefaultOrganization.id],"permissions"],
64+
data:{
65+
[MockDefaultOrganization.id]:{
66+
editOrganization:true,
67+
},
68+
},
69+
},
70+
],
71+
},
72+
};

‎site/src/pages/ManagementSettingsPage/OrganizationSettingsPage.test.tsx

Lines changed: 4 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,15 @@ import OrganizationSettingsPage from "./OrganizationSettingsPage";
1313

1414
jest.spyOn(console,"error").mockImplementation(()=>{});
1515

16-
constrenderRootPage=async()=>{
16+
constrenderPage=async()=>{
1717
renderWithManagementSettingsLayout(<OrganizationSettingsPage/>,{
1818
route:"/organizations",
1919
path:"/organizations/:organization?",
2020
});
2121
awaitwaitForLoaderToBeRemoved();
2222
};
2323

24-
constrenderPage=async(orgName:string)=>{
25-
renderWithManagementSettingsLayout(<OrganizationSettingsPage/>,{
26-
route:`/organizations/${orgName}`,
27-
path:"/organizations/:organization",
28-
});
29-
awaitwaitForLoaderToBeRemoved();
30-
};
31-
3224
describe("OrganizationSettingsPage",()=>{
33-
it("has no organizations",async()=>{
34-
server.use(
35-
http.get("/api/v2/organizations",()=>{
36-
returnHttpResponse.json([]);
37-
}),
38-
http.post("/api/v2/authcheck",async()=>{
39-
returnHttpResponse.json({
40-
[`${MockDefaultOrganization.id}.editOrganization`]:true,
41-
viewDeploymentValues:true,
42-
});
43-
}),
44-
);
45-
awaitrenderRootPage();
46-
awaitscreen.findByText("No organizations found");
47-
});
48-
4925
it("has no editable organizations",async()=>{
5026
server.use(
5127
http.get("/api/v2/organizations",()=>{
@@ -57,7 +33,7 @@ describe("OrganizationSettingsPage", () => {
5733
});
5834
}),
5935
);
60-
awaitrenderRootPage();
36+
awaitrenderPage();
6137
awaitscreen.findByText("No organizations found");
6238
});
6339

@@ -75,7 +51,7 @@ describe("OrganizationSettingsPage", () => {
7551
});
7652
}),
7753
);
78-
awaitrenderRootPage();
54+
awaitrenderPage();
7955
constform=screen.getByTestId("org-settings-form");
8056
expect(within(form).getByRole("textbox",{name:"Name"})).toHaveValue(
8157
MockDefaultOrganization.name,
@@ -94,46 +70,10 @@ describe("OrganizationSettingsPage", () => {
9470
});
9571
}),
9672
);
97-
awaitrenderRootPage();
73+
awaitrenderPage();
9874
constform=screen.getByTestId("org-settings-form");
9975
expect(within(form).getByRole("textbox",{name:"Name"})).toHaveValue(
10076
MockOrganization2.name,
10177
);
10278
});
103-
104-
it("cannot find organization",async()=>{
105-
server.use(
106-
http.get("/api/v2/organizations",()=>{
107-
returnHttpResponse.json([MockDefaultOrganization,MockOrganization2]);
108-
}),
109-
http.post("/api/v2/authcheck",async()=>{
110-
returnHttpResponse.json({
111-
[`${MockOrganization2.id}.editOrganization`]:true,
112-
viewDeploymentValues:true,
113-
});
114-
}),
115-
);
116-
awaitrenderPage("the-endless-void");
117-
awaitscreen.findByText("Organization not found");
118-
});
119-
120-
it("cannot edit organization",async()=>{
121-
server.use(
122-
http.get("/api/v2/organizations",()=>{
123-
returnHttpResponse.json([MockDefaultOrganization]);
124-
}),
125-
http.post("/api/v2/authcheck",async()=>{
126-
returnHttpResponse.json({
127-
viewDeploymentValues:true,
128-
});
129-
}),
130-
);
131-
// No form since they cannot edit, instead sees the summary view.
132-
awaitrenderPage(MockDefaultOrganization.name);
133-
expect(screen.queryByTestId("org-settings-form")).not.toBeInTheDocument();
134-
awaitscreen.findByRole("heading",{
135-
level:1,
136-
name:MockDefaultOrganization.display_name,
137-
});
138-
});
13979
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp