Skip to content

Commit

Permalink
username and avatar selector tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexia-May committed Oct 24, 2024
1 parent 5712f28 commit 12838ab
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 4 deletions.
194 changes: 194 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.2",
"@vitejs/plugin-react-swc": "^3.3.2",
"@vitest/coverage-v8": "^2.1.3",
"@vitest/ui": "^2.1.3",
"autoprefixer": "^10.4.20",
"eslint": "^9.11.1",
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/UsernameForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ export function UsernameForm({ input, setInput, avatar, setAvatar, error }) {
></label>
<div className="flex">
<span
data-testid="select-avatar"
className="relative inline-flex items-center px-3 text-sm text-gray-900 bg-gray-200 border border-e-0 border-gray-300 rounded-s-md dark:bg-gray-600 dark:text-gray-400 dark:border-gray-600 cursor-pointer"
onClick={() => setAvatarOpen(!avatarOpen)} // Toggle avatar dropdown on click
>
{avatar ? (
<img
data-testid="avatar-img"
className="w-8 h-8 rounded-full"
src={avatar}
alt="Selected Avatar"
Expand Down Expand Up @@ -73,7 +75,7 @@ export function UsernameForm({ input, setInput, avatar, setAvatar, error }) {

</div>
{avatarOpen && (
<div className="absolute z-10">
<div className="absolute z-10" data-testid="avatar-dropdown">
<AvatarDropdown
setAvatar={setAvatar}
setAvatarOpen={setAvatarOpen}
Expand Down
1 change: 0 additions & 1 deletion frontend/tests/components/placeholder.md

This file was deleted.

33 changes: 33 additions & 0 deletions frontend/tests/components/usernameForm.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//tests for the username form component visible on landing

//imports needed
import { render, screen } from "@testing-library/react";
import { describe, expect, test } from "vitest";
import { UsernameForm } from "../../src/components/UsernameForm";
import userEvent from "@testing-library/user-event";

describe("Username Form", () => {

//avatar selection tests
test("given an avatar link it is displayed", () => {
render(<UsernameForm avatar={"./testroute"}/>)
const imgEl = screen.getByTestId("avatar-img")
expect(imgEl).toHaveProperty('src', 'http://localhost:3000/testroute')
})

//avatar dropdown
test("user clicks on icon and sees the dropdown", async () => {
// user sees the username form
const user = userEvent.setup()
render(<UsernameForm />)
//user clicks on the icon
const buttonEl = screen.getByTestId("select-avatar")
await user.click(buttonEl)
//expect dropdown to appear
const dropdownEl = screen.getByTestId("avatar-dropdown")
expect(dropdownEl).toBeDefined()
})

})


1 change: 0 additions & 1 deletion frontend/tests/handlers/placeholder.md

This file was deleted.

1 change: 0 additions & 1 deletion frontend/tests/services/placeholder.md

This file was deleted.

0 comments on commit 12838ab

Please sign in to comment.