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

feat: have user type name of thing to delete for extra safety#4080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
presleyp merged 12 commits intomainfrompresleyp/destructive-dialog
Sep 20, 2022
Merged
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Fix the worst of the UsersPage test bugs
  • Loading branch information
@presleyp
presleyp committedSep 15, 2022
commit06e6e658015e693ec1e348faddff3b5f33c6cb07
48 changes: 27 additions & 21 deletionssite/src/pages/UsersPage/UsersPage.test.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,16 +26,18 @@ const { t } = i18n

const suspendUser = async (setupActionSpies: () => void) => {
// Get the first user in the table
const users = await screen.findAllByText(/.*@coder.com/)
const firstUserRow = users[0].closest("tr")
if (!firstUserRow) {
throw new Error("Error on get the first user row")
}
waitFor(async () => {
const users = await screen.findAllByText(/.*@coder.com/)
const firstUserRow = users[0].closest("tr")

// Click on the "more" button to display the "Suspend" option
const moreButton = within(firstUserRow).getByLabelText("more")
if (!firstUserRow) {
throw new Error("Error on get the first user row")
}
// Click on the "more" button to display the "Suspend" option
const moreButton = within(firstUserRow).getByLabelText("more")

fireEvent.click(moreButton)
fireEvent.click(moreButton)
})

const menu = await screen.findByRole("menu")
const suspendButton = within(menu).getByText(UsersTableBodyLanguage.suspendMenuItem)
Expand All@@ -58,21 +60,23 @@ const suspendUser = async (setupActionSpies: () => void) => {

const deleteUser = async (setupActionSpies: () => void) => {
// Get the first user in the table
const users = await screen.findAllByText(/.*@coder.com/)
const firstUserRow = users[0].closest("tr")
if (!firstUserRow) {
throw new Error("Error on get the first user row")
}
waitFor(async () => {
const users = await screen.findAllByText(/.*@coder.com/)
const firstUserRow = users[0].closest("tr")
if (!firstUserRow) {
throw new Error("Error on get the first user row")
}

// Click on the "more" button to display the "Suspend" option
const moreButton = within(firstUserRow).getByLabelText("more")
// Click on the "more" button to display the "Delete" option
const moreButton = within(firstUserRow).getByLabelText("more")

fireEvent.click(moreButton)
fireEvent.click(moreButton)
})

const menu = await screen.findByRole("menu")
constsuspendButton = within(menu).getByText(UsersTableBodyLanguage.deleteMenuItem)
constdeleteButton = within(menu).getByText(UsersTableBodyLanguage.deleteMenuItem)

fireEvent.click(suspendButton)
fireEvent.click(deleteButton)

// Check if the confirm message is displayed
const confirmDialog = await screen.findByRole("dialog")
Expand All@@ -83,7 +87,9 @@ const deleteUser = async (setupActionSpies: () => void) => {
// Confirm with text input
const labelText = t("deleteDialog.confirmLabel", { ns: "common", entity: "user" })
const textField = screen.getByLabelText(labelText)
await userEvent.type(textField, MockUser.username)
waitFor(async () => {
await userEvent.type(textField, MockUser.username)
})

// Setup spies to check the actions after
setupActionSpies()
Expand DownExpand Up@@ -284,7 +290,7 @@ describe("UsersPage", () => {
jest.spyOn(API, "deleteUser").mockResolvedValueOnce(undefined)
jest
.spyOn(API, "getUsers")
.mockImplementationOnce(() => Promise.resolve([MockUser,MockUser2]))
.mockImplementationOnce(() => Promise.resolve([MockUser2]))
})

// Check if the success message is displayed
Expand All@@ -294,7 +300,7 @@ describe("UsersPage", () => {
expect(API.deleteUser).toBeCalledTimes(1)
expect(API.deleteUser).toBeCalledWith(MockUser.id)

// Check if the users list wasreload
// Check if the users list wasreloaded
await waitFor(() => expect(API.getUsers).toBeCalledTimes(1))
})
})
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp