Skip to content
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
10 changes: 8 additions & 2 deletions packages/react-styled/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"dev": "npm run copy-assets && tsc --build --watch --preserveWatchOutput",
"predev": "npm run copy-assets",
"clean": "rm -rf dist *.tsbuildinfo",
"lint": "eslint \"src/**/*.{ts,tsx}\""
"lint": "eslint \"src/**/*.{ts,tsx}\" \"test/**/*.{ts,tsx}\"",
"test": "vitest run"
},
"files": [
"dist",
Expand All @@ -41,9 +42,14 @@
"@storacha/ui-core": "^2.4.0"
},
"devDependencies": {
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.0.0",
"@types/react": "^18.0.0",
"fake-indexeddb": "^5.0.0",
"happy-dom": "^12.0.0",
"react": "^18.0.0",
"typescript": "^5.0.0"
"typescript": "^5.0.0",
"vitest": "^1.0.0"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
Expand Down
179 changes: 179 additions & 0 deletions packages/react-styled/test/StorachaAuth.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
import { test, expect, vi, beforeEach, describe } from 'vitest'
import { render, screen, cleanup, waitFor } from '@testing-library/react'
import 'fake-indexeddb/auto'
import { Provider, StorachaAuth as HeadlessStorachaAuth } from '@storacha/console-toolkit-react'
import { StorachaAuth } from '../src/components/StorachaAuth.js'

describe('StorachaAuth Styled Component Suite', () => {
beforeEach(() => {
cleanup()
vi.clearAllMocks()
})

describe('StorachaAuth.Form', () => {
test('renders styled form with correct elements', () => {
render(
<Provider>
<HeadlessStorachaAuth>
<StorachaAuth.Form />
</HeadlessStorachaAuth>
</Provider>
)

// Check logo with alt text "Storacha"
expect(screen.getByAltText('Storacha')).toBeTruthy()

// Check email label
expect(screen.getByLabelText('Email')).toBeTruthy()

// Check authorize button
expect(screen.getByRole('button', { name: 'Authorize' })).toBeTruthy()

// Check terms of service text
expect(screen.getByText(/By registering with storacha.network/)).toBeTruthy()
expect(screen.getByText(/Terms of Service/)).toBeTruthy()
})

test('renders email input with correct attributes', () => {
render(
<Provider>
<HeadlessStorachaAuth>
<StorachaAuth.Form />
</HeadlessStorachaAuth>
</Provider>
)

const emailInput = screen.getByLabelText('Email')
expect(emailInput).toBeTruthy()
expect(emailInput.getAttribute('id')).toBe('storacha-auth-email')
})
})

describe('StorachaAuth.EmailInput', () => {
test('renders standalone email input component', () => {
render(
<Provider>
<HeadlessStorachaAuth>
<HeadlessStorachaAuth.Form>
<StorachaAuth.EmailInput />
</HeadlessStorachaAuth.Form>
</HeadlessStorachaAuth>
</Provider>
)

const emailInput = screen.getByRole('textbox')
expect(emailInput).toBeTruthy()
expect(emailInput.getAttribute('id')).toBe('storacha-auth-email')
})
})

describe('StorachaAuth.CancelButton', () => {
test('renders cancel button with correct text', () => {
render(
<Provider>
<HeadlessStorachaAuth>
<StorachaAuth.CancelButton />
</HeadlessStorachaAuth>
</Provider>
)

expect(screen.getByRole('button', { name: 'Cancel' })).toBeTruthy()
})
})

describe('StorachaAuth.Submitted', () => {
test('renders submitted state with email verification message', () => {
render(
<Provider>
<HeadlessStorachaAuth>
<StorachaAuth.Submitted />
</HeadlessStorachaAuth>
</Provider>
)

// Check for verification title
expect(screen.getByText('Verify your email address!')).toBeTruthy()

// Check for logo
expect(screen.getByAltText('Storacha')).toBeTruthy()

// Check for cancel button
expect(screen.getByRole('button', { name: 'Cancel' })).toBeTruthy()

// Check for instruction text
expect(screen.getByText(/authorize this agent/)).toBeTruthy()
expect(screen.getByText(/check your spam folder/)).toBeTruthy()
})
})

describe('StorachaAuth.Ensurer', () => {
test('renders loader initially during initialization', () => {
render(
<Provider>
<HeadlessStorachaAuth>
<StorachaAuth.Ensurer>
<div data-testid="authenticated-content">Authenticated!</div>
</StorachaAuth.Ensurer>
</HeadlessStorachaAuth>
</Provider>
)

// Should show the loader during initialization
expect(screen.getByText('Initializing')).toBeTruthy()
expect(screen.getByText('Setting up authentication...')).toBeTruthy()
})

test('renders form after initialization when not authenticated', async () => {
render(
<Provider>
<HeadlessStorachaAuth>
<StorachaAuth.Ensurer>
<div data-testid="authenticated-content">Authenticated!</div>
</StorachaAuth.Ensurer>
</HeadlessStorachaAuth>
</Provider>
)

// Wait for the form to appear after initialization
await waitFor(() => {
expect(screen.getByLabelText('Email')).toBeTruthy()
})

expect(screen.getByRole('button', { name: 'Authorize' })).toBeTruthy()
})

test('renders with proper styling classes after initialization', async () => {
render(
<Provider>
<HeadlessStorachaAuth>
<StorachaAuth.Ensurer>
<div>Content</div>
</StorachaAuth.Ensurer>
</HeadlessStorachaAuth>
</Provider>
)

// Wait for the form to appear
await waitFor(() => {
const form = document.querySelector('.storacha-auth-form')
expect(form).toBeTruthy()
})
})
})

describe('Export functionality', () => {
test('exports useStorachaAuth hook from headless package', async () => {
const { useStorachaAuth } = await import('../src/components/StorachaAuth.js')
expect(useStorachaAuth).toBeDefined()
expect(typeof useStorachaAuth).toBe('function')
})

test('StorachaAuth has all required subcomponents', () => {
expect(StorachaAuth.Form).toBeDefined()
expect(StorachaAuth.EmailInput).toBeDefined()
expect(StorachaAuth.CancelButton).toBeDefined()
expect(StorachaAuth.Submitted).toBeDefined()
expect(StorachaAuth.Ensurer).toBeDefined()
})
})
})
29 changes: 29 additions & 0 deletions packages/react-styled/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { defineConfig } from 'vitest/config'
import { resolve } from 'path'

export default defineConfig({
test: {
environment: 'happy-dom',
globals: true,
},
resolve: {
alias: [
{
find: /^(.+)\.js$/,
replacement: '$1',
},
{
find: '@',
replacement: resolve(__dirname, './src'),
},
{
find: '@storacha/console-toolkit-react',
replacement: resolve(__dirname, '../react/src'),
},
],
extensions: ['.ts', '.tsx', '.js', '.jsx'],
},
esbuild: {
target: 'node18',
},
})
9 changes: 5 additions & 4 deletions packages/react/test/import-space/ImportSpace.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,12 @@ describe('ImportSpace Component Suite', () => {

await waitFor(
() => {
const importingText = screen.queryByText(/Importing: true/)
const errorText = screen.queryByTestId('error')
expect(importingText || errorText).toBeTruthy()
const importingTrue = screen.queryByText(/Importing: true/)
const errorEl = screen.queryByTestId('error')
const importingFalse = screen.queryByText(/Importing: false/)
expect(importingTrue || errorEl || importingFalse).toBeTruthy()
},
{ timeout: 3000 }
{ timeout: 5000, interval: 150 }
)
})

Expand Down
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.