diff --git a/Frontend/.env.example b/.env.example similarity index 94% rename from Frontend/.env.example rename to .env.example index 22df02b..736596f 100644 --- a/Frontend/.env.example +++ b/.env.example @@ -4,7 +4,6 @@ DB_PORT= DB_NAME= DB_USER= DB_PASSWORD= -HOST= PG_ADMIN_USER= PG_ADMIN_PASSWORD= \ No newline at end of file diff --git a/Frontend/src/FrontendLogic/LogicConnection.ts b/Frontend/src/FrontendLogic/LogicConnection.ts index c7e6654..1e08489 100644 --- a/Frontend/src/FrontendLogic/LogicConnection.ts +++ b/Frontend/src/FrontendLogic/LogicConnection.ts @@ -1,7 +1,6 @@ export const BACKEND_URL = import.meta.env.VITE_BACKEND_URL ?? 'http://it2810-10.idi.ntnu.no:3001/' -export const NETWORK_ERROR_MESSAGE = - 'Could not reach the server.' +export const NETWORK_ERROR_MESSAGE = 'Could not reach the server.' export async function Gql(query: string, variables: Record): Promise { const token = GetStoredToken() diff --git a/Frontend/src/FrontendLogic/MainPageLogicFrontend.ts b/Frontend/src/FrontendLogic/MainPageLogicFrontend.ts index 92a84f9..0ee588a 100644 --- a/Frontend/src/FrontendLogic/MainPageLogicFrontend.ts +++ b/Frontend/src/FrontendLogic/MainPageLogicFrontend.ts @@ -14,7 +14,6 @@ const mainPageGenreStorageKeys: Record = { discounts: 'GameStart:genreMainpage:discounts' } - function ReportStorageError(action: string, error: unknown) { const message = error instanceof Error ? error.message : String(error) console.error(`MainPage: Could not ${action} in session storage: ${message}`) @@ -31,8 +30,9 @@ export function SaveMainPageGenre(section: MainPageGenreSection, genre: string) } export function GetDiscountedOnlySearchpage(): boolean { - return ReadStored(DISCOUNT_ONLY_KEY, false, IsBoolean, 'session', (error) => - ReportStorageError('Could not read discounted only games:', error)) + return ReadStored(DISCOUNT_ONLY_KEY, false, IsBoolean, 'session', (error) => + ReportStorageError('Could not read discounted only games:', error) + ) } export function SaveDiscountedOnlySearchpage(discountedOnly: boolean) { @@ -40,8 +40,9 @@ export function SaveDiscountedOnlySearchpage(discountedOnly: boolean) { } export function GetSavedRecentReviewCount(): number { - return ReadStored(RECENT_REVIEW_KEY, DEFAULT_REVIEW_COUNT, IsInteger, 'session', (error) => - ReportStorageError('Could not read recent review count: ', error)) + return ReadStored(RECENT_REVIEW_KEY, DEFAULT_REVIEW_COUNT, IsInteger, 'session', (error) => + ReportStorageError('Could not read recent review count: ', error) + ) } export function SaveRecentReviewCount(count: number) { diff --git a/Frontend/src/FrontendLogic/SearchPageLogicFrontend.ts b/Frontend/src/FrontendLogic/SearchPageLogicFrontend.ts index 4159648..10087c9 100644 --- a/Frontend/src/FrontendLogic/SearchPageLogicFrontend.ts +++ b/Frontend/src/FrontendLogic/SearchPageLogicFrontend.ts @@ -50,4 +50,4 @@ export function SaveFilterMenuOpenSearchpage(isOpen: boolean) { export function GetFilterMenuOpenSearchpage(): boolean { return ReadStored(menuStorageKey, false, IsBoolean) -} \ No newline at end of file +} diff --git a/Frontend/src/FrontendLogic/Storage.ts b/Frontend/src/FrontendLogic/Storage.ts index 8eb58ca..8d5c6d8 100644 --- a/Frontend/src/FrontendLogic/Storage.ts +++ b/Frontend/src/FrontendLogic/Storage.ts @@ -1,4 +1,4 @@ -import type { User } from "../types/User" +import type { User } from '../types/User' type StorageKind = 'session' | 'local' @@ -6,7 +6,8 @@ export const IsString = (value: unknown): value is string => typeof value === 's export const IsBoolean = (value: unknown): value is boolean => typeof value === 'boolean' // export const IsNumber = (value: unknown): value is number => // typeof value === 'number' && Number.isFinite(value) && value > 0 -export const IsInteger = (value: unknown): value is number => typeof value === 'number' && Number.isInteger(value) && value > 0 +export const IsInteger = (value: unknown): value is number => + typeof value === 'number' && Number.isInteger(value) && value > 0 export const IsStringArray = (value: unknown): value is string[] => Array.isArray(value) export const IsNull = (value: unknown): value is null => value === 'null' export const IsUser = (value: unknown): value is User => { @@ -62,4 +63,4 @@ export function RemoveStored(key: string, kind: StorageKind = 'session') { } catch { console.log(`Could not remove "${key}" from ${kind} storage`) } -} \ No newline at end of file +} diff --git a/Frontend/src/FrontendLogic/UserLogicFrontend.ts b/Frontend/src/FrontendLogic/UserLogicFrontend.ts index 6a585a2..4eb477d 100644 --- a/Frontend/src/FrontendLogic/UserLogicFrontend.ts +++ b/Frontend/src/FrontendLogic/UserLogicFrontend.ts @@ -42,7 +42,9 @@ export function SaveUser(user: User, remember = true) { // Returns the saved user or null if no user is found. export function GetSavedUser(): User | null { - const user = ReadStored(USER_KEY, null, OrNull(IsUser), 'local') ?? ReadStored(USER_KEY, null, OrNull(IsUser)) + const user = + ReadStored(USER_KEY, null, OrNull(IsUser), 'local') ?? + ReadStored(USER_KEY, null, OrNull(IsUser)) if (!user) ClearUser() return user } diff --git a/Frontend/src/css/FriendsPage.css b/Frontend/src/css/FriendsPage.css index d83ef4d..f15290a 100644 --- a/Frontend/src/css/FriendsPage.css +++ b/Frontend/src/css/FriendsPage.css @@ -179,4 +179,3 @@ margin-top: 0; padding-top: 0; } - diff --git a/Frontend/src/css/Global.css b/Frontend/src/css/Global.css index 3ef9e36..931bb64 100644 --- a/Frontend/src/css/Global.css +++ b/Frontend/src/css/Global.css @@ -57,14 +57,14 @@ body { /* Primary: green, darker on hover, pale when disabled */ :is( - .app-button, - .profile-button, - .filtersection .resetButton, - .filtersection .removeFiltersButton, - .genre-carousel-controls .MuiButton-root, - .reviewCardActions .app-button, - .sign-in-and-up-card .MuiButton-contained - ).MuiButton-root { + .app-button, + .profile-button, + .filtersection .resetButton, + .filtersection .removeFiltersButton, + .genre-carousel-controls .MuiButton-root, + .reviewCardActions .app-button, + .sign-in-and-up-card .MuiButton-contained +).MuiButton-root { background-color: var(--primary-component-color); color: var(--primary-text-color); } @@ -123,11 +123,11 @@ body { /* Light: white button for use on green cards */ :is( - .app-button--light, - .activeGameWishlistButton, - .activeGameReviewsContent .reviewComposerToggle, - .reviewComposerActions .MuiButton-root - ).MuiButton-root { + .app-button--light, + .activeGameWishlistButton, + .activeGameReviewsContent .reviewComposerToggle, + .reviewComposerActions .MuiButton-root +).MuiButton-root { background-color: var(--primary-background-color); color: var(--primary-text-color); text-transform: none; @@ -188,7 +188,12 @@ body { These render in a portal outside the page, so they are styled by their own class. */ /* Select: add "app-menu-item" to each MenuItem (the older class names keep working) */ -:is(.app-menu-item, .filterOption, .sortingOptionSearchpage, .sortingOptionWishlist).MuiMenuItem-root.Mui-selected { +:is( + .app-menu-item, + .filterOption, + .sortingOptionSearchpage, + .sortingOptionWishlist + ).MuiMenuItem-root.Mui-selected { background-color: var(--secondary-component-color); } diff --git a/Frontend/src/hooks/useSearchPageResults.ts b/Frontend/src/hooks/useSearchPageResults.ts index 1df788b..4fbe40f 100644 --- a/Frontend/src/hooks/useSearchPageResults.ts +++ b/Frontend/src/hooks/useSearchPageResults.ts @@ -46,7 +46,9 @@ export function useSearchPageResults({ page, search, genres, sort }: SearchPageR const [countError, setCountError] = useState(null) useEffect(() => { - FetchGenres().then(setAvailableGenres).catch((err: unknown) => + FetchGenres() + .then(setAvailableGenres) + .catch((err: unknown) => setGenresError(err instanceof Error ? err.message : 'Could not load genres') ) }, []) diff --git a/Frontend/src/pages/MainPage.tsx b/Frontend/src/pages/MainPage.tsx index 92a80e6..1474617 100644 --- a/Frontend/src/pages/MainPage.tsx +++ b/Frontend/src/pages/MainPage.tsx @@ -135,7 +135,7 @@ export default function MainPage() { genresError={genresError} loadGames={LoadDiscountedGames} loadingText="Loading discount games..." - emptyText="No discount games found for this genre." + emptyText="No discounted games found for this genre." showSeeMore storageKey="discounts" /> diff --git a/Frontend/src/tests/GameLogicFrontend.test.ts b/Frontend/src/tests/GameLogicFrontend.test.ts index 7d89ed0..919fd67 100644 --- a/Frontend/src/tests/GameLogicFrontend.test.ts +++ b/Frontend/src/tests/GameLogicFrontend.test.ts @@ -161,10 +161,7 @@ describe('fetchGamesFromDB', () => { it('does not reuse cached results from the previous cache version', async () => { const values = new Map([ - [ - 'games:v1:1:0:title-desc::', - JSON.stringify({ fetchedAt: Date.now(), games: [game] }) - ] + ['games:v1:1:0:title-desc::', JSON.stringify({ fetchedAt: Date.now(), games: [game] })] ]) StubLocalStorage(values) global.fetch = vi.fn().mockResolvedValue(MockResponse({ data: { games: [] } })) diff --git a/Frontend/src/types/User.ts b/Frontend/src/types/User.ts index 76b0a8d..a9957b5 100644 --- a/Frontend/src/types/User.ts +++ b/Frontend/src/types/User.ts @@ -3,4 +3,4 @@ export interface User { email: string username: string token: string -} \ No newline at end of file +} diff --git a/README.md b/README.md index 989d3e9..413380c 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ To see the project as it was for the second handin look at the `Second-Deliverab To see the project as it was for the third handin look at the `Third-Deliverable` release of the codebase on git. +To see the project as it was for the fourth handin look at the `Fourth-Deliverable` release of the codebase on git. + ## Versions Local development runtime: @@ -38,6 +40,8 @@ Development dependencies (versions resolved in `package-lock.json`): - typescript-eslint 8.70.1 - vite 8.3.0 - vitest 5.0.1 +- playwright 1.65.0 +- monocart-reporter 3.2.1 ## How to run the application @@ -58,6 +62,9 @@ You can also access application through the virtual machine by using this link: | `npm run test` | Runs all the tests with Vitest | | `npm run test:ui` | Runs Vitest with its browser UI | | `npm run test:coverage` | Runs all the tests once and shows our test coverage (`vitest run --coverage`) | +| `npm run test:e2e` | Runs all the e2e tests with playwright | +| `npm run test:e2e:ui` | Runs all the e2e tests with playwrights ui mode | +| `npm run test:api` | Runs all the api tests | | `npm run server` | Starts the backend server | | `npm run db:create` | Creates the database tables | | `npm run db:fill` | Fills the database with games | @@ -70,111 +77,179 @@ You can also access application through the virtual machine by using this link: ## Folder structure ```text -src - ┣ api - ┃ ┣ FriendLogicFrontend.ts - ┃ ┣ GameLogicFrontend.ts - ┃ ┣ LogicConnection.ts - ┃ ┣ MainPageLogicFrontend.ts - ┃ ┣ ProfileLogicFrontend.ts - ┃ ┣ ReviewLogicFrontend.ts - ┃ ┣ SearchPageLogicFrontend.ts - ┃ ┣ UserLogicFrontend.ts - ┃ ┗ WishlistLogicFrontend.ts - ┣ assets - ┃ ┣ LogoGameStartTransparent.webp - ┃ ┣ maskot_gamestart.webp - ┃ ┗ maskot_head_gamestart.webp - ┣ backend - ┃ ┣ DatabaseConnection.ts +Backend + ┣ deploy + ┃ ┗ project2-backend.service + ┣ logic ┃ ┣ FriendLogicBackend.ts - ┃ ┣ GameColumns.ts - ┃ ┣ Genres.ts + ┃ ┣ GenresLogicBackend.ts ┃ ┣ MainPageLogicBackend.ts ┃ ┣ ProfileLogicBackend.ts - ┃ ┣ Reviews.ts - ┃ ┣ Server.ts - ┃ ┣ Steam.ts + ┃ ┣ ReviewsLogicBackend.ts ┃ ┣ UserLogicBackend.ts ┃ ┗ WishlistLogicBackend.ts - ┣ components - ┃ ┣ ActiveGameCard.tsx - ┃ ┣ Footer.tsx - ┃ ┣ Header.tsx - ┃ ┣ PageHeading.tsx - ┃ ┣ PassiveGameCard.tsx - ┃ ┣ ProfileCard.tsx - ┃ ┣ ProfileEditor.tsx - ┃ ┣ RecentReviews.tsx - ┃ ┣ ReviewCard.tsx - ┃ ┣ Reviews.tsx - ┃ ┗ WishlistGameCard.tsx - ┣ context - ┃ ┗ AuthContext.tsx - ┣ css - ┃ ┣ ActiveGameCard.css - ┃ ┣ CreateAccountPage.css - ┃ ┣ EditProfile.css - ┃ ┣ Footer.css - ┃ ┣ FriendsPage.css - ┃ ┣ GamePage.css - ┃ ┣ Global.css - ┃ ┣ Header.css - ┃ ┣ LoginPage.css - ┃ ┣ MainPage.css - ┃ ┣ PageHeading.css - ┃ ┣ PassiveGameCard.css - ┃ ┣ ProfilePage.css - ┃ ┣ RecentReviews.css - ┃ ┣ Reviews.css - ┃ ┣ SearchPage.css - ┃ ┣ SignInUpCard.css - ┃ ┣ WishlistGameCard.css - ┃ ┗ WishlistPage.css - ┣ database - ┃ ┣ CreateTables.ts - ┃ ┣ FetchGamesToJson.ts - ┃ ┣ FillDb.ts - ┃ ┣ FillGenres.ts - ┃ ┗ games.json - ┣ pages - ┃ ┣ FriendsPage.tsx - ┃ ┣ GamePage.tsx - ┃ ┣ MainPage.tsx - ┃ ┣ ProfilePage.tsx - ┃ ┣ SearchPage.tsx - ┃ ┣ SignIn.tsx - ┃ ┣ SignUp.tsx - ┃ ┗ WishlistPage.tsx + ┣ resolvers + ┃ ┣ FriendResolvers.ts + ┃ ┣ GameResolvers.ts + ┃ ┣ index.ts + ┃ ┣ ReviewResolvers.ts + ┃ ┣ types.ts + ┃ ┣ UserResolvers.ts + ┃ ┗ WishlistResolvers.ts ┣ tests - ┃ ┣ FriendsPage.test.tsx - ┃ ┣ GameLogicFrontend.test.ts - ┃ ┣ GamePage.test.tsx + ┃ ┣ GameResolvers.test.ts ┃ ┣ GenresBackend.test.ts - ┃ ┣ MainPage.test.tsx - ┃ ┣ MainPageBackend.test.ts - ┃ ┣ PageHeading.test.tsx - ┃ ┣ PassiveGameCard.test.tsx + ┃ ┣ MainpageBackend.test.ts ┃ ┣ ProfileLogicBackend.test.ts - ┃ ┣ ProfileLogicFrontend.test.ts - ┃ ┣ RecentReviews.test.tsx - ┃ ┣ ReviewCard.test.tsx - ┃ ┣ ReviewLogicFrontend.test.ts ┃ ┣ ReviewsBackend.test.ts - ┃ ┣ SearchPage.test.tsx - ┃ ┣ Setup.ts ┃ ┣ SteamBackend.test.ts ┃ ┣ TokenBackend.test.ts - ┃ ┣ TokenFrontend.test.ts ┃ ┣ UserLogicBackend.test.ts - ┃ ┣ UserLogicFrontend.test.ts - ┃ ┣ WishlistBackend.test.ts - ┃ ┗ WishlistPage.test.tsx + ┃ ┗ WishlistBackend.test.ts ┣ types - ┃ ┣ Game.ts - ┃ ┣ Review.ts - ┃ ┗ SetupOptions.ts + ┃ ┗ GameColumns.ts + ┣ DatabaseConnection.ts + ┣ Schema.ts + ┣ Server.ts + ┗ Steam.ts +``` + +```text +Database + ┣ CreateTables.ts + ┣ FetchGamesToJson.ts + ┣ FillDb.ts + ┣ FillGenres.ts + ┗ games.json +``` + +```text +E2E + ┣ api + ┃ ┣ auth.api.spec.ts + ┃ ┣ friends.api.spec.ts + ┃ ┣ games.api.spec.ts + ┃ ┣ HelpersAPI.ts + ┃ ┣ mainpage.api.spec.ts + ┃ ┣ reviews.api.spec.ts + ┃ ┗ wishlist.api.spec.ts + ┣ Auth.spec.ts + ┣ E2EConfig.ts + ┣ Fixtures.ts + ┣ Friendpage.spec.ts + ┣ Global-Setup.ts + ┣ helpers.ts + ┣ Mainpage.spec.ts + ┣ MainpageToGamepage.spec.ts + ┣ Navigation.spec.ts + ┣ Profilepage.spec.ts + ┣ Reviews.spec.ts + ┣ Searchpage.spec.ts + ┗ Wishlist.spec.ts +``` + +```text +Frontend + ┣ src + ┃ ┣ assets + ┃ ┃ ┣ LogoGameStartTransparent.webp + ┃ ┃ ┣ maskot_gamestart.webp + ┃ ┃ ┗ maskot_head_gamestart.webp + ┃ ┣ components + ┃ ┃ ┣ ActiveGameCard.tsx + ┃ ┃ ┣ Footer.tsx + ┃ ┃ ┣ GenreGamesSection.tsx + ┃ ┃ ┣ Header.tsx + ┃ ┃ ┣ PageHeading.tsx + ┃ ┃ ┣ PassiveGameCard.tsx + ┃ ┃ ┣ ProfileCard.tsx + ┃ ┃ ┣ ProfileEditor.tsx + ┃ ┃ ┣ RecentReviews.tsx + ┃ ┃ ┣ ReviewCard.tsx + ┃ ┃ ┣ ReviewComposer.tsx + ┃ ┃ ┣ Reviews.tsx + ┃ ┃ ┣ ScrollManager.tsx + ┃ ┃ ┣ SearchPageControls.tsx + ┃ ┃ ┣ SearchPageResults.tsx + ┃ ┃ ┣ TopGames.tsx + ┃ ┃ ┣ UserReviews.tsx + ┃ ┃ ┗ WishlistGameCard.tsx + ┃ ┣ context + ┃ ┃ ┗ AuthContext.tsx + ┃ ┣ css + ┃ ┃ ┣ ActiveGameCard.css + ┃ ┃ ┣ CreateAccountPage.css + ┃ ┃ ┣ EditProfile.css + ┃ ┃ ┣ Footer.css + ┃ ┃ ┣ FriendsPage.css + ┃ ┃ ┣ GamePage.css + ┃ ┃ ┣ Global.css + ┃ ┃ ┣ Header.css + ┃ ┃ ┣ LoginPage.css + ┃ ┃ ┣ MainPage.css + ┃ ┃ ┣ PageHeading.css + ┃ ┃ ┣ PassiveGameCard.css + ┃ ┃ ┣ ProfilePage.css + ┃ ┃ ┣ RecentReviews.css + ┃ ┃ ┣ ReviewComposer.css + ┃ ┃ ┣ Reviews.css + ┃ ┃ ┣ SearchPage.css + ┃ ┃ ┣ SignInUpCard.css + ┃ ┃ ┣ UserReviews.css + ┃ ┃ ┣ WishlistGameCard.css + ┃ ┃ ┗ WishlistPage.css + ┃ ┣ FrontendLogic + ┃ ┃ ┣ FriendLogicFrontend.ts + ┃ ┃ ┣ GameLogicFrontend.ts + ┃ ┃ ┣ LogicConnection.ts + ┃ ┃ ┣ MainPageLogicFrontend.ts + ┃ ┃ ┣ ProfileLogicFrontend.ts + ┃ ┃ ┣ ReviewLogicFrontend.ts + ┃ ┃ ┣ SearchPageLogicFrontend.ts + ┃ ┃ ┣ Storage.ts + ┃ ┃ ┣ UserLogicFrontend.ts + ┃ ┃ ┗ WishlistLogicFrontend.ts + ┃ ┣ hooks + ┃ ┃ ┣ useDebouncedValue.ts + ┃ ┃ ┗ useSearchPageResults.ts + ┃ ┣ pages + ┃ ┃ ┣ FriendsPage.tsx + ┃ ┃ ┣ GamePage.tsx + ┃ ┃ ┣ MainPage.tsx + ┃ ┃ ┣ ProfilePage.tsx + ┃ ┃ ┣ SearchPage.tsx + ┃ ┃ ┣ SignIn.tsx + ┃ ┃ ┣ SignUp.tsx + ┃ ┃ ┗ WishlistPage.tsx + ┃ ┣ tests + ┃ ┃ ┣ ActiveGameCard.test.tsx + ┃ ┃ ┣ FriendsPage.test.tsx + ┃ ┃ ┣ GameLogicFrontend.test.ts + ┃ ┃ ┣ GamePage.test.tsx + ┃ ┃ ┣ MainPage.test.tsx + ┃ ┃ ┣ PageHeading.test.tsx + ┃ ┃ ┣ PassiveGameCard.test.tsx + ┃ ┃ ┣ ProfileLogicFrontend.test.ts + ┃ ┃ ┣ RecentReviews.test.tsx + ┃ ┃ ┣ ReviewCard.test.tsx + ┃ ┃ ┣ ReviewLogicFrontend.test.ts + ┃ ┃ ┣ SearchPage.test.tsx + ┃ ┃ ┣ TokenFrontend.test.ts + ┃ ┃ ┣ useDebouncedValue.test.ts + ┃ ┃ ┣ UserLogicFrontend.test.ts + ┃ ┃ ┣ UserReviews.test.tsx + ┃ ┃ ┗ WishlistPage.test.tsx + ┃ ┗ types + ┃ ┃ ┣ Game.ts + ┃ ┃ ┣ Profile.ts + ┃ ┃ ┣ Review.ts + ┃ ┃ ┣ SetupOptions.ts + ┃ ┃ ┗ User.ts + ┣ .env.development + ┣ .env.development.example + ┣ .env.example ┣ App.tsx + ┣ index.html ┗ Main.tsx ``` @@ -182,7 +257,7 @@ src ## Functional requirements -The third delivery for the course requires a functional prototype. Our prototype includes all the functionality we wanted for our website, with user/profile, wishlist, friends, pagination, and searching and filtering. +The fourth delivery for the course requires a finished product. The website implements all our intended features, such as searching for games, filters, sorting, wishlist, adding friends and updating you profile. We have also finished component testing, as well as end-to-end testing. View the database information: [Database](#database) View the backend information: [Backend](#backend) @@ -195,13 +270,23 @@ When the user logs in they will be directed to the main page, where they will se The user will also be able to access their profile from the navigation bar. Here the user can customize their user with an about section, a favourite game, and game setup (pc, console, mobile). -The application will also have a searchpage where a user can browse all games. The user should also be able to search for games, filter by genre, discount, ect., and sort by title, price or discounts. +The application will also have a searchpage where a user can browse all games. The user should also be able to search for games, filter by genre, discount, ect., and sort by title, price or discounts. The genre filter is meant to be intersected, to allow users to find games that are both genres. So that the filter "Fantasy" AND "Multi-player" gives users "Fantasy Multi-player" games, instead of reciving all "Fantasy" and all "Multi-player" games. We think this is natural to what users want when looking for games, as returning the joint set would include a lot of games outside of the "Fantasy" genre, and many "Single-player" games. When selecting a game anywhere on the application, the user will be sent to the sepcified game page. Here they can create reviews, when logged in, and read all reviews made on the game. Users can also enter the friends page to add friends by their secret FriendID. When selecting a friend, they will be able to see their profile and wishlistpage. Friendship is mutual. If you want to test the add friend function, you can use the friend id ```cabbages``` to add our mock user. -Lastly, the application will have a wishlist page where the user can place, and view, the games they want. Our goal is to implement a friends function that allows users to view their friends' wishlist. +Lastly, the application will have a wishlist page where the user can place, and view, the games they want. + +#### The purpose of our application + +The purpose of the website is not to sell games, but to showcase games in a new way and help users find new, fun games to play. + +Steam only allows players to review games with either "Recommended" or "Not recommended", which can paint a black-and-white picture of games that come in different shades of gray. We therefore implemented a rating system from 1 to 5 stars to give users a more nuanced picture. Users can also leave a comment to explain why they gave that particular rating. + +The discount was added to help users find new games they might like, at a low price. Discounts in our database may not be accurate, as we fetched all games once, and stored the result in a JSON file. This was done to show the functionality of the website, without constantly calling the APIs. Another reason why they might not be accurate is that the Steam API is returns American prices and discounts, not Norwegian ones. This can cause different games to be discounted on Steam and on our website, and the discount percentages may differ as well. + +The existing profile and wishlist functionality felt underwhelming and a bit pointless, so we added friends to give users a reason to customise their profile and keep their wishlist up to date. With this functionality, friends can now view you profile and wishlist, and you could view your friends' profiles and wishlists. ## Styling @@ -209,7 +294,7 @@ We are using the [Mui react component library](https://mui.com/components/) and ### Scalability -Phone size = 390 px × 844 px +Phone size = 393 px × 844 px Tablet size = 768 px × 1024 ### ESLint and Prettier @@ -226,6 +311,7 @@ For this application we are using sessionstorage to store: - Searchbar input - Chosen sorting option - User +- Selected friend We are using localstorage to store: @@ -240,29 +326,51 @@ The games are saved to make the page load faster and save bandwidth. The user is Our main focus has been to avoid sending more data and making more requests than we need to, since that is where most of the energy use in an application like ours comes from. -The search page only sends a request when the user presses enter or clicks the search button, so typing a game name results in one request instead of one per letter. The results are paginated with 12 games per page, and search, filtering and sorting are all done in the database. This way the client never has to download all 5000+ games just to sort or filter them. - -Pages of games that have already been fetched are cached in localStorage for 12 hours, so going back and forth between the search page and a game page does not fetch the same games again. Filters, search and sorting are also saved in sessionStorage (see [Storage](#storage)), so the user does not have to redo their search or filter options, resulting in a smoother user experience. +Search and filtering are handled in the database, and the results are paginated to 12 games per page. The input is debounced, so the app does not send a request for every letter while a user is typing. We also cache game lists in localStorage for 12 hours, keyed by page, search term, active filters and sort option, so returning to a previous result set does not require another fetch. Filters, the search value and the selected sort order are saved in sessionStorage (see [Storage](#storage)), which reduces unnecessary work and makes the user experience smoother. The game data was fetched from Steam once and stored in `games.json`, which is used to fill the database. This means we do not call the Steam APIs while the application is in use. The backend also sets limits on how much data a single request can ask for. The games query is capped at 500 games, recent reviews at 50, and the sections on the main page only fetch the 3 or 10 games they actually show. Even if someone sends a request asking for everything, the server will not return the whole database. Since we use GraphQL, the client also only gets the fields it asks for, instead of a fixed response like a REST endpoint would give. The database and backend run directly on the VM without Docker, so there is no extra layer using resources on the server. -On the design side we use system fonts (Arial), so no fonts need to be downloaded, and we keep images to the game covers plus our logo and mascot. - For components we use MUI, and Lucide for icons. MUI is not the smallest library, but using it means we do not have to write and ship our own versions of things like buttons, inputs, menus and pagination. Vite only includes the components and icons we actually import in the build, and the Lucide icons are small SVGs instead of image files. -There are still some things we want to fix for the final delivery. The search results fetch the full description of every game even though the cards do not show it, game images are not lazy loaded, and the mascot image on the main page is around 500 KB and should be compressed. +On the design side we use system fonts (Arial), so no fonts need to be downloaded. We also converted our self-made images, such as the mascot, from JPEG to WebP to limit the storage needed. However, the game images were already in JPG format from the database, and converting them manually would have required a large amount of work. All images are non the less lazy-loaded. + +There are still opportunities to improve the application further. The search results currently include the full description for every game even though the cards do not display it, the images are not lazy-loaded yet, and the mascot image on the main page is still large enough to compress further. We also need to cache the logo image, as this was forgotten in this iteration. ## Accessibility -So far we have added `aria-label`s to some of the buttons that only show an icon, alt texts to the images, and labels to the fields on the sign in and sign up pages. Some of the choices we mentioned earlier also help with accessibility, like the responsive design in [Styling](#styling) and using Arial as mentioned in [Sustainability](#sustainability), which is easy to read. +Buttons that only show an icon have `aria-label`s, images have alt texts, and all form fields have labels, so the site can be used with a screen reader. Error messages are read out when they show up. The application can also be used with only keyboard, by tabbing through the page and pressing enter. Elements in focus get a black or green outline so it is easy to see where you are. + +We have tested the site with Lighthouse and a screen reader. Some of the choices we mentioned earlier also help with accessibility, like responsive design in [Styling](#styling) and using Arial as mentioned in [Sustainability](#sustainability), which is easy to read. -Most of the accessibility work is still left for the next delivery. We want to focus on screen reader support, like adding labels to the search bar and other inputs that are missing them, and making sure loading, search results and error messages are read out properly. We also want to look at page structuring and page titles, and test the site with a screen reader and Lighthouse. +There are still some things that could be better. All pages have the same page title, so it might be hard to know which page you are on from the browser tab or a screen reader. ## Tests -To run tests, open the terminal and run ```npx vitest```. To test with coverage, install ```npm install -D @vitest/coverage-v8``` and run ```npx vitest --coverage``` to include coverage. +### Component tests + +To run the components tests (```Frontend/tests``` and ```Backend/tests```), open the terminal and run ```npm run test```. To test with coverage, install ```npm install -D @vitest/coverage-v8``` and run ```npm run test:coverage``` to include coverage. + +### E2E tests + +The end-to-end tests run on both chronium and firefox for desktop. While for the phone tests, they run on chronium and safari. These tests run on their own local backend and frontend, and sets up their own test database before filling it by running the necessary scripts for you. + +Start with installing playwright and monocart-reports by running ```npx playwright install``` and ```npm install monocart-coverage-reports```. Then you need to make sure you have the postgres admin user and password filled in the ```.env``` (see ```.env.example```). + +To run the E2e test you need to have no local backend or frontend running. Close them if you have either running. We also recommend checking if you have a backend running that you can not see if you are experiencing issues with running the E2E tests. This you can do by opening a terminal and running ```netstat -ano | findstr LISTENING | findstr ":3001 :5173"```, if you are on windows, and ```lsof -nP -iTCP:3001 -sTCP:LISTEN``` and ```lsof -nP -iTCP:3001 -sTCP:LISTEN``` if you are on macOs / Linux. If nothing prints, the ports are free, and you are good to go. If it prints PIDs, you have to stop the processes with ```Stop-Process -Id -Force``` on windows and ```kill ``` on macOs/Linux (using the PIDs that was printed). + +Then you can run the tests with ```npm run test:e2e``` or ```npm run test:e2e:ui``` if you want to use playwrights ui function. + +Some of our group members experienced that some tests would fail on the first run, but not fail when running the same ```npm run test:e2e``` script again without changing anything. If some tests fail when you are running ```npm run test:e2e``` we recommend running the script one more time. + +To look at the test coverage you can open the ```test-results/coverage/coverage/index.html``` file. + +### API tests + +To run the api tests (```E2E/api```) you need to have no local backend running. To run the tests, open the terminal and run ```npm run test:api```. + +The api folder is located in the E2E folder because those tests use the same backend setup as the E2E tests. ## Database @@ -419,27 +527,35 @@ Now you should be able to use the database. To use the local database you have to have a local server running. This can be created by running ```npm run server:local```. Now that the database and server is up and running you should be able to run the project by running npm run dev as usual. -If you want to run the project with ```npm run dev``` using the VM backend after creating ```Frontend/.env.development```, you may have to uncomment or remove ```VITE_BACKEND_URL=http://localhost:3001/``` as the existence of this variable will cause the project to run on the local backend. +#### Switiching back to the VM backend + +Since the ```npm run dev``` reads the ```VITE_BACKEND_URL=http://localhost:3001/``` the frontend will keep using the local backend. Therefore, if you want to run the project again using the VM backend you have to comment out or delete the ```VITE_BACKEND_URL=http://localhost:3001/``` line in ```Frontend/.env.development```. Then you can restart ```npm run dev``` and the VM backend will be used. ## Known issues We know that our application has a few bugs, here are the bugs we are aware of, and want to fix: - When price is ```0.00```, should show ```Free``` instead. -- Some pages have logic in them. We will clean them up for the next deliverable. -- On main page, genres for the ```Dicounted games``` section is fetched from all games, and not discounted ones. This leads to several genres where no discounted games show up. -- Toggle filter button on the searchpage does not remove filter when toggeled off. -- Maskot image is not stored in local storage. -- Selecting see more on the discounted genre will take you to searchpage with the genre filter applited, but not the discount. - The sign in and signup payloads are sent as plaintext as this is an http website and not https. Although we are aware of the dangers, we have decided to not fix this, as this is a small student project. May be changed in the future. ## Usage of AI Areas where we have used AI: -- CSS improvements: Guidance for quick fixes, such as components shape, background and space adjusting. +- CSS improvements: Guidance for quick fixes, such as components shape, background and space adjusting. - Test generation: Creating ideas for tests and code skeletons to speed up development and improving coverage. - Converting all function names to PascalCase. - Look over the assignment criterias and give feedback on where we lack functionality. - Debugging errors in running, merge conflicts and file structure. - Fixing or updating existing page logic for quick changes from last iteration. + +Concrete examples of use: +- From delivery 2 to delivery 3, we updated from generating our database from the api, to generating it from the JSON file. To make these changes, we used AI on our existing ```FillDb.ts``` and asked it to change fetching from the API to fetching from ```Games.json```. +- In order to have buttons be uniform and reusable, we used AI to help create a plain button class that could be applied to all buttons. +- After delivery 2, we realised that our naming conventions were not extensive enough. We had files with pascal case, camel case, and snake case. We therefore used AI to change the names of the files to pascal case, to have a uniform naming convention. + +The AI tools we have used: +- [Claude AI](https://claude.ai/) +- [ChatGPT](https://chatgpt.com/) + +All recommendations made by AI has been reviewed by at least one group member.