From 1992f5bdd7bd0652ed03c3804358bef474f54a2c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Elida=20Kj=C3=B8pstad?=
<77298927+Stelaug@users.noreply.github.com>
Date: Tue, 3 Nov 2026 16:01:20 +0100
Subject: [PATCH 1/6] feat: adds Title: A-Z as defalt sort
---
.../FrontendLogic/SearchPageLogicFrontend.ts | 17 +++++++++++++++++
Frontend/src/pages/SearchPage.tsx | 12 +++++-------
2 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/Frontend/src/FrontendLogic/SearchPageLogicFrontend.ts b/Frontend/src/FrontendLogic/SearchPageLogicFrontend.ts
index 242de39..8f6f1a4 100644
--- a/Frontend/src/FrontendLogic/SearchPageLogicFrontend.ts
+++ b/Frontend/src/FrontendLogic/SearchPageLogicFrontend.ts
@@ -76,3 +76,20 @@ export function GetPageSearchpage(): number {
return 1
}
}
+
+export function ClearFilterAndSort() {
+ try {
+ sessionStorage.removeItem('GameStart:sortOptionSearchpage')
+ sessionStorage.removeItem('GameStart:filtersSearchpage')
+ } catch (error) {
+ console.log(`Could not clear filters and sorting from storage`)
+ }
+}
+
+export function ClearSearch() {
+ try {
+ sessionStorage.removeItem('GameStart:pageSearchpage')
+ } catch (error) {
+ console.log(`Could not clear search from storage`)
+ }
+}
\ No newline at end of file
diff --git a/Frontend/src/pages/SearchPage.tsx b/Frontend/src/pages/SearchPage.tsx
index 13aac0c..6d03c64 100644
--- a/Frontend/src/pages/SearchPage.tsx
+++ b/Frontend/src/pages/SearchPage.tsx
@@ -32,6 +32,7 @@ import type { SelectChangeEvent } from '@mui/material'
type SortOption = '' | 'discount-desc' | 'price-asc' | 'price-desc' | 'title-asc'
+const DEFAULT_SORT: SortOption = 'title-asc'
const SORT_OPTIONS: SortOption[] = ['', 'discount-desc', 'price-asc', 'price-desc', 'title-asc']
const GAMES_PER_PAGE = 12
@@ -39,7 +40,7 @@ const NO_GAMES: Game[] = []
function GetInitialSort(): SortOption {
const saved = GetSortOptionSearchpage()
- return SORT_OPTIONS.includes(saved as SortOption) ? (saved as SortOption) : ''
+ return SORT_OPTIONS.includes(saved as SortOption) ? (saved as SortOption) : DEFAULT_SORT
}
export function SearchPage() {
@@ -56,7 +57,7 @@ export function SearchPage() {
const [searchVal, setSearchVal] = useState(GetQuerySearchpage)
const [searchQuery, setSearchQuery] = useState(GetQuerySearchpage)
const [isFilterActive, setIsFilterActive] = useState(
- () => activeFilters.length > 0 || activeSorting !== ''
+ () => activeFilters.length > 0 || activeSorting !== DEFAULT_SORT
)
// fetches the genres from the DB
@@ -188,8 +189,8 @@ export function SearchPage() {
onChange={HandleSortChange}
label="Sort by"
>
-
))}
-
-
+
+
)}
From 3ed9e9bfb711b8d1fe8902495f31097d5698c3c8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Elida=20Kj=C3=B8pstad?=
<77298927+Stelaug@users.noreply.github.com>
Date: Thu, 5 Nov 2026 19:56:21 +0100
Subject: [PATCH 4/6] style: adds styling to the buttons
---
Frontend/src/css/SearchPage.css | 60 ++++++++++++++++++++++++++-----
Frontend/src/pages/SearchPage.tsx | 42 +++++++++++-----------
2 files changed, 72 insertions(+), 30 deletions(-)
diff --git a/Frontend/src/css/SearchPage.css b/Frontend/src/css/SearchPage.css
index 48871c6..ba49ce8 100644
--- a/Frontend/src/css/SearchPage.css
+++ b/Frontend/src/css/SearchPage.css
@@ -53,11 +53,11 @@
.filtersection {
box-sizing: border-box;
- display: flex;
- flex-wrap: wrap;
+ display: grid;
+ grid-template-columns: repeat(2, minmax(0, 1fr));
+ align-items: start;
align-self: center;
- justify-content: center;
- gap: 0.5rem;
+ gap: 0.75rem 0.5rem;
width: min(480px, calc(100% - 32px));
padding: 16px;
border: 1px solid var(--primary-accent-color);
@@ -65,13 +65,55 @@
}
.filtersection .MuiFormControl-root {
- flex: 1 1 200px;
- min-width: min(100%, 140px);
+ min-width: 0;
+}
+
+.filtersection .resetButton.MuiButton-root,
+.filtersection .removeFiltersButton.MuiButton-root {
+ width: 100%;
+ padding: 0.6rem 1rem;
+ border: none;
+ border-radius: 4px;
+ background-color: var(--primary-component-color);
+ color: var(--primary-text-color);
+ font-family: var(--primary-font);
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
+}
+
+.filtersection .resetButton.MuiButton-root:hover,
+.filtersection .removeFiltersButton.MuiButton-root:hover {
+ background-color: var(--primary-accent-color);
+}
+
+.filtersection .resetButton.MuiButton-root.Mui-disabled,
+.filtersection .removeFiltersButton.MuiButton-root.Mui-disabled {
+ background-color: var(--secondary-component-color);
+ color: rgba(0, 0, 0, 0.4);
+ box-shadow: none;
+}
+
+.filtersection .MuiOutlinedInput-root .MuiOutlinedInput-notchedOutline {
+ border-color: var(--primary-component-color);
}
-@media (min-width: 600px) {
- .filtersection .MuiFormControl-root {
- min-width: 200px;
+.filtersection .MuiOutlinedInput-root:hover .MuiOutlinedInput-notchedOutline,
+.filtersection .MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline {
+ border-color: var(--primary-accent-color);
+}
+
+.filtersection .MuiInputLabel-root.Mui-focused {
+ color: var(--primary-accent-color);
+}
+
+@media (max-width: 599px) {
+ .filtersection {
+ grid-template-columns: minmax(0, 1fr);
+ }
+
+ .filtersection .resetButton,
+ .filtersection .removeFiltersButton {
+ grid-column: 1;
+ grid-row: auto;
}
}
diff --git a/Frontend/src/pages/SearchPage.tsx b/Frontend/src/pages/SearchPage.tsx
index 012ae35..fc328c7 100644
--- a/Frontend/src/pages/SearchPage.tsx
+++ b/Frontend/src/pages/SearchPage.tsx
@@ -265,28 +265,28 @@ export function SearchPage() {
))}
-
-
+
+
)}
Date: Fri, 6 Nov 2026 08:20:06 +0100
Subject: [PATCH 5/6] test: updates the test for searchpage to work with the
new functionality
---
Frontend/src/pages/SearchPage.tsx | 2 +-
Frontend/src/tests/SearchPage.test.tsx | 418 +++++++++++++++++++++++--
2 files changed, 401 insertions(+), 19 deletions(-)
diff --git a/Frontend/src/pages/SearchPage.tsx b/Frontend/src/pages/SearchPage.tsx
index fc328c7..a5d7363 100644
--- a/Frontend/src/pages/SearchPage.tsx
+++ b/Frontend/src/pages/SearchPage.tsx
@@ -62,7 +62,7 @@ export function SearchPage() {
const [searchVal, setSearchVal] = useState(GetQuerySearchpage)
const [searchQuery, setSearchQuery] = useState(GetQuerySearchpage)
const [isFilterActive, setIsFilterActive] = useState(GetFilterMenuOpenSearchpage)
- const appliedFilters = isFilterActive ? activeFilters : NO_FILTERS
+ const appliedFilters = isFilterActive && activeFilters.length > 0 ? activeFilters : NO_FILTERS
const appliedSorting = isFilterActive ? activeSorting : DEFAULT_SORT
// fetches the genres from the DB
diff --git a/Frontend/src/tests/SearchPage.test.tsx b/Frontend/src/tests/SearchPage.test.tsx
index fe49923..067935f 100644
--- a/Frontend/src/tests/SearchPage.test.tsx
+++ b/Frontend/src/tests/SearchPage.test.tsx
@@ -101,22 +101,66 @@ async function RenderWithNamedGames() {
await screen.findByRole('heading', { name: 'Doom' })
}
-function OpenFilters() {
+const DEFAULT_SORT = 'title-asc'
+
+// Session storage keys used by the page
+const KEY_QUERY = 'GameStart:querySearchpage'
+const KEY_SORT = 'GameStart:sortOptionSearchpage'
+const KEY_FILTERS = 'GameStart:filtersSearchpage'
+const KEY_PAGE = 'GameStart:pageSearchpage'
+const KEY_MENU = 'GameStart:filterMenuOpenSearchpage'
+
+// Clicks the funnel button. It opens the menu when it is closed and closes it when it is open.
+function ToggleFilters() {
fireEvent.click(screen.getByRole('button', { name: 'Toggle filters' }))
}
+function OpenFilters() {
+ ToggleFilters()
+}
+
function Search(text: string) {
const input = screen.getByPlaceholderText('Search here or use filter')
fireEvent.change(input, { target: { value: text } })
fireEvent.submit(input.closest('form') as HTMLFormElement)
}
-function ChooseSort(optionName: string) {
- OpenFilters()
+// Picks a sort option in the sorting menu, which must already be open
+function PickSort(optionName: string) {
fireEvent.mouseDown(screen.getByRole('combobox', { name: 'Sort by' }))
fireEvent.click(screen.getByRole('option', { name: optionName }))
}
+function ChooseSort(optionName: string) {
+ OpenFilters()
+ PickSort(optionName)
+}
+
+function ClickButton(name: string) {
+ fireEvent.click(screen.getByRole('button', { name }))
+}
+
+function IsDisabled(name: string) {
+ return screen.getByRole('button', { name }).hasAttribute('disabled')
+}
+
+// Saves what the page would have saved in an earlier visit
+function SaveEarlierVisit(saved: {
+ query?: string
+ sort?: string
+ filters?: string[]
+ page?: number
+ menuOpen?: boolean
+}) {
+ if (saved.query !== undefined) sessionStorage.setItem(KEY_QUERY, JSON.stringify(saved.query))
+ if (saved.sort !== undefined) sessionStorage.setItem(KEY_SORT, JSON.stringify(saved.sort))
+ if (saved.filters !== undefined)
+ sessionStorage.setItem(KEY_FILTERS, JSON.stringify(saved.filters))
+ if (saved.page !== undefined) sessionStorage.setItem(KEY_PAGE, JSON.stringify(saved.page))
+ if (saved.menuOpen !== undefined)
+ sessionStorage.setItem(KEY_MENU, JSON.stringify(saved.menuOpen))
+}
+
// The options object the page passes as the third argument
function LastOptions() {
return FetchGamesFromDB.mock.lastCall?.[2]
@@ -147,7 +191,7 @@ describe('SearchPage', () => {
expect(FetchGamesFromDB).toHaveBeenCalledWith(12, 0, {
search: '',
genres: [],
- sort: ''
+ sort: DEFAULT_SORT
})
})
@@ -188,13 +232,29 @@ describe('SearchPage', () => {
const filterToggle = screen.getByRole('button', { name: 'Toggle filters' })
expect(filterToggle.getAttribute('aria-pressed')).toBe('false')
- expect(screen.queryByText('Sort by:')).toBeNull()
+ expect(screen.queryByRole('combobox', { name: 'Sort by' })).toBeNull()
+ expect(screen.queryByRole('combobox', { name: 'Filter by genre' })).toBeNull()
fireEvent.click(filterToggle)
expect(filterToggle.getAttribute('aria-pressed')).toBe('true')
expect(screen.getByRole('combobox', { name: 'Sort by' })).toBeTruthy()
expect(screen.getByRole('combobox', { name: 'Filter by genre' })).toBeTruthy()
+
+ fireEvent.click(filterToggle)
+
+ expect(filterToggle.getAttribute('aria-pressed')).toBe('false')
+ expect(screen.queryByRole('combobox', { name: 'Sort by' })).toBeNull()
+ })
+
+ it('shows Title: A to Z as the sorting when nothing else is chosen', async () => {
+ await RenderWithNamedGames()
+
+ OpenFilters()
+
+ expect(screen.getByRole('combobox', { name: 'Sort by' }).textContent).toBe(
+ 'Title: A to Z'
+ )
})
})
@@ -256,11 +316,16 @@ describe('SearchPage', () => {
})
describe('sorting', () => {
+ it('sorts by title A to Z when no other sorting is chosen', async () => {
+ await RenderWithNamedGames()
+
+ expect(LastOptions()?.sort).toBe('title-asc')
+ })
+
it.each([
['Price: low to high', 'price-asc'],
['Price: high to low', 'price-desc'],
- ['Discount: high to low', 'discount-desc'],
- ['Title: A to Z', 'title-asc']
+ ['Discount: high to low', 'discount-desc']
])('sends the "%s" sort to the backend as %s', async (label, sort) => {
await RenderWithNamedGames()
@@ -269,6 +334,35 @@ describe('SearchPage', () => {
await waitFor(() => expect(LastOptions()?.sort).toBe(sort))
})
+ it('can go back to Title: A to Z after another sort was chosen', async () => {
+ await RenderWithNamedGames()
+
+ ChooseSort('Price: low to high')
+ await waitFor(() => expect(LastOptions()?.sort).toBe('price-asc'))
+ await waitFor(() => expect(screen.queryByRole('listbox')).toBeNull())
+
+ PickSort('Title: A to Z')
+
+ await waitFor(() => expect(LastOptions()?.sort).toBe('title-asc'))
+ })
+
+ it('goes back to page 1 when the sorting changes', async () => {
+ GetTotalGameCount.mockResolvedValue(30)
+ SaveEarlierVisit({ page: 2 })
+ await RenderWithNamedGames()
+ expect(FetchGamesFromDB).toHaveBeenLastCalledWith(12, 12, expect.anything())
+
+ ChooseSort('Price: low to high')
+
+ await waitFor(() =>
+ expect(FetchGamesFromDB).toHaveBeenLastCalledWith(
+ 12,
+ 0,
+ expect.objectContaining({ sort: 'price-asc' })
+ )
+ )
+ })
+
it('shows the games in the order the backend returns them', async () => {
FetchGamesFromDB.mockResolvedValue([celeste, doom, anno])
RenderSearchPage()
@@ -324,12 +418,261 @@ describe('SearchPage', () => {
expect(LastOptions()).toEqual({
search: 'celeste',
genres: ['Indie'],
- sort: ''
+ sort: DEFAULT_SORT
})
)
})
})
+ describe('closing and reopening the filter menu', () => {
+ const chosen = { sort: 'price-desc', filters: ['Indie'], menuOpen: true }
+
+ it('applies the chosen sorting and genres while the menu is open', async () => {
+ SaveEarlierVisit(chosen)
+
+ await RenderWithNamedGames()
+
+ expect(LastOptions()).toEqual({ search: '', genres: ['Indie'], sort: 'price-desc' })
+ expect(GetTotalGameCount).toHaveBeenLastCalledWith({ search: '', genres: ['Indie'] })
+ })
+
+ it('goes back to the default sorting and no genres when the menu is closed', async () => {
+ SaveEarlierVisit(chosen)
+ await RenderWithNamedGames()
+
+ ToggleFilters()
+
+ await waitFor(() =>
+ expect(LastOptions()).toEqual({ search: '', genres: [], sort: DEFAULT_SORT })
+ )
+ expect(GetTotalGameCount).toHaveBeenLastCalledWith({ search: '', genres: [] })
+ })
+
+ it('keeps the search when the menu is closed', async () => {
+ SaveEarlierVisit({ ...chosen, query: 'doom' })
+ await RenderWithNamedGames()
+
+ ToggleFilters()
+
+ await waitFor(() =>
+ expect(LastOptions()).toEqual({ search: 'doom', genres: [], sort: DEFAULT_SORT })
+ )
+ })
+
+ it('applies the earlier choices again when the menu is reopened', async () => {
+ SaveEarlierVisit(chosen)
+ await RenderWithNamedGames()
+ ToggleFilters()
+ await waitFor(() => expect(LastOptions()?.genres).toEqual([]))
+
+ ToggleFilters()
+
+ await waitFor(() =>
+ expect(LastOptions()).toEqual({
+ search: '',
+ genres: ['Indie'],
+ sort: 'price-desc'
+ })
+ )
+ expect(screen.getByRole('combobox', { name: 'Sort by' }).textContent).toBe(
+ 'Price: high to low'
+ )
+ expect(screen.getByRole('combobox', { name: 'Filter by genre' }).textContent).toBe(
+ 'Indie'
+ )
+ })
+
+ it('keeps the choices in storage while the menu is closed', async () => {
+ SaveEarlierVisit(chosen)
+ await RenderWithNamedGames()
+
+ ToggleFilters()
+ await waitFor(() => expect(LastOptions()?.genres).toEqual([]))
+
+ expect(sessionStorage.getItem(KEY_SORT)).toBe('"price-desc"')
+ expect(sessionStorage.getItem(KEY_FILTERS)).toBe('["Indie"]')
+ })
+
+ it('does not apply saved choices while the menu is closed', async () => {
+ SaveEarlierVisit({ sort: 'price-desc', filters: ['Indie'], menuOpen: false })
+
+ await RenderWithNamedGames()
+
+ expect(LastOptions()).toEqual({ search: '', genres: [], sort: DEFAULT_SORT })
+ expect(screen.queryByRole('combobox', { name: 'Sort by' })).toBeNull()
+ })
+
+ it('goes back to page 1 when the menu is toggled while choices are active', async () => {
+ GetTotalGameCount.mockResolvedValue(30)
+ SaveEarlierVisit({ ...chosen, page: 2 })
+ await RenderWithNamedGames()
+ expect(FetchGamesFromDB).toHaveBeenLastCalledWith(12, 12, expect.anything())
+
+ ToggleFilters()
+
+ await waitFor(() =>
+ expect(FetchGamesFromDB).toHaveBeenLastCalledWith(12, 0, expect.anything())
+ )
+ })
+
+ it('keeps the page when the menu is toggled with nothing chosen', async () => {
+ GetTotalGameCount.mockResolvedValue(30)
+ SaveEarlierVisit({ page: 2 })
+ await RenderWithNamedGames()
+
+ ToggleFilters()
+ ToggleFilters()
+
+ expect(FetchGamesFromDB).toHaveBeenCalledTimes(1)
+ expect(FetchGamesFromDB).toHaveBeenLastCalledWith(12, 12, expect.anything())
+ })
+ })
+
+ describe('Remove filters button', () => {
+ it('is disabled when no genre is chosen', async () => {
+ await RenderWithNamedGames()
+
+ OpenFilters()
+
+ expect(IsDisabled('Remove filters')).toBe(true)
+ })
+
+ it('is enabled when a genre is chosen', async () => {
+ SaveEarlierVisit({ filters: ['Indie'], menuOpen: true })
+
+ await RenderWithNamedGames()
+
+ expect(IsDisabled('Remove filters')).toBe(false)
+ })
+
+ it('removes all genres but keeps the search and the sorting', async () => {
+ SaveEarlierVisit({
+ query: 'o',
+ sort: 'price-desc',
+ filters: ['Indie', 'Action'],
+ menuOpen: true
+ })
+ await RenderWithNamedGames()
+
+ ClickButton('Remove filters')
+
+ await waitFor(() =>
+ expect(LastOptions()).toEqual({ search: 'o', genres: [], sort: 'price-desc' })
+ )
+ expect(GetTotalGameCount).toHaveBeenLastCalledWith({ search: 'o', genres: [] })
+ expect(
+ (screen.getByPlaceholderText('Search here or use filter') as HTMLInputElement).value
+ ).toBe('o')
+ expect(screen.getByRole('combobox', { name: 'Sort by' }).textContent).toBe(
+ 'Price: high to low'
+ )
+ expect(sessionStorage.getItem(KEY_FILTERS)).toBe('[]')
+ expect(IsDisabled('Remove filters')).toBe(true)
+ })
+
+ it('goes back to page 1', async () => {
+ GetTotalGameCount.mockResolvedValue(30)
+ SaveEarlierVisit({ filters: ['Indie'], menuOpen: true, page: 2 })
+ await RenderWithNamedGames()
+ expect(FetchGamesFromDB).toHaveBeenLastCalledWith(12, 12, expect.anything())
+
+ ClickButton('Remove filters')
+
+ await waitFor(() =>
+ expect(FetchGamesFromDB).toHaveBeenLastCalledWith(12, 0, expect.anything())
+ )
+ })
+ })
+
+ describe('Reset button', () => {
+ const SearchBox = () =>
+ screen.getByPlaceholderText('Search here or use filter') as HTMLInputElement
+
+ it('is disabled when there is nothing to reset', async () => {
+ await RenderWithNamedGames()
+
+ OpenFilters()
+
+ expect(IsDisabled('Reset')).toBe(true)
+ })
+
+ it('is enabled when text has been typed, even if it was not searched for', async () => {
+ await RenderWithNamedGames()
+ OpenFilters()
+
+ fireEvent.change(SearchBox(), { target: { value: 'doo' } })
+
+ expect(IsDisabled('Reset')).toBe(false)
+ })
+
+ it('is enabled when another sorting is chosen', async () => {
+ SaveEarlierVisit({ sort: 'price-asc', menuOpen: true })
+
+ await RenderWithNamedGames()
+
+ expect(IsDisabled('Reset')).toBe(false)
+ })
+
+ it('clears the search, the sorting and the genres', async () => {
+ SaveEarlierVisit({
+ query: 'o',
+ sort: 'price-desc',
+ filters: ['Indie'],
+ menuOpen: true
+ })
+ await RenderWithNamedGames()
+
+ ClickButton('Reset')
+
+ await waitFor(() =>
+ expect(LastOptions()).toEqual({ search: '', genres: [], sort: DEFAULT_SORT })
+ )
+ expect(GetTotalGameCount).toHaveBeenLastCalledWith({ search: '', genres: [] })
+ expect(SearchBox().value).toBe('')
+ expect(screen.getByRole('combobox', { name: 'Sort by' }).textContent).toBe(
+ 'Title: A to Z'
+ )
+ expect(sessionStorage.getItem(KEY_QUERY)).toBe('""')
+ expect(sessionStorage.getItem(KEY_SORT)).toBe('"title-asc"')
+ expect(sessionStorage.getItem(KEY_FILTERS)).toBe('[]')
+ expect(IsDisabled('Reset')).toBe(true)
+ })
+
+ it('keeps the filter menu open', async () => {
+ SaveEarlierVisit({ sort: 'price-desc', menuOpen: true })
+ await RenderWithNamedGames()
+
+ ClickButton('Reset')
+
+ await waitFor(() => expect(LastOptions()?.sort).toBe(DEFAULT_SORT))
+ expect(screen.getByRole('combobox', { name: 'Sort by' })).toBeTruthy()
+ })
+
+ it('empties text that was typed but not searched for', async () => {
+ await RenderWithNamedGames()
+ OpenFilters()
+ fireEvent.change(SearchBox(), { target: { value: 'doo' } })
+
+ ClickButton('Reset')
+
+ expect(SearchBox().value).toBe('')
+ expect(IsDisabled('Reset')).toBe(true)
+ })
+
+ it('goes back to page 1', async () => {
+ GetTotalGameCount.mockResolvedValue(30)
+ SaveEarlierVisit({ sort: 'price-desc', menuOpen: true, page: 2 })
+ await RenderWithNamedGames()
+ expect(FetchGamesFromDB).toHaveBeenLastCalledWith(12, 12, expect.anything())
+
+ ClickButton('Reset')
+
+ await waitFor(() =>
+ expect(FetchGamesFromDB).toHaveBeenLastCalledWith(12, 0, expect.anything())
+ )
+ })
+ })
+
describe('pagination', () => {
it('requests the next page of 12 games when a page is clicked', async () => {
GetTotalGameCount.mockResolvedValue(13)
@@ -383,15 +726,44 @@ describe('SearchPage', () => {
Search('doom')
- await waitFor(() =>
- expect(sessionStorage.getItem('GameStart:querySearchpage')).toBe('"doom"')
- )
+ await waitFor(() => expect(sessionStorage.getItem(KEY_QUERY)).toBe('"doom"'))
+ })
+
+ it('saves the chosen sorting', async () => {
+ await RenderWithNamedGames()
+
+ ChooseSort('Price: low to high')
+
+ await waitFor(() => expect(sessionStorage.getItem(KEY_SORT)).toBe('"price-asc"'))
+ })
+
+ it('saves whether the filter menu is open', async () => {
+ await RenderWithNamedGames()
+ await waitFor(() => expect(sessionStorage.getItem(KEY_MENU)).toBe('false'))
+
+ OpenFilters()
+
+ await waitFor(() => expect(sessionStorage.getItem(KEY_MENU)).toBe('true'))
+ })
+
+ it('restores an open filter menu', async () => {
+ SaveEarlierVisit({ menuOpen: true })
+
+ await RenderWithNamedGames()
+
+ expect(screen.getByRole('combobox', { name: 'Sort by' })).toBeTruthy()
+ expect(
+ screen.getByRole('button', { name: 'Toggle filters' }).getAttribute('aria-pressed')
+ ).toBe('true')
})
it('restores a saved search, sort and genres into the first request', async () => {
- sessionStorage.setItem('GameStart:querySearchpage', JSON.stringify('o'))
- sessionStorage.setItem('GameStart:sortOptionSearchpage', JSON.stringify('price-desc'))
- sessionStorage.setItem('GameStart:filtersSearchpage', JSON.stringify(['Indie']))
+ SaveEarlierVisit({
+ query: 'o',
+ sort: 'price-desc',
+ filters: ['Indie'],
+ menuOpen: true
+ })
await RenderWithNamedGames()
@@ -408,7 +780,7 @@ describe('SearchPage', () => {
})
it('restores a saved page', async () => {
- sessionStorage.setItem('GameStart:pageSearchpage', JSON.stringify(2))
+ SaveEarlierVisit({ page: 2 })
await RenderWithNamedGames()
@@ -416,19 +788,29 @@ describe('SearchPage', () => {
})
it('ignores an invalid saved sort option', async () => {
- sessionStorage.setItem('GameStart:sortOptionSearchpage', JSON.stringify('nonsense'))
+ SaveEarlierVisit({ sort: 'nonsense', menuOpen: true })
+
+ await RenderWithNamedGames()
+
+ expect(LastOptions()?.sort).toBe(DEFAULT_SORT)
+ })
+
+ it('uses the default sorting when an empty sort was saved earlier', async () => {
+ SaveEarlierVisit({ sort: '', menuOpen: true })
await RenderWithNamedGames()
- expect(LastOptions()?.sort).toBe('')
+ expect(LastOptions()?.sort).toBe(DEFAULT_SORT)
})
it('survives corrupted storage', async () => {
- sessionStorage.setItem('GameStart:filtersSearchpage', '{not json')
+ sessionStorage.setItem(KEY_FILTERS, '{not json')
+ sessionStorage.setItem(KEY_MENU, '{not json')
await RenderWithNamedGames()
expect(ShownTitles()).toHaveLength(3)
+ expect(LastOptions()).toEqual({ search: '', genres: [], sort: DEFAULT_SORT })
})
})
})
From 886e16e77a94b89917db7f146ba4d92220d12744 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Eline=20J=C3=A5sund?=
Date: Fri, 6 Nov 2026 08:57:20 +0100
Subject: [PATCH 6/6] fix: change duplicate key
---
Frontend/src/pages/SearchPage.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Frontend/src/pages/SearchPage.tsx b/Frontend/src/pages/SearchPage.tsx
index a5d7363..c03ac37 100644
--- a/Frontend/src/pages/SearchPage.tsx
+++ b/Frontend/src/pages/SearchPage.tsx
@@ -149,7 +149,7 @@ export function SearchPage() {
}, [searchQuery, appliedFilters])
const requestKey = useMemo(
- () => JSON.stringify([page, searchQuery, appliedFilters, appliedFilters]),
+ () => JSON.stringify([page, searchQuery, appliedFilters, appliedSorting]),
[page, searchQuery, appliedFilters, appliedSorting]
)
const isCurrent = result !== null && result.key === requestKey