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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion webapp/app/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ import Page from './page';

it('App Router: Works with Server Components', () => {
render(<Page />);
expect(screen.getByRole('heading')).toHaveTextContent('App Router');
expect(screen.getByRole('heading')).toHaveTextContent(
'TinyURL like application'
);
});
17 changes: 15 additions & 2 deletions webapp/components/url-shortener/ui/URLShortener.test.jsx
Original file line number Diff line number Diff line change
@@ -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';

Check warning on line 4 in webapp/components/url-shortener/ui/URLShortener.test.jsx

View workflow job for this annotation

GitHub Actions / Webapp Build & Test

'act' is defined but never used

Check warning on line 4 in webapp/components/url-shortener/ui/URLShortener.test.jsx

View workflow job for this annotation

GitHub Actions / Webapp Build & Test

'act' is defined but never used

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(<URLShortener />);

Expand All @@ -17,6 +23,12 @@
});

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(<URLShortener />);

const enterUrlTextBox = screen.getByRole('textbox', {
Expand All @@ -39,7 +51,8 @@
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();
Expand Down
Loading