Skip to content

Commit

Permalink
fix: Fix rendered header error (#3590)
Browse files Browse the repository at this point in the history
  • Loading branch information
suejung-sentry authored Dec 20, 2024
1 parent 96d9efe commit 358f6ec
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
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

0 comments on commit 358f6ec

Please sign in to comment.