Skip to content

Commit b9d5461

Browse files
authored
Enable CI tests on frontend
1 parent 8ea5fdf commit b9d5461

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ jobs:
7171
- name: Lint Webapp
7272
run: yarn lint
7373

74-
#- name: Run Tests (Webapp)
75-
# run: npm test
74+
- name: Run Tests (Webapp)
75+
run: npm test
7676

7777
- name: Build Webapp
7878
run: yarn build

webapp/app/page.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ import Page from './page';
66

77
it('App Router: Works with Server Components', () => {
88
render(<Page />);
9-
expect(screen.getByRole('heading')).toHaveTextContent('App Router');
9+
expect(screen.getByRole('heading')).toHaveTextContent(
10+
'TinyURL like application'
11+
);
1012
});

webapp/components/url-shortener/ui/URLShortener.test.jsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
22
import { describe, it, expect } from '@jest/globals';
33
import { URLShortener } from './URLShortener';
4-
import React from 'react';
4+
import React, { act } from 'react';
5+
6+
global.fetch = jest.fn();
57

68
describe('URLShortenerV2', () => {
9+
beforeEach(() => {
10+
jest.clearAllMocks(); // Reset all mocks before each test
11+
});
12+
713
it("renders the long URL input and Shorten button in 'initial' mode", () => {
814
render(<URLShortener />);
915

@@ -17,6 +23,12 @@ describe('URLShortenerV2', () => {
1723
});
1824

1925
it("clicking the 'Shorten' button triggers the shorten action", async () => {
26+
const shortenedUrl = 'https://short.ly/abc123';
27+
global.fetch = jest.fn().mockResolvedValue({
28+
ok: true,
29+
json: async () => ({ shortenedUrl }), // API response in JSON
30+
});
31+
2032
render(<URLShortener />);
2133

2234
const enterUrlTextBox = screen.getByRole('textbox', {
@@ -39,7 +51,8 @@ describe('URLShortenerV2', () => {
3951
const shortenedUrlTextBox = screen.getByRole('textbox', {
4052
name: /shortened url/i,
4153
});
42-
expect(shortenedUrlTextBox).toHaveValue('should-be-a-shortened-url');
54+
//expect(shortenedUrlTextBox).toHaveValue('should-be-a-shortened-url');
55+
expect(shortenedUrlTextBox).toHaveValue(shortenedUrl);
4356
expect(
4457
screen.queryByRole('button', { name: /shorten url/i })
4558
).not.toBeInTheDocument();

0 commit comments

Comments
 (0)