From 7acb352b0ccdd9164a0e950bf8d5bdac8d3ee755 Mon Sep 17 00:00:00 2001 From: selimyanat Date: Tue, 4 Mar 2025 16:05:35 +0100 Subject: [PATCH 1/2] Enable CI tests on frontend --- webapp/app/page.test.tsx | 4 +++- .../url-shortener/ui/URLShortener.test.jsx | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/webapp/app/page.test.tsx b/webapp/app/page.test.tsx index ff25813..71235a3 100644 --- a/webapp/app/page.test.tsx +++ b/webapp/app/page.test.tsx @@ -6,5 +6,7 @@ import Page from './page'; it('App Router: Works with Server Components', () => { render(); - expect(screen.getByRole('heading')).toHaveTextContent('App Router'); + expect(screen.getByRole('heading')).toHaveTextContent( + 'TinyURL like application' + ); }); diff --git a/webapp/components/url-shortener/ui/URLShortener.test.jsx b/webapp/components/url-shortener/ui/URLShortener.test.jsx index b28c6e1..56089f5 100644 --- a/webapp/components/url-shortener/ui/URLShortener.test.jsx +++ b/webapp/components/url-shortener/ui/URLShortener.test.jsx @@ -1,9 +1,15 @@ import { render, screen, fireEvent, waitFor } from '@testing-library/react'; import { describe, it, expect } from '@jest/globals'; import { URLShortener } from './URLShortener'; -import React from 'react'; +import React, { act } from 'react'; + +global.fetch = jest.fn(); describe('URLShortenerV2', () => { + beforeEach(() => { + jest.clearAllMocks(); // Reset all mocks before each test + }); + it("renders the long URL input and Shorten button in 'initial' mode", () => { render(); @@ -17,6 +23,12 @@ describe('URLShortenerV2', () => { }); it("clicking the 'Shorten' button triggers the shorten action", async () => { + const shortenedUrl = 'https://short.ly/abc123'; + global.fetch = jest.fn().mockResolvedValue({ + ok: true, + json: async () => ({ shortenedUrl }), // API response in JSON + }); + render(); const enterUrlTextBox = screen.getByRole('textbox', { @@ -39,7 +51,8 @@ describe('URLShortenerV2', () => { const shortenedUrlTextBox = screen.getByRole('textbox', { name: /shortened url/i, }); - expect(shortenedUrlTextBox).toHaveValue('should-be-a-shortened-url'); + //expect(shortenedUrlTextBox).toHaveValue('should-be-a-shortened-url'); + expect(shortenedUrlTextBox).toHaveValue(shortenedUrl); expect( screen.queryByRole('button', { name: /shorten url/i }) ).not.toBeInTheDocument(); From 3c4fdc44b709c63f0e030b309970e940ec0b348f Mon Sep 17 00:00:00 2001 From: selimyanat Date: Tue, 4 Mar 2025 16:10:25 +0100 Subject: [PATCH 2/2] Enable CI tests on frontend --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66f38d0..cf29d7b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,8 +71,8 @@ jobs: - name: Lint Webapp run: yarn lint - #- name: Run Tests (Webapp) - # run: npm test + - name: Run Tests (Webapp) + run: npm test - name: Build Webapp run: yarn build