Skip to content

Commit

Permalink
Merge pull request #259 from pnnl/main
Browse files Browse the repository at this point in the history
Release Merge to Production
  • Loading branch information
sudhacheran authored Dec 24, 2024
2 parents 4a5f757 + 8ed7c5b commit e115bc4
Show file tree
Hide file tree
Showing 36 changed files with 2,222 additions and 1,405 deletions.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const routes = [
),
},
{
path: `/app/:projectId/doe_workflow_combustion_safety_testing`,
path: `/app/:projectId/doe_combustion_appliance_safety_tests`,
// Workflow list view: List the names of workflows available for generating installation report.
element: (
<Suspense fallback={<div>Loading...</div>}>
Expand Down
86 changes: 86 additions & 0 deletions src/__tests__/showOrHide.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { render, screen } from '@testing-library/react'
import { StoreContext } from '../components/store'
import ShowOrHide from '../components/show_or_hide'

// Mock StoreContext data
const mockStoreContext = {
docId: 'TestDocID123',
attachments: {},
data: { location: { state: 'WA', zip_code: '99354' } },
metadata: {},
}

describe('ShowOrHide Component', () => {
// Helper function to render the component with StoreContext provider
const renderWithContext = (props: any) => {
return render(
<StoreContext.Provider value={mockStoreContext as any}>
<ShowOrHide {...props} />
</StoreContext.Provider>,
)
}

test('renders children when "visible" prop is true', () => {
renderWithContext({
visible: true,
children: <div>Visible Content</div>,
})

// Assert that the content is rendered
expect(screen.getByText('Visible Content')).toBeInTheDocument()
})

test('does not render children when "visible" prop is false', () => {
renderWithContext({
visible: false,
children: <div>Invisible Content</div>,
})

// Assert that the content is not rendered
expect(screen.queryByText('Invisible Content')).not.toBeInTheDocument()
})

test('renders children when path and value match in context', () => {
renderWithContext({
path: 'location.state',
value: 'WA',
children: <div>Location is WA</div>,
})

// Assert that the content is rendered because the path and value match
expect(screen.getByText('Location is WA')).toBeInTheDocument()
})

test('renders children when path and value match in parent data', () => {
const mockParent = {
data_: { location: { state: 'CA', zip_code: '23412' } },
}

renderWithContext({
path: 'location.state',
value: 'CA',
parent: mockParent,
children: <div>Content Visible with Parent Data</div>,
})

const content = screen.getByText('Content Visible with Parent Data')
// Assert that the content is rendered because the parent data matches the path and value
expect(content).toBeInTheDocument()
})

test('does not render children when parent document is passed and path does not match', () => {
const mockParent = { data: { location: { state: 'NY' } } }

renderWithContext({
path: 'location.state',
value: 'CA',
parent: mockParent,
children: <div>Content Visible with Parent Data</div>,
})

// Assert that the content is not rendered because the path and value do not match in parent data
expect(
screen.queryByText('Content Visible with Parent Data'),
).not.toBeInTheDocument()
})
})
6 changes: 3 additions & 3 deletions src/__tests__/test.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import ReactDOM from 'react-dom'
import ReactDOM from 'react-dom/client'
import Home from '../components/home'
import { MemoryRouter } from 'react-router-dom'

it('renders without crashing', () => {
const div = document.createElement('div')
ReactDOM.render(
const root = ReactDOM.createRoot(div) // Create root using new API
root.render(
<MemoryRouter>
<Home />
</MemoryRouter>,
div,
)
})
Loading

0 comments on commit e115bc4

Please sign in to comment.