From 25a6095c0bd534e9cc837bb3e6ea3b5080fa7ff3 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 20 Dec 2023 20:00:11 +0000 Subject: [PATCH 1/2] feat: Add unit tests for WebScrape component --- .../UIUC-Components/WebScrape.test.tsx | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/components/UIUC-Components/WebScrape.test.tsx diff --git a/src/components/UIUC-Components/WebScrape.test.tsx b/src/components/UIUC-Components/WebScrape.test.tsx new file mode 100644 index 000000000..f8b8f9239 --- /dev/null +++ b/src/components/UIUC-Components/WebScrape.test.tsx @@ -0,0 +1,57 @@ +import React from 'react'; +import { render, fireEvent } from '@testing-library/react'; +import '@testing-library/jest-dom/extend-expect'; +import nock from 'nock'; +import WebScrape from './WebScrape'; + +describe('WebScrape component', () => { + test('renders without crashing', () => { + const { getByPlaceholderText } = render(); + expect(getByPlaceholderText('Enter URL')).toBeInTheDocument(); + }); + + test('validateUrl function works correctly', () => { + const { getByPlaceholderText } = render(); + const input = getByPlaceholderText('Enter URL'); + fireEvent.change(input, { target: { value: 'https://validurl.com' } }); + expect(input.value).toBe('https://validurl.com'); + fireEvent.change(input, { target: { value: 'invalidurl' } }); + expect(input.value).toBe('invalidurl'); + }); + + test('handleSubmit function works correctly', async () => { + const { getByPlaceholderText, getByText } = render(); + const input = getByPlaceholderText('Enter URL'); + fireEvent.change(input, { target: { value: 'https://validurl.com' } }); + const button = getByText('Ingest'); + fireEvent.click(button); + await new Promise((r) => setTimeout(r, 2000)); + expect(getByText('Web scraping started')).toBeInTheDocument(); + }); + + test('scrapeWeb function works correctly', async () => { + nock('https://flask-production-751b.up.railway.app') + .get('/web-scrape') + .reply(200, { data: 'scraped data' }); + const { getByPlaceholderText, getByText } = render(); + const input = getByPlaceholderText('Enter URL'); + fireEvent.change(input, { target: { value: 'https://validurl.com' } }); + const button = getByText('Ingest'); + fireEvent.click(button); + await new Promise((r) => setTimeout(r, 2000)); + expect(getByText('scraped data')).toBeInTheDocument(); + }); + + test('downloadMITCourse function works correctly', async () => { + nock('https://flask-production-751b.up.railway.app') + .get('/mit-download') + .reply(200, { data: 'downloaded data' }); + const { getByPlaceholderText, getByText } = render(); + const input = getByPlaceholderText('Enter URL'); + fireEvent.change(input, { target: { value: 'https://ocw.mit.edu' } }); + const button = getByText('Ingest'); + fireEvent.click(button); + await new Promise((r) => setTimeout(r, 2000)); + expect(getByText('downloaded data')).toBeInTheDocument(); + }); +}); From 4265e2c87dae7511d59a42104952c6ec7abac952 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 20 Dec 2023 20:00:56 +0000 Subject: [PATCH 2/2] feat: Updated src/components/UIUC-Components/WebSc --- src/components/UIUC-Components/WebScrape.tsx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/components/UIUC-Components/WebScrape.tsx b/src/components/UIUC-Components/WebScrape.tsx index 67a7c1d17..da8566991 100644 --- a/src/components/UIUC-Components/WebScrape.tsx +++ b/src/components/UIUC-Components/WebScrape.tsx @@ -35,7 +35,7 @@ const shouldShowFields = (inputUrl: string) => { ) } -const validateUrl = (url: string) => { +export const validateUrl = (url: string) => { const courseraRegex = /^https?:\/\/(www\.)?coursera\.org\/learn\/.+/ const mitRegex = /^https?:\/\/ocw\.mit\.edu\/.+/ const githubRegex = /^https?:\/\/(www\.)?github\.com\/.+/ @@ -51,7 +51,7 @@ const validateUrl = (url: string) => { ) } -const formatUrl = (url: string) => { +export const formatUrl = (url: string) => { if (!/^https?:\/\//i.test(url)) { url = 'http://' + url } @@ -117,7 +117,19 @@ export const WebScrape = ({ } } - const handleSubmit = async () => { +export const handleSubmit = async ( + url: string, + courseName: string, + courseOptions: { + maxUrls: string, + maxDepth: string, + stayOnBaseUrl: boolean, + selectedCanvasOptions: string[], + }, + isNewCourse: boolean, + user: { email: string }, + router: any, + ) => { if (validateUrl(url)) { setLoadingSpinner(true) let data = null