Skip to content

Commit

Permalink
added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
deepikagonuguntla committed Jul 11, 2024
1 parent a78e59c commit 0d2a458
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
2 changes: 0 additions & 2 deletions app/javascript/components/Faqs/Faqs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ describe('Faq component', () => {
root.render(<Faqs />);
});

console.log(rootElement.innerHTML);

await waitFor(() => {
expect(screen.getByText("kml")).toBeInTheDocument();
expect(screen.getByText("kml2")).toBeInTheDocument();
Expand Down
46 changes: 44 additions & 2 deletions app/javascript/components/SignUp/SignUp.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,56 @@ import '@testing-library/jest-dom/extend-expect';
import * as React from "react";
import SignUp from "../SignUp/SignUp.jsx";
import { createRoot } from 'react-dom/client';
import axios from 'axios';
import { act } from 'react-dom/test-utils';
import { waitFor, screen, fireEvent } from '@testing-library/react';
import { useNavigate } from 'react-router-dom';
jest.mock('axios');

const mockUseNavigate = jest.fn();
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'), // Use actual react-router-dom for other functions
useNavigate: () => mockUseNavigate, // Mock useNavigate
}));

describe("SignUp", () => {
test("SignUp", () => {
afterEach(() => {
// Clear all mocks after each test
jest.clearAllMocks();
});

test("test active schools", async () => {

const active_schools = {
"J. M. Rapport School Career Development - Albert Tuitt Campus (X362 J.M. RAPPORT SCHOOL CAREER)": 1156,
"P.S. X017- Adlai Campus (X450 P.S. X017 - ADLAI CAMPUS)": 1158,
"PS8 The Emily Warren Roebling School (K008 PS8 EMILY WARREN ROEBLING)": 1157,
"Renaissance High School for Musical Theater and the Arts (X405 RENAISSANCE HS FOR MUSICAL)": 1159
}

axios.get.mockResolvedValue({ data: { activeSchools: active_schools, emailMasks: ["schools.nyc.gov", "@nypl.org"] } });
const rootElement = document.createElement('div');
document.body.appendChild(rootElement);
const root = createRoot(rootElement);

// Use act to ensure all updates are processed before assertions
await act(async () => {
root.render(<SignUp />);
});

expect(screen.getByText("Email address must end with @schools.nyc.gov or a participating school domain.")).toBeInTheDocument();
expect(screen.getByText("J. M. Rapport School Career Development - Albert Tuitt Campus (X362 J.M. RAPPORT SCHOOL CAREER)")).toBeInTheDocument();
});

test("test active schools with no active schools", async () => {
axios.get.mockResolvedValue({ data: { activeSchools: {}, emailMasks: ["schools.nyc.gov", "@nypl.org"] } });
const rootElement = document.createElement('div');
document.body.appendChild(rootElement);
const root = createRoot(rootElement);

// Use act to ensure all updates are processed before assertions
root.render(<SignUp />);
await act(async () => {
root.render(<SignUp />);
});
});
});
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
"forceConsistentCasingInFileNames": true,
// `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc`
"noEmit": true,
"types": ["node", "webpack-env", "jest", "@testing-library/jest-dom"]
"types": ["node", "webpack-env", "jest", "@testing-library/jest-dom"],
"paths": {
"react": [ "./node_modules/@types/react" ]
}
}
}

0 comments on commit 0d2a458

Please sign in to comment.