Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix rendered header error #3590

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/layouts/BaseLayout/BaseLayout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ beforeAll(() => {
server.listen({ onUnhandledRequest: 'warn' })
})

beforeEach(() => {
vi.resetModules()
vi.restoreAllMocks()
})

afterEach(() => {
queryClient.clear()
queryClientV5.clear()
Expand Down Expand Up @@ -588,4 +593,27 @@ describe('BaseLayout', () => {
expect(errorMainAppUI).toBeInTheDocument()
})
})

describe('When Header has a network call error', async () => {
it('renders nothing for the errored header', async () => {
vi.spyOn(
await import('layouts/Header'),
'default'
).mockImplementationOnce(() => {
throw new Error('Simulated Header Error')
})

setup({ currentUser: userHasDefaultOrg })
render(<BaseLayout>hello</BaseLayout>, { wrapper: wrapper() })

const header = screen.queryByText(/Header/)
expect(header).not.toBeInTheDocument()

const mainAppContent = await screen.findByText('hello')
expect(mainAppContent).toBeInTheDocument()

const footerContent = await screen.findByText(/Footer/)
expect(footerContent).toBeInTheDocument()
})
})
})
5 changes: 3 additions & 2 deletions src/layouts/BaseLayout/BaseLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Header from 'layouts/Header'
import ErrorBoundary from 'layouts/shared/ErrorBoundary'
import { EmptyErrorComponent } from 'layouts/shared/ErrorBoundary/ErrorBoundary'
import NetworkErrorBoundary from 'layouts/shared/NetworkErrorBoundary'
import SilentNetworkErrorWrapper from 'layouts/shared/SilentNetworkErrorWrapper'
import ToastNotifications from 'layouts/ToastNotifications'
import { RepoBreadcrumbProvider } from 'pages/RepoPage/context'
import { useImpersonate } from 'services/impersonate'
Expand Down Expand Up @@ -110,7 +111,7 @@ function BaseLayout({ children }: React.PropsWithChildren) {
{/* Header */}
<Suspense>
<ErrorBoundary errorComponent={<EmptyErrorComponent />}>
<NetworkErrorBoundary>
<SilentNetworkErrorWrapper>
{isFullExperience || isImpersonating ? (
<>
<GlobalTopBanners />
Expand All @@ -121,7 +122,7 @@ function BaseLayout({ children }: React.PropsWithChildren) {
{showDefaultOrgSelector ? <InstallationHelpBanner /> : null}
</>
)}
</NetworkErrorBoundary>
</SilentNetworkErrorWrapper>
</ErrorBoundary>
</Suspense>

Expand Down
Loading