Skip to content

Commit

Permalink
fix(cypress): test
Browse files Browse the repository at this point in the history
  • Loading branch information
aliraza556 committed Oct 27, 2024
1 parent a90b6aa commit f20f976
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 51 deletions.
12 changes: 8 additions & 4 deletions cypress/e2e/admin/signin.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ describe('Admin Login', () => {
const title = `Testing NavFiber`
const description = 'Testing Graph Description'

cy.get('[data-testid="onboarding-title"]').should('have.text', 'Welcome to SecondBrain!')
// Open settings modal
cy.get('div[data-testid="settings-modal"]').should('be.visible').click()

// Asserting the settings label text
cy.get('[data-testid="setting-label"]').should('have.text', 'Admin Settings')

// Efficiently interact with the about title
cy.get('#cy-graph-title-id').should('be.visible').click().type('{selectAll}').type(title)
cy.get('#cy-about-title-id').should('be.visible').click().type('{selectAll}').type(title)

// Efficiently interact with the about description
cy.get('#cy-graph-description-id').should('be.visible').click().type('{selectAll}').type(description)
cy.get('#cy-about-id').should('be.visible').click().type('{selectAll}').type(description)

// Submit the form
cy.get('#onboarding-confirm-cta').click()
cy.get('#add-node-submit-cta').click()
cy.wait('@updateAbout')

cy.wait(1000)
Expand Down
53 changes: 33 additions & 20 deletions src/components/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useAppStore } from '~/stores/useAppStore'
import { useDataStore } from '~/stores/useDataStore'
import { useFeatureFlagStore } from '~/stores/useFeatureFlagStore'
import { useUpdateSelectedNode } from '~/stores/useGraphStore'
import { useModal } from '~/stores/useModalStore'
import { useTeachStore } from '~/stores/useTeachStore'
import { useUserStore } from '~/stores/useUserStore'
import {
Expand All @@ -29,6 +30,7 @@ import { colors } from '~/utils/colors'
import { updateBudget } from '~/utils/setBudget'
import version from '~/utils/versionHelper'
import { ModalsContainer } from '../ModalsContainer'
import { OnboardingModal } from '../ModalsContainer/OnboardingFlow'
import { ActionsToolbar } from './ActionsToolbar'
import { AppBar } from './AppBar'
import { DeviceCompatibilityNotice } from './DeviceCompatibilityNotification'
Expand Down Expand Up @@ -56,9 +58,10 @@ const LazySideBar = lazy(() => import('./SideBar').then(({ SideBar }) => ({ defa
export const App = () => {
const [searchParams] = useSearchParams()
const query = searchParams.get('q')
const { setBudget, setNodeCount } = useUserStore((s) => s)
const { setBudget, setNodeCount, isAdmin } = useUserStore((s) => s)
const queueRef = useRef<FetchDataResponse | null>(null)
const timerRef = useRef<NodeJS.Timeout | null>(null)
const { open, visible } = useModal('onboardingFlow')

const {
setSidebarOpen,
Expand All @@ -68,6 +71,7 @@ export const App = () => {
setTranscriptOpen,
universeQuestionIsOpen,
setUniverseQuestionIsOpen,
appMetaData,
} = useAppStore((s) => s)

const setTeachMeAnswer = useTeachStore((s) => s.setTeachMeAnswer)
Expand Down Expand Up @@ -322,10 +326,16 @@ export const App = () => {
}, [runningProjectId, setRunningProjectMessages])

useEffect(() => {
if (!splashDataLoading) {
setUniverseQuestionIsOpen()
if (isAdmin && !appMetaData?.title && !visible) {
open() // Open the onboarding modal if conditions are met
}
}, [setUniverseQuestionIsOpen, splashDataLoading])
}, [isAdmin, appMetaData?.title, open, visible])

useEffect(() => {
if (!splashDataLoading && !visible) {
setUniverseQuestionIsOpen() // Set universe question open only if onboarding is not visible
}
}, [setUniverseQuestionIsOpen, splashDataLoading, visible])

return (
<>
Expand All @@ -336,22 +346,25 @@ export const App = () => {
<Leva hidden={!isDevelopment || true} isRoot />

<Suspense fallback={<div>Loading...</div>}>
{!splashDataLoading ? (
<Wrapper direction="row">
<FormProvider {...form}>
<LazyMainToolbar />
{!universeQuestionIsOpen && <LazySideBar />}
<LazyUniverse />
<Overlay />
<AppBar />
<Version>v{version}</Version>
<ActionsToolbar />
</FormProvider>

<ModalsContainer />
<Toasts />
</Wrapper>
) : null}
{!splashDataLoading &&
(visible ? (
<OnboardingModal /> // Show OnboardingModal if visible
) : (
<Wrapper direction="row">
<FormProvider {...form}>
<LazyMainToolbar />
{!universeQuestionIsOpen && <LazySideBar />}
<LazyUniverse />
<Overlay />
<AppBar />
<Version>v{version}</Version>
<ActionsToolbar />
</FormProvider>

<ModalsContainer />
<Toasts />
</Wrapper>
))}
</Suspense>
</>
)
Expand Down
30 changes: 7 additions & 23 deletions src/components/AppContainer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,24 @@
import { lazy, Suspense, useEffect } from 'react'
import { lazy, Suspense } from 'react'
import { Route, Routes } from 'react-router-dom'
import { useAppStore } from '~/stores/useAppStore'
import { useModal } from '~/stores/useModalStore'
import { useUserStore } from '~/stores/useUserStore'

import { E2ETests } from '~/utils'
import { AppProviders } from '../App/Providers'
import { AuthGuard } from '../Auth'
import { OnboardingModal } from '../ModalsContainer/OnboardingFlow'

const LazyApp = lazy(() => import('../App').then(({ App }) => ({ default: App })))

export const AppContainer = () => {
const App = <LazyApp />
const [isAdmin] = useUserStore((s) => [s.isAdmin, s.setPubKey])
const { open, visible } = useModal('onboardingFlow')
const { appMetaData } = useAppStore((s) => s)

useEffect(() => {
if (isAdmin && !appMetaData?.title && !visible) {
open()
}
}, [isAdmin, appMetaData?.title, open, visible])

return (
<AppProviders>
<Suspense fallback={<div>Loading...</div>}>
<AuthGuard>
{visible ? (
<OnboardingModal />
) : (
<Routes>
<Route element={App} path="/" />
<Route element={App} path="/search" />
<Route element={App} path="*" />
</Routes>
)}
<Routes>
<Route element={App} path="/" />
<Route element={App} path="/search" />
<Route element={App} path="*" />
</Routes>
</AuthGuard>
</Suspense>
<E2ETests />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ export const GraphDetailsStep: FC<Props> = ({ onSubmit, error }) => {
return (
<Flex>
<Flex align="center" direction="column" justify="center">
<StyledText data-testid="onboarding-title">Welcome to SecondBrain!</StyledText>
<StyledText>Welcome to SecondBrain!</StyledText>
<StyledSubText>Set a name and short description for your graph.</StyledSubText>
</Flex>

<StyledWrapper>
<Flex className="input__wrapper">
<TextInput
id="cy-graph-title-id"
id="graph-title"
label="Title"
maxLength={50}
name="title"
Expand All @@ -58,7 +58,7 @@ export const GraphDetailsStep: FC<Props> = ({ onSubmit, error }) => {
}}
/>
<TextInput
id="cy-graph-description-id"
id="graph-description"
label="Description"
maxLength={100}
name="description"
Expand All @@ -78,7 +78,6 @@ export const GraphDetailsStep: FC<Props> = ({ onSubmit, error }) => {
<Button
color="secondary"
disabled={isSubmitting || !!error || !isFormValid}
id="onboarding-confirm-cta"
onClick={onSubmit}
size="large"
variant="contained"
Expand Down

0 comments on commit f20f976

Please sign in to comment.