The time has come to summarize everything we've learned in this module! Your task is to create a complete test suite for the Cosmic Mission Control Center -- an application managing space missions, crew, and ship systems.
The Mission Control Center consists of the following components:
/api/missions)useMissions -- fetching and managing missionsuseSystemHealth -- monitoring system healthuseCrewFilter -- filtering crewReview the application code and written tests below. The application demonstrates a complete test suite covering:
1__tests__/
2 MissionDashboard.test.js -- main panel tests
3 CrewManager.test.js -- crew management tests
4 SystemStatus.test.js -- system status tests
5 hooks/
6 useMissions.test.js -- missions hook tests
7 useSystemHealth.test.js -- systems hook tests
8 utils/
9 validators.test.js -- validation function tests1test('adds new crew member', async () => {
2 // Arrange -- prepare
3 const user = userEvent.setup();
4 render(<CrewManager />);
5
6 // Act -- execute
7 await user.type(screen.getByLabelText('Name'), 'Commander Nova');
8 await user.selectOptions(screen.getByLabelText('Role'), 'Captain');
9 await user.click(screen.getByRole('button', { name: 'Add Member' }));
10
11 // Assert -- verify
12 expect(screen.getByText('Commander Nova')).toBeInTheDocument();
13 expect(screen.getByText('Captain')).toBeInTheDocument();
14});1describe('MissionDashboard', () => {
2 beforeEach(() => {
3 // Each test starts with a clean state
4 jest.clearAllMocks();
5 global.fetch = jest.fn();
6 });
7
8 afterEach(() => {
9 jest.restoreAllMocks();
10 });
11});1test('shows error boundary on crash', () => {
2 const ThrowError = () => { throw new Error('Kaboom!'); };
3
4 // Silence console.error
5 const spy = jest.spyOn(console, 'error').mockImplementation(() => {});
6
7 render(
8 <ErrorBoundary fallback={<p>Something went wrong</p>}>
9 <ThrowError />
10 </ErrorBoundary>
11 );
12
13 expect(screen.getByText('Something went wrong')).toBeInTheDocument();
14 spy.mockRestore();
15});it('displays error when mission not found')useState works, test your logicBelow you'll find a complete Mission Control Center example with tests. Analyze the code and pay attention to: