|
1 | | -import React from 'react'; |
2 | | -import { render, screen, fireEvent, within, waitFor} from '@testing-library/react'; |
3 | | -import { UserAccountView } from '../user-account-view'; |
| 1 | +import React from "react" |
| 2 | +import { |
| 3 | + fireEvent, |
| 4 | + render, |
| 5 | + screen, |
| 6 | + waitFor, |
| 7 | + within, |
| 8 | +} from "@testing-library/react" |
| 9 | +import { UserAccountView } from "../user-account-view" |
4 | 10 |
|
5 | 11 | const baseUser = { |
6 | | - name: "John Doe", |
7 | | - |
8 | | - orcid: "0000-0001-2345-6789", |
9 | | - location: "San Francisco, CA", |
10 | | - institution: "University of California", |
11 | | - links: ["https://example.com", "https://example.org"], |
12 | | - github: "johndoe", |
13 | | - }; |
| 12 | + name: "John Doe", |
| 13 | + |
| 14 | + orcid: "0000-0001-2345-6789", |
| 15 | + location: "San Francisco, CA", |
| 16 | + institution: "University of California", |
| 17 | + links: ["https://example.com", "https://example.org"], |
| 18 | + github: "johndoe", |
| 19 | +} |
14 | 20 |
|
15 | | -describe('<UserAccountView />', () => { |
16 | | - it('should render the user details correctly', () => { |
17 | | - render(<UserAccountView user={baseUser} />); |
| 21 | +describe("<UserAccountView />", () => { |
| 22 | + it("should render the user details correctly", () => { |
| 23 | + render(<UserAccountView user={baseUser} />) |
18 | 24 |
|
19 | 25 | // Check if user details are rendered |
20 | | - expect(screen.getByText('Name:')).toBeInTheDocument(); |
21 | | - expect(screen.getByText('John Doe')).toBeInTheDocument(); |
22 | | - expect(screen.getByText('Email:')).toBeInTheDocument(); |
23 | | - expect(screen.getByText('[email protected]')).toBeInTheDocument(); |
24 | | - expect(screen.getByText('ORCID:')).toBeInTheDocument(); |
25 | | - expect(screen.getByText('0000-0001-2345-6789')).toBeInTheDocument(); |
26 | | - expect(screen.getByText('johndoe')).toBeInTheDocument(); |
27 | | - }); |
| 26 | + expect(screen.getByText("Name:")).toBeInTheDocument() |
| 27 | + expect(screen.getByText("John Doe")).toBeInTheDocument() |
| 28 | + expect(screen.getByText("Email:")).toBeInTheDocument() |
| 29 | + expect(screen.getByText("[email protected]")).toBeInTheDocument() |
| 30 | + expect(screen.getByText("ORCID:")).toBeInTheDocument() |
| 31 | + expect(screen.getByText("0000-0001-2345-6789")).toBeInTheDocument() |
| 32 | + expect(screen.getByText("johndoe")).toBeInTheDocument() |
| 33 | + }) |
28 | 34 |
|
29 | | - it('should render links with EditableContent', async () => { |
30 | | - render(<UserAccountView user={baseUser} />); |
31 | | - const institutionSection = within(screen.getByText('Institution').closest('.user-meta-block')); |
32 | | - expect(screen.getByText('Institution')).toBeInTheDocument(); |
33 | | - const editButton = institutionSection.getByText('Edit'); |
34 | | - fireEvent.click(editButton); |
35 | | - const textbox = institutionSection.getByRole('textbox'); |
36 | | - fireEvent.change(textbox, { target: { value: 'New University' } }); |
37 | | - const saveButton = institutionSection.getByText('Save'); |
38 | | - const closeButton = institutionSection.getByText('Close'); |
39 | | - fireEvent.click(saveButton); |
40 | | - fireEvent.click(closeButton); |
| 35 | + it("should render links with EditableContent", async () => { |
| 36 | + render(<UserAccountView user={baseUser} />) |
| 37 | + const institutionSection = within( |
| 38 | + screen.getByText("Institution").closest(".user-meta-block"), |
| 39 | + ) |
| 40 | + expect(screen.getByText("Institution")).toBeInTheDocument() |
| 41 | + const editButton = institutionSection.getByText("Edit") |
| 42 | + fireEvent.click(editButton) |
| 43 | + const textbox = institutionSection.getByRole("textbox") |
| 44 | + fireEvent.change(textbox, { target: { value: "New University" } }) |
| 45 | + const saveButton = institutionSection.getByText("Save") |
| 46 | + const closeButton = institutionSection.getByText("Close") |
| 47 | + fireEvent.click(saveButton) |
| 48 | + fireEvent.click(closeButton) |
41 | 49 | // Add debug step |
42 | | - await waitFor(() => screen.debug()); |
| 50 | + await waitFor(() => screen.debug()) |
43 | 51 | // Use a flexible matcher to check for text |
44 | 52 | await waitFor(() => |
45 | | - expect(institutionSection.getByText('New University')).toBeInTheDocument() |
46 | | - ); |
47 | | - }); |
48 | | - |
| 53 | + expect(institutionSection.getByText("New University")).toBeInTheDocument() |
| 54 | + ) |
| 55 | + }) |
49 | 56 |
|
50 | | - it('should render location with EditableContent', async () => { |
51 | | - render(<UserAccountView user={baseUser} />); |
52 | | - const locationSection = within(screen.getByText('Location').closest('.user-meta-block')); |
53 | | - expect(screen.getByText('Location')).toBeInTheDocument(); |
54 | | - const editButton = locationSection.getByText('Edit'); |
55 | | - fireEvent.click(editButton); |
56 | | - const textbox = locationSection.getByRole('textbox'); |
57 | | - fireEvent.change(textbox, { target: { value: 'Marin, CA' } }); |
58 | | - const saveButton = locationSection.getByText('Save'); |
59 | | - const closeButton = locationSection.getByText('Close'); |
60 | | - fireEvent.click(saveButton); |
61 | | - fireEvent.click(closeButton); |
| 57 | + it("should render location with EditableContent", async () => { |
| 58 | + render(<UserAccountView user={baseUser} />) |
| 59 | + const locationSection = within( |
| 60 | + screen.getByText("Location").closest(".user-meta-block"), |
| 61 | + ) |
| 62 | + expect(screen.getByText("Location")).toBeInTheDocument() |
| 63 | + const editButton = locationSection.getByText("Edit") |
| 64 | + fireEvent.click(editButton) |
| 65 | + const textbox = locationSection.getByRole("textbox") |
| 66 | + fireEvent.change(textbox, { target: { value: "Marin, CA" } }) |
| 67 | + const saveButton = locationSection.getByText("Save") |
| 68 | + const closeButton = locationSection.getByText("Close") |
| 69 | + fireEvent.click(saveButton) |
| 70 | + fireEvent.click(closeButton) |
62 | 71 | // Add debug step |
63 | | - await waitFor(() => screen.debug()); |
| 72 | + await waitFor(() => screen.debug()) |
64 | 73 | // Use a flexible matcher to check for text |
65 | 74 | await waitFor(() => |
66 | | - expect(locationSection.getByText('Marin, CA')).toBeInTheDocument() |
67 | | - ); |
68 | | - }); |
69 | | -}); |
| 75 | + expect(locationSection.getByText("Marin, CA")).toBeInTheDocument() |
| 76 | + ) |
| 77 | + }) |
| 78 | +}) |
0 commit comments