Rsr2425 commited on
Commit
a372176
·
1 Parent(s): 84c2c84

Updated tests

Browse files
frontend/src/components/DocumentInput.tsx CHANGED
@@ -7,7 +7,7 @@ function DocumentInput() {
7
 
8
  const handleSubmit = async () => {
9
  try {
10
- const response = await fetch('/api/crawl/', {
11
  method: 'POST',
12
  headers: {
13
  'Content-Type': 'application/json',
@@ -38,7 +38,7 @@ function DocumentInput() {
38
  onChange={handleUrlChange}
39
  />
40
  <Button variant="contained" onClick={handleSubmit}>
41
- Pull Source Docs
42
  </Button>
43
  </Box>
44
  {showSuccess && (
 
7
 
8
  const handleSubmit = async () => {
9
  try {
10
+ const response = await fetch('/api/ingest/', {
11
  method: 'POST',
12
  headers: {
13
  'Content-Type': 'application/json',
 
38
  onChange={handleUrlChange}
39
  />
40
  <Button variant="contained" onClick={handleSubmit}>
41
+ Scan
42
  </Button>
43
  </Box>
44
  {showSuccess && (
frontend/src/components/Header.tsx CHANGED
@@ -4,7 +4,7 @@ function Header() {
4
  return (
5
  <Box sx={{ mb: 4 }}>
6
  <Typography variant="h2" component="h1" align="center">
7
- Simplifi
8
  </Typography>
9
  </Box>
10
  );
 
4
  return (
5
  <Box sx={{ mb: 4 }}>
6
  <Typography variant="h2" component="h1" align="center">
7
+ SimpliFi
8
  </Typography>
9
  </Box>
10
  );
frontend/src/tests/App.test.tsx CHANGED
@@ -8,14 +8,14 @@ describe('App', () => {
8
  render(<App />);
9
 
10
  // Check for title
11
- expect(screen.getByText('Simplifi')).toBeInTheDocument();
12
 
13
  // Check for input fields
14
  expect(screen.getByLabelText('Source Documentation')).toBeInTheDocument();
15
  expect(screen.getByLabelText('Quiz focus?')).toBeInTheDocument();
16
 
17
  // Check for buttons
18
- expect(screen.getByText('Pull Source Docs')).toBeInTheDocument();
19
  expect(screen.getByText('Generate')).toBeInTheDocument();
20
  });
21
  });
 
8
  render(<App />);
9
 
10
  // Check for title
11
+ expect(screen.getByText('SimpliFi')).toBeInTheDocument();
12
 
13
  // Check for input fields
14
  expect(screen.getByLabelText('Source Documentation')).toBeInTheDocument();
15
  expect(screen.getByLabelText('Quiz focus?')).toBeInTheDocument();
16
 
17
  // Check for buttons
18
+ expect(screen.getByText('Scan')).toBeInTheDocument();
19
  expect(screen.getByText('Generate')).toBeInTheDocument();
20
  });
21
  });
frontend/src/tests/components/DocumentInput.test.tsx CHANGED
@@ -15,14 +15,14 @@ describe('DocumentInput', () => {
15
  render(<DocumentInput />);
16
 
17
  const input = screen.getByLabelText('Source Documentation');
18
- const button = screen.getByText('Pull Source Docs');
19
 
20
  await act(async () => {
21
  await fireEvent.change(input, { target: { value: 'https://example.com' } });
22
  await fireEvent.click(button);
23
  });
24
 
25
- expect(mockFetch).toHaveBeenCalledWith('/api/crawl/', {
26
  method: 'POST',
27
  headers: { 'Content-Type': 'application/json' },
28
  body: JSON.stringify({ url: 'https://example.com' }),
@@ -40,7 +40,7 @@ describe('DocumentInput', () => {
40
 
41
  // First submit a URL
42
  const input = screen.getByLabelText('Source Documentation');
43
- const button = screen.getByText('Pull Source Docs');
44
 
45
  await act(async () => {
46
  await fireEvent.change(input, { target: { value: 'https://example.com' } });
 
15
  render(<DocumentInput />);
16
 
17
  const input = screen.getByLabelText('Source Documentation');
18
+ const button = screen.getByText('Scan');
19
 
20
  await act(async () => {
21
  await fireEvent.change(input, { target: { value: 'https://example.com' } });
22
  await fireEvent.click(button);
23
  });
24
 
25
+ expect(mockFetch).toHaveBeenCalledWith('/api/ingest/', {
26
  method: 'POST',
27
  headers: { 'Content-Type': 'application/json' },
28
  body: JSON.stringify({ url: 'https://example.com' }),
 
40
 
41
  // First submit a URL
42
  const input = screen.getByLabelText('Source Documentation');
43
+ const button = screen.getByText('Scan');
44
 
45
  await act(async () => {
46
  await fireEvent.change(input, { target: { value: 'https://example.com' } });
frontend/src/tests/components/Topics.test.tsx CHANGED
@@ -1,14 +1,15 @@
1
  import { render, screen, waitFor, fireEvent } from '@testing-library/react';
 
2
  import Topics from '../../components/Topics';
3
- import { vi } from 'vitest';
4
 
5
  describe('Topics Component', () => {
6
- const mockOnTopicChange = vi.fn();
 
 
7
 
8
  beforeEach(() => {
9
- vi.clearAllMocks();
10
- // Clear fetch mock before each test
11
- vi.spyOn(global, 'fetch').mockClear();
12
  });
13
 
14
  it('shows loading state initially', () => {
@@ -20,11 +21,11 @@ describe('Topics Component', () => {
20
 
21
  it('displays topics after successful fetch', async () => {
22
  const mockTopics = { sources: ['Topic 1', 'Topic 2', 'Topic 3'] };
23
- vi.spyOn(global, 'fetch').mockImplementationOnce(() =>
24
  Promise.resolve({
25
  ok: true,
26
  json: () => Promise.resolve(mockTopics),
27
- } as Response)
28
  );
29
 
30
  render(<Topics onTopicChange={mockOnTopicChange} />);
@@ -44,11 +45,11 @@ describe('Topics Component', () => {
44
  });
45
 
46
  it('handles API error correctly', async () => {
47
- vi.spyOn(global, 'fetch').mockImplementationOnce(() =>
48
  Promise.resolve({
49
  ok: false,
50
  status: 500,
51
- } as Response)
52
  );
53
 
54
  render(<Topics onTopicChange={mockOnTopicChange} />);
@@ -63,11 +64,11 @@ describe('Topics Component', () => {
63
 
64
  it('calls onTopicChange when topic is selected', async () => {
65
  const mockTopics = { sources: ['Topic 1', 'Topic 2'] };
66
- vi.spyOn(global, 'fetch').mockImplementationOnce(() =>
67
  Promise.resolve({
68
  ok: true,
69
  json: () => Promise.resolve(mockTopics),
70
- } as Response)
71
  );
72
 
73
  render(<Topics onTopicChange={mockOnTopicChange} />);
@@ -88,11 +89,11 @@ describe('Topics Component', () => {
88
 
89
  it('handles malformed API response correctly', async () => {
90
  const malformedResponse = { wrongKey: [] };
91
- vi.spyOn(global, 'fetch').mockImplementationOnce(() =>
92
  Promise.resolve({
93
  ok: true,
94
  json: () => Promise.resolve(malformedResponse),
95
- } as Response)
96
  );
97
 
98
  render(<Topics onTopicChange={mockOnTopicChange} />);
@@ -106,7 +107,7 @@ describe('Topics Component', () => {
106
  });
107
 
108
  it('handles network errors correctly', async () => {
109
- vi.spyOn(global, 'fetch').mockImplementationOnce(() =>
110
  Promise.reject(new Error('Network error'))
111
  );
112
 
 
1
  import { render, screen, waitFor, fireEvent } from '@testing-library/react';
2
+ import '@testing-library/jest-dom';
3
  import Topics from '../../components/Topics';
 
4
 
5
  describe('Topics Component', () => {
6
+ const mockOnTopicChange = jest.fn();
7
+ const mockFetch = jest.fn();
8
+ global.fetch = mockFetch;
9
 
10
  beforeEach(() => {
11
+ jest.clearAllMocks();
12
+ mockFetch.mockClear();
 
13
  });
14
 
15
  it('shows loading state initially', () => {
 
21
 
22
  it('displays topics after successful fetch', async () => {
23
  const mockTopics = { sources: ['Topic 1', 'Topic 2', 'Topic 3'] };
24
+ mockFetch.mockImplementationOnce(() =>
25
  Promise.resolve({
26
  ok: true,
27
  json: () => Promise.resolve(mockTopics),
28
+ })
29
  );
30
 
31
  render(<Topics onTopicChange={mockOnTopicChange} />);
 
45
  });
46
 
47
  it('handles API error correctly', async () => {
48
+ mockFetch.mockImplementationOnce(() =>
49
  Promise.resolve({
50
  ok: false,
51
  status: 500,
52
+ })
53
  );
54
 
55
  render(<Topics onTopicChange={mockOnTopicChange} />);
 
64
 
65
  it('calls onTopicChange when topic is selected', async () => {
66
  const mockTopics = { sources: ['Topic 1', 'Topic 2'] };
67
+ mockFetch.mockImplementationOnce(() =>
68
  Promise.resolve({
69
  ok: true,
70
  json: () => Promise.resolve(mockTopics),
71
+ })
72
  );
73
 
74
  render(<Topics onTopicChange={mockOnTopicChange} />);
 
89
 
90
  it('handles malformed API response correctly', async () => {
91
  const malformedResponse = { wrongKey: [] };
92
+ mockFetch.mockImplementationOnce(() =>
93
  Promise.resolve({
94
  ok: true,
95
  json: () => Promise.resolve(malformedResponse),
96
+ })
97
  );
98
 
99
  render(<Topics onTopicChange={mockOnTopicChange} />);
 
107
  });
108
 
109
  it('handles network errors correctly', async () => {
110
+ mockFetch.mockImplementationOnce(() =>
111
  Promise.reject(new Error('Network error'))
112
  );
113