Skip to content

Commit

Permalink
Cy/non pat appless (#3667)
Browse files Browse the repository at this point in the history
  • Loading branch information
calvin-codecov authored Jan 24, 2025
1 parent 9a77add commit 53ce439
Show file tree
Hide file tree
Showing 60 changed files with 1,007 additions and 3,911 deletions.
1 change: 0 additions & 1 deletion src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ const user = {
student: false,
studentCreatedAt: null,
studentUpdatedAt: null,
customerIntent: 'PERSONAL',
},
trackingMetadata: {
service: 'github',
Expand Down
Binary file added src/assets/onboarding/org_list_install_app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 5 additions & 76 deletions src/layouts/BaseLayout/BaseLayout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ const mockedUseImpersonate = useImpersonate as Mock
vi.mock('shared/GlobalTopBanners', () => ({
default: () => 'GlobalTopBanners',
}))
vi.mock('./InstallationHelpBanner', () => ({
default: () => 'InstallationHelpBanner',
}))
vi.mock('pages/TermsOfService', () => ({ default: () => 'TermsOfService' }))
vi.mock('pages/DefaultOrgSelector', () => ({
default: () => 'DefaultOrgSelector',
}))
vi.mock('layouts/Header', () => ({ default: () => 'Header' }))
vi.mock('layouts/Footer', () => ({ default: () => 'Footer' }))

Expand All @@ -53,7 +47,6 @@ const mockUser = {
student: false,
studentCreatedAt: null,
studentUpdatedAt: null,
customerIntent: 'BUSINESS',
externalId: 'asdf',
owners: [
{
Expand Down Expand Up @@ -330,9 +323,6 @@ describe('BaseLayout', () => {
const hello = screen.getByText('hello')
expect(hello).toBeInTheDocument()

const defaultOrg = screen.queryByText(/DefaultOrgSelector/)
expect(defaultOrg).not.toBeInTheDocument()

const termsOfService = screen.queryByText(/TermsOfService/)
expect(termsOfService).not.toBeInTheDocument()
})
Expand All @@ -352,9 +342,6 @@ describe('BaseLayout', () => {
const hello = screen.getByText('hello')
expect(hello).toBeInTheDocument()

const defaultOrg = screen.queryByText(/DefaultOrgSelector/)
expect(defaultOrg).not.toBeInTheDocument()

const termsOfService = screen.queryByText(/TermsOfService/)
expect(termsOfService).not.toBeInTheDocument()
})
Expand Down Expand Up @@ -385,68 +372,19 @@ describe('BaseLayout', () => {
const header = screen.queryByText(/Header/)
expect(header).not.toBeInTheDocument()
})

it('renders help banner', async () => {
setup({
currentUser: userNoTermsAgreement,
internalUser: mockUserNoTermsAgreement,
})

render(<BaseLayout>hello</BaseLayout>, { wrapper: wrapper() })
const helpBanner = await screen.findByText(/InstallationHelpBanner/)
expect(helpBanner).toBeInTheDocument()
})
})

describe('when no default org selected', () => {
it('renders the default org selector', async () => {
setup({
currentUser: loggedInUser,
internalUser: mockUser,
})
render(<BaseLayout>hello</BaseLayout>, { wrapper: wrapper() })

const defaultOrgSelector = await screen.findByText(/DefaultOrgSelector/)
expect(defaultOrgSelector).toBeInTheDocument()
})

it('does not render the header', async () => {
setup({
currentUser: loggedInUser,
internalUser: mockUser,
})
render(<BaseLayout>hello</BaseLayout>, { wrapper: wrapper() })

const defaultOrgSelector = await screen.findByText(/DefaultOrgSelector/)
expect(defaultOrgSelector).toBeInTheDocument()

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

it('renders help banner', async () => {
setup({
currentUser: loggedInUser,
internalUser: mockUser,
})

render(<BaseLayout>hello</BaseLayout>, { wrapper: wrapper() })
const helpBanner = await screen.findByText(/InstallationHelpBanner/)
expect(helpBanner).toBeInTheDocument()
})
})

describe('when agreed to TOS and default org selected', () => {
describe('when agreed to TOS', () => {
it('renders children', async () => {
setup({ currentUser: userHasDefaultOrg })
setup({ currentUser: loggedInUser })
render(<BaseLayout>hello</BaseLayout>, { wrapper: wrapper() })

const children = await screen.findByText(/hello/)
expect(children).toBeInTheDocument()
})

it('renders header', async () => {
setup({ currentUser: userHasDefaultOrg })
setup({ currentUser: loggedInUser })
render(<BaseLayout>hello</BaseLayout>, { wrapper: wrapper() })

const header = await screen.findByText(/Header/)
Expand Down Expand Up @@ -488,9 +426,6 @@ describe('BaseLayout', () => {
const hello = screen.getByText('hello')
expect(hello).toBeInTheDocument()

const defaultOrg = screen.queryByText(/DefaultOrgSelector/)
expect(defaultOrg).not.toBeInTheDocument()

const termsOfService = screen.queryByText(/TermsOfService/)
expect(termsOfService).not.toBeInTheDocument()
})
Expand All @@ -510,9 +445,6 @@ describe('BaseLayout', () => {
const hello = screen.getByText('hello')
expect(hello).toBeInTheDocument()

const defaultOrg = screen.queryByText(/DefaultOrgSelector/)
expect(defaultOrg).not.toBeInTheDocument()

const termsOfService = screen.queryByText(/TermsOfService/)
expect(termsOfService).not.toBeInTheDocument()
})
Expand Down Expand Up @@ -550,23 +482,20 @@ describe('BaseLayout', () => {

const header = await screen.findByText(/Header/)
expect(header).toBeInTheDocument()

const defaultOrgSelector = screen.queryByText(/DefaultOrgSelector/)
expect(defaultOrgSelector).not.toBeInTheDocument()
})
})

describe('when agreed to TOS and default org selected', () => {
it('renders children', async () => {
setup({ currentUser: userHasDefaultOrg })
setup({ currentUser: loggedInUser })
render(<BaseLayout>hello</BaseLayout>, { wrapper: wrapper() })

const children = await screen.findByText(/hello/)
expect(children).toBeInTheDocument()
})

it('renders header', async () => {
setup({ currentUser: userHasDefaultOrg })
setup({ currentUser: loggedInUser })
render(<BaseLayout>hello</BaseLayout>, { wrapper: wrapper() })

const header = await screen.findByText(/Header/)
Expand Down
106 changes: 44 additions & 62 deletions src/layouts/BaseLayout/BaseLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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 { OnboardingContainerProvider } from 'pages/OwnerPage/OnboardingContainerContext/context'
import { RepoBreadcrumbProvider } from 'pages/RepoPage/context'
import { useEventContext } from 'services/events/hooks'
import { useImpersonate } from 'services/impersonate'
Expand All @@ -20,8 +21,6 @@ import LoadingLogo from 'ui/LoadingLogo'
import { NavigatorDataQueryOpts } from './hooks/NavigatorDataQueryOpts'
import { useUserAccessGate } from './hooks/useUserAccessGate'

const DefaultOrgSelector = lazy(() => import('pages/DefaultOrgSelector'))
const InstallationHelpBanner = lazy(() => import('./InstallationHelpBanner'))
const TermsOfService = lazy(() => import('pages/TermsOfService'))

const FullPageLoader = () => (
Expand All @@ -31,20 +30,16 @@ const FullPageLoader = () => (
)

interface OnboardingOrChildrenProps extends React.PropsWithChildren {
isImpersonating: boolean
isFullExperience: boolean
showAgreeToTerms: boolean
redirectToSyncPage: boolean
showDefaultOrgSelector: boolean
}

function OnboardingOrChildren({
children,
isImpersonating,
isFullExperience,
showAgreeToTerms,
redirectToSyncPage,
showDefaultOrgSelector,
}: OnboardingOrChildrenProps) {
if (showAgreeToTerms && !isFullExperience) {
return (
Expand All @@ -58,14 +53,6 @@ function OnboardingOrChildren({
return <Redirect to="/sync" />
}

if (showDefaultOrgSelector && !isFullExperience && !isImpersonating) {
return (
<Suspense fallback={null}>
<DefaultOrgSelector />
</Suspense>
)
}

return <>{children}</>
}

Expand All @@ -83,7 +70,6 @@ function BaseLayout({ children }: React.PropsWithChildren) {
const {
isFullExperience,
showAgreeToTerms,
showDefaultOrgSelector,
redirectToSyncPage,
isLoading: isUserAccessGateLoading,
} = useUserAccessGate()
Expand All @@ -109,53 +95,49 @@ function BaseLayout({ children }: React.PropsWithChildren) {

return (
<>
<RepoBreadcrumbProvider>
{/* Header */}
<Suspense>
<ErrorBoundary errorComponent={<EmptyErrorComponent />}>
<SilentNetworkErrorWrapper>
{isFullExperience || isImpersonating ? (
<>
<GlobalTopBanners />
<Header hasRepoAccess={data?.hasRepoAccess} />
</>
) : (
<>
{showDefaultOrgSelector ? <InstallationHelpBanner /> : null}
</>
)}
</SilentNetworkErrorWrapper>
</ErrorBoundary>
</Suspense>

{/* Main Page Contents */}
<Suspense fallback={<FullPageLoader />}>
<ErrorBoundary sentryScopes={[['layout', 'base']]}>
<NetworkErrorBoundary>
<main className="container mb-8 flex grow flex-col gap-2 md:p-0">
<GlobalBanners />
<OnboardingOrChildren
isFullExperience={isFullExperience}
showAgreeToTerms={showAgreeToTerms}
showDefaultOrgSelector={showDefaultOrgSelector}
redirectToSyncPage={redirectToSyncPage}
isImpersonating={isImpersonating}
>
{children}
</OnboardingOrChildren>
</main>
</NetworkErrorBoundary>
</ErrorBoundary>
</Suspense>

{/* Footer */}
{isFullExperience && (
<>
<Footer />
<ToastNotifications />
</>
)}
</RepoBreadcrumbProvider>
<OnboardingContainerProvider>
<RepoBreadcrumbProvider>
{/* Header */}
<Suspense>
<ErrorBoundary errorComponent={<EmptyErrorComponent />}>
<SilentNetworkErrorWrapper>
{isFullExperience || isImpersonating ? (
<>
<GlobalTopBanners />
<Header hasRepoAccess={data?.hasRepoAccess} />
</>
) : null}
</SilentNetworkErrorWrapper>
</ErrorBoundary>
</Suspense>

{/* Main Page Contents */}
<Suspense fallback={<FullPageLoader />}>
<ErrorBoundary sentryScopes={[['layout', 'base']]}>
<NetworkErrorBoundary>
<main className="container mb-8 flex grow flex-col gap-2 md:p-0">
<GlobalBanners />
<OnboardingOrChildren
isFullExperience={isFullExperience}
showAgreeToTerms={showAgreeToTerms}
redirectToSyncPage={redirectToSyncPage}
>
{children}
</OnboardingOrChildren>
</main>
</NetworkErrorBoundary>
</ErrorBoundary>
</Suspense>

{/* Footer */}
{isFullExperience ? (
<>
<Footer />
<ToastNotifications />
</>
) : null}
</RepoBreadcrumbProvider>
</OnboardingContainerProvider>
</>
)
}
Expand Down

This file was deleted.

Loading

0 comments on commit 53ce439

Please sign in to comment.