Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions E2E/Auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async function signUpAndTestWrongPassword(page: Page) {

// Desktop authentication
test.describe('Desktop authentication', () => {
test.beforeEach(async ({}, testInfo) => {
test.beforeEach(async ({ page: _page }, testInfo) => {
test.skip(
['mobile-chrome', 'Mobile Safari'].includes(testInfo.project.name),
'Desktop tests are not run on mobile projects'
Expand All @@ -126,7 +126,7 @@ test.describe('Desktop authentication', () => {

// Mobile authentication
test.describe('Mobile authentication', () => {
test.beforeEach(async ({}, testInfo) => {
test.beforeEach(async ({ page: _page }, testInfo) => {
test.skip(
!['mobile-chrome', 'Mobile Safari'].includes(testInfo.project.name),
'Mobile tests are only run on mobile projects'
Expand Down
31 changes: 19 additions & 12 deletions E2E/Fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { test as base, expect } from '@playwright/test'
import { test as base, expect, type APIRequestContext } from '@playwright/test'
import { BACKEND_URL } from './E2EConfig'
import { addCoverageReport } from 'monocart-reporter'

Expand All @@ -21,13 +21,17 @@ type Fixtures = {
seedReview: (userId: number) => Promise<void>
}

// GraphQL helper
async function graphql(
request: any,
type GraphQLResponse<TData> = {
data?: TData
errors?: { message: string }[]
}

async function graphql<TData>(
request: APIRequestContext,
query: string,
variables = {},
variables: Record<string, unknown> = {},
token?: string
) {
): Promise<TData> {
const res = await request.post(BACKEND_URL, {
headers: token
? { Authorization: `Bearer ${token}` }
Expand All @@ -42,24 +46,27 @@ async function graphql(
)
}

const json = await res.json()
const json: GraphQLResponse<TData> = await res.json()

if (json.errors) {
if (json.errors?.length) {
throw new Error(json.errors[0].message)
}

if (json.data === undefined) {
throw new Error('Backend response did not include data')
}
return json.data
}

// Create a test user
async function createUser(request: any): Promise<TestUser> {
async function createUser(request: APIRequestContext): Promise<TestUser> {
const stamp =
`${Date.now()}${Math.random().toString(36).slice(2, 6)}`

const username = `e2e${stamp}`
const email = `e2e+${stamp}@example.com`

const data = await graphql(
const data = await graphql<{ signup: TestUser }>(
request,
`
mutation($u: String!, $e: String!, $p: String!) {
Expand Down Expand Up @@ -136,7 +143,7 @@ export const test = base.extend<Fixtures & { coverage: void }>({
throw new Error(`Unknown test user ID: ${userId}`)
}

const gamesData = await graphql(
const gamesData = await graphql<{ games: { appid: number }[] }>(
request,
`
query {
Expand Down Expand Up @@ -186,7 +193,7 @@ export const test = base.extend<Fixtures & { coverage: void }>({
)
}

const gamesData = await graphql(
const gamesData = await graphql<{ games: { appid: number }[] }>(
request,
`
query {
Expand Down
4 changes: 2 additions & 2 deletions E2E/Friendpage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function addFriend(page: Page, friendId: string) {

// Desktop tests
test.describe('FriendPage', () => {
test.beforeEach(async ({}, testInfo) => {
test.beforeEach(async ({ page: _page }, testInfo) => {
test.skip(
['mobile-chrome', 'Mobile Safari'].includes(testInfo.project.name),
'Desktop tests are not run on mobile projects'
Expand All @@ -102,7 +102,7 @@ test.describe('FriendPage', () => {

// Mobile tests
test.describe('Mobile FriendPage', () => {
test.beforeEach(async ({}, testInfo) => {
test.beforeEach(async ({ page: _page }, testInfo) => {
test.skip(
!['mobile-chrome', 'Mobile Safari'].includes(testInfo.project.name),
'Mobile tests are only run on mobile projects'
Expand Down
8 changes: 4 additions & 4 deletions E2E/Mainpage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function navigateFromRecentReviewToGame(

// Desktop tests
test.describe('Desktop MainPage - Carousels', () => {
test.beforeEach(async ({}, testInfo) => {
test.beforeEach(async ({ page: _page }, testInfo) => {
test.skip(
['mobile-chrome', 'Mobile Safari'].includes(testInfo.project.name),
'Desktop tests are not run on mobile projects'
Expand All @@ -60,7 +60,7 @@ test.describe('Desktop MainPage - Carousels', () => {

// Mobile tests
test.describe('Mobile MainPage - Carousels', () => {
test.beforeEach(async ({}, testInfo) => {
test.beforeEach(async ({ page: _page }, testInfo) => {
test.skip(
!['mobile-chrome', 'Mobile Safari'].includes(testInfo.project.name),
'Mobile tests are only run on mobile projects'
Expand All @@ -86,7 +86,7 @@ test.describe('Mobile MainPage - Carousels', () => {

// Recent review navigation - Desktop
test.describe('Desktop MainPage components', () => {
test.beforeEach(async ({}, testInfo) => {
test.beforeEach(async ({ page: _page }, testInfo) => {
test.skip(
['mobile-chrome', 'Mobile Safari'].includes(testInfo.project.name),
'Desktop tests are not run on mobile projects'
Expand All @@ -104,7 +104,7 @@ test.describe('Desktop MainPage components', () => {

// Recent review navigation - Mobile
test.describe('Mobile MainPage components', () => {
test.beforeEach(async ({}, testInfo) => {
test.beforeEach(async ({ page: _page }, testInfo) => {
test.skip(
!['mobile-chrome', 'Mobile Safari'].includes(testInfo.project.name),
'Mobile tests are only run on mobile projects'
Expand Down
4 changes: 2 additions & 2 deletions E2E/MainpageToGamepage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function navigateToWishlist(page: Page, isMobile = false) {

// Desktop test
test.describe('Desktop top game and wishlist', () => {
test.beforeEach(async ({}, testInfo) => {
test.beforeEach(async ({ page: _page }, testInfo) => {
test.skip(
['mobile-chrome', 'Mobile Safari'].includes(testInfo.project.name),
'Desktop tests are not run on mobile projects'
Expand All @@ -93,7 +93,7 @@ test.describe('Desktop top game and wishlist', () => {

// Mobile test
test.describe('Mobile top game and wishlist', () => {
test.beforeEach(async ({}, testInfo) => {
test.beforeEach(async ({ page: _page }, testInfo) => {
test.skip(
!['mobile-chrome', 'Mobile Safari'].includes(testInfo.project.name),
'Mobile tests are only run on mobile projects'
Expand Down
8 changes: 4 additions & 4 deletions E2E/Navigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ async function navigateMobile(

// Desktop header navigation
test.describe('Desktop header navigation', () => {
test.beforeEach(async ({}, testInfo) => {
test.beforeEach(async ({ page: _page }, testInfo) => {
test.skip(
['mobile-chrome', 'Mobile Safari'].includes(testInfo.project.name),
'Desktop tests are not run on mobile projects'
)
})

test('Navigate through all header pages and sign out', async ({ page, user }) => {
test('Navigate through all header pages and sign out', async ({ page, user: _user }) => {
await openMainPage(page)

// MainPage -> SearchPage
Expand Down Expand Up @@ -111,7 +111,7 @@ test.describe('Desktop header navigation', () => {

// Mobile header navigation
test.describe('Mobile header navigation', () => {
test.beforeEach(async ({}, testInfo) => {
test.beforeEach(async ({ page: _page }, testInfo) => {
test.skip(
!['mobile-chrome', 'Mobile Safari'].includes(testInfo.project.name),
'Mobile tests are only run on mobile projects'
Expand All @@ -122,7 +122,7 @@ test.describe('Mobile header navigation', () => {
viewport: { width: 390, height: 844 }
})

test('Navigate through all header pages and sign out', async ({ page, user }) => {
test('Navigate through all header pages and sign out', async ({ page, user: _user }) => {
await openMainPage(page)

// MainPage -> SearchPage
Expand Down
8 changes: 4 additions & 4 deletions E2E/Profilepage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ async function editUserProfile(page: Page) {

// Desktop profile tests
test.describe('Desktop ProfilePage', () => {
test.beforeEach(async ({}, testInfo) => {
test.beforeEach(async ({ page: _page }, testInfo) => {
test.skip(
['mobile-chrome', 'Mobile Safari'].includes(testInfo.project.name),
'Desktop tests are not run on mobile projects'
)
})

test('User can edit their profile', async ({ page, user }) => {
test('User can edit their profile', async ({ page, user: _user }) => {
await editUserProfile(page)
})
})

// Mobile profile tests
test.describe('Mobile ProfilePage', () => {
test.beforeEach(async ({}, testInfo) => {
test.beforeEach(async ({ page: _page }, testInfo) => {
test.skip(
!['mobile-chrome', 'Mobile Safari'].includes(testInfo.project.name),
'Mobile tests are only run on mobile projects'
Expand All @@ -63,7 +63,7 @@ test.describe('Mobile ProfilePage', () => {
viewport: { width: 390, height: 844 }
})

test('User can edit their profile on mobile', async ({ page, user }) => {
test('User can edit their profile on mobile', async ({ page, user: _user }) => {
await editUserProfile(page)
})
})
4 changes: 2 additions & 2 deletions E2E/Reviews.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function navigateFromRecentReviewToGame(

// Desktop tests
test.describe('Desktop Recent Reviews', () => {
test.beforeEach(async ({}, testInfo) => {
test.beforeEach(async ({ page: _page }, testInfo) => {
test.skip(
['mobile-chrome', 'Mobile Safari'].includes(testInfo.project.name),
'Desktop tests are not run on mobile projects'
Expand All @@ -50,7 +50,7 @@ async function navigateFromRecentReviewToGame(

// Mobile tests
test.describe('Mobile Recent Reviews', () => {
test.beforeEach(async ({}, testInfo) => {
test.beforeEach(async ({ page: _page }, testInfo) => {
test.skip(
!['mobile-chrome', 'Mobile Safari'].includes(testInfo.project.name),
'Mobile tests are only run on mobile projects'
Expand Down
4 changes: 2 additions & 2 deletions E2E/Searchpage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async function checkSearchPagination(page: Page, checkReturnToFirstPage = true)

// Desktop SearchPage tests
test.describe('Desktop SearchPage', () => {
test.beforeEach(async ({}, testInfo) => {
test.beforeEach(async ({ page: _page }, testInfo) => {
test.skip(
['mobile-chrome', 'Mobile Safari'].includes(testInfo.project.name),
'Desktop tests are not run on mobile projects'
Expand Down Expand Up @@ -195,7 +195,7 @@ test.describe('Mobile SearchPage', () => {
viewport: { width: 390, height: 844 }
})

test.beforeEach(async ({}, testInfo) => {
test.beforeEach(async ({ page: _page }, testInfo) => {
test.skip(
!['mobile-chrome', 'Mobile Safari'].includes(testInfo.project.name),
'Mobile tests are only run on mobile projects'
Expand Down
4 changes: 2 additions & 2 deletions E2E/Wishlist.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async function checkWishlistHorizontalOverflow(page: Page) {

// Desktop WishlistPage tests
test.describe('Desktop WishlistPage', () => {
test.beforeEach(async ({}, testInfo) => {
test.beforeEach(async ({ page: _page }, testInfo) => {
test.skip(
['mobile-chrome', 'Mobile Safari'].includes(testInfo.project.name),
'Desktop tests are not run on mobile projects'
Expand Down Expand Up @@ -137,7 +137,7 @@ test.describe('Mobile WishlistPage', () => {
viewport: { width: 390, height: 844 }
})

test.beforeEach(async ({}, testInfo) => {
test.beforeEach(async ({ page: _page }, testInfo) => {
test.skip(
!['mobile-chrome', 'Mobile Safari'].includes(testInfo.project.name),
'Mobile tests are only run on mobile projects'
Expand Down
31 changes: 12 additions & 19 deletions Frontend/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ import { UseAuth } from '../context/AuthContext'

export default function Header() {
const { user, logout } = UseAuth()
const [menuOpen, setMenuOpen] = useState(false)

const location = useLocation()

useEffect(() => {
setMenuOpen(false)
}, [location.pathname])
const [menuOpenPath, setMenuOpenPath] = useState<string | null>(null)
const menuOpen = menuOpenPath === location.pathname

const navigationLinks = [
{ to: '/', label: 'Home', icon: <House /> },
Expand All @@ -35,14 +31,14 @@ export default function Header() {
]

const CloseMenu = () => {
setMenuOpen(false)
setMenuOpenPath(null)
}

// Close the menu with Escape
useEffect(() => {
if (!menuOpen) return undefined
const HandleKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Escape') setMenuOpen(false)
if (e.key === 'Escape') setMenuOpenPath(null)
}
window.addEventListener('keydown', HandleKeyDown)
return () => window.removeEventListener('keydown', HandleKeyDown)
Expand All @@ -57,7 +53,11 @@ export default function Header() {
aria-label={menuOpen ? 'Close menu' : 'Open menu'}
aria-expanded={menuOpen}
aria-controls="navigationMenue"
onClick={() => setMenuOpen((open) => !open)}
onClick={() =>
setMenuOpenPath((path) =>
path === location.pathname ? null : location.pathname
)
}
>
{menuOpen ? <X /> : <Menu />}
</button>
Expand All @@ -83,30 +83,23 @@ export default function Header() {
key={link.to}
to={link.to}
end
className={({ isActive }) =>
isActive ? 'is-active' : undefined
}
className={({ isActive }) => (isActive ? 'is-active' : undefined)}
>
{link.icon}
{link.label}
</NavLink>
))}

{user ? (
<Link
to="/"
onClick={logout}
>
<Link to="/" onClick={logout}>
<LogOut />
Sign Out
</Link>
) : (
<NavLink
to="/SignIn"
end
className={({ isActive }) =>
isActive ? 'is-active' : undefined
}
className={({ isActive }) => (isActive ? 'is-active' : undefined)}
>
<LogIn />
Sign In
Expand Down
4 changes: 2 additions & 2 deletions Frontend/src/components/ReviewCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ export default function ReviewCard({
className="app-button"
size="small"
onClick={() => onEdit(review)}
aria-label={`Edit review for ${game?.name} `}
aria-label={game ? `Edit review for ${game.name}` : 'Edit review'}
>
Edit
</Button>
<Button
className="reviewCardDelete"
size="small"
onClick={() => onDelete(review)}
aria-label={`Delete review for ${game?.name} `}
aria-label={game ? `Delete review for ${game.name}` : 'Delete review'}
>
Delete
</Button>
Expand Down
Loading