-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from ral-facilities/view-systems-#18
View systems #18
- Loading branch information
Showing
11 changed files
with
474 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { screen, waitFor } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { System } from '../app.types'; | ||
import { renderComponentWithBrowserRouter } from '../setupTests'; | ||
import SystemsJSON from '../mocks/Systems.json'; | ||
import SystemDetails, { SystemDetailsProps } from './systemDetails.component'; | ||
|
||
describe('SystemDetails', () => { | ||
let props: SystemDetailsProps; | ||
let mockSystemDetails: System; | ||
|
||
const createView = () => { | ||
if (props.id) | ||
mockSystemDetails = SystemsJSON.filter( | ||
(system) => system.id === props.id | ||
)[0]; | ||
return renderComponentWithBrowserRouter(<SystemDetails {...props} />); | ||
}; | ||
|
||
beforeEach(() => { | ||
props = { | ||
id: '65328f34a40ff5301575a4e3', | ||
}; | ||
}); | ||
|
||
it('renders correctly when no system is selected', async () => { | ||
props.id = null; | ||
|
||
createView(); | ||
|
||
expect(screen.getByText('No system selected')).toBeInTheDocument(); | ||
expect(screen.getByText('Please select a system')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders correctly when a system is selected', async () => { | ||
createView(); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText(mockSystemDetails.name)).toBeInTheDocument(); | ||
}); | ||
expect(screen.queryByText('Please select a system')).toBeFalsy(); | ||
expect( | ||
screen.getByText(mockSystemDetails.location ?? '') | ||
).toBeInTheDocument(); | ||
expect(screen.getByText(mockSystemDetails.owner ?? '')).toBeInTheDocument(); | ||
expect( | ||
screen.getByText(mockSystemDetails.importance ?? '') | ||
).toBeInTheDocument(); | ||
// Can have new line character which breaks normal matching | ||
expect( | ||
screen.getByText( | ||
(_, element) => element?.textContent === mockSystemDetails.description | ||
) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders correctly when a system with only required values is selected', async () => { | ||
props.id = '65328f34a40ff5301575a4e5'; | ||
createView(); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText(mockSystemDetails.name)).toBeInTheDocument(); | ||
}); | ||
expect(screen.queryByText('Please select a system')).toBeFalsy(); | ||
// One for each of location, owner and description | ||
expect(await screen.findAllByText('None')).toHaveLength(3); | ||
}); | ||
|
||
it('renders correctly when the system is not found', async () => { | ||
props.id = 'invalid_id'; | ||
|
||
createView(); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText('No system selected')).toBeInTheDocument(); | ||
}); | ||
expect(screen.getByText('Please select a system')).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.