Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

some fix

kruzhambus5257ccf51bce
diff --git a/src/App.test.tsx b/src/App.test.tsx
deleted file mode 100644
index 18fcec51e..000000000
--- a/src/App.test.tsx
+++ /dev/null
@@ -1,60 +0,0 @@
-import React from 'react'
-import { Provider } from 'react-redux'
-import { MemoryRouter } from 'react-router-dom'
-// eslint-disable-next-line import/no-extraneous-dependencies
-import { render, screen, waitFor } from '@testing-library/react'
-import { configureStore } from '@reduxjs/toolkit'
-
-import App from './App'
-
-const mockStore = configureStore({
- reducer: {
- auth: {
- loading: false,
- authenticated: false,
- user: null,
- },
- ui: {
- theme: {
- theme: 'light',
- },
- },
- errors: {
- error: null,
- },
- alerts: {
- message: '',
- type: '',
- },
- },
-} as any)
-
-describe('App component', () => {
- it('renders the main page', async () => {
- render(
- <Provider store={mockStore}>
- <MemoryRouter initialEntries={['/']}>
- <App />
- </MemoryRouter>
- </Provider>,
- )
-
- // eslint-disable-next-line testing-library/prefer-find-by
- await waitFor(() => expect(screen.getByTestId('main-page')).toBeInTheDocument())
- })
-
- it('renders the sign up page', async () => {
- render(
- <Provider store={mockStore}>
- <MemoryRouter initialEntries={['/signup']}>
- <App />
- </MemoryRouter>
- </Provider>,
- )
-
- // eslint-disable-next-line testing-library/prefer-find-by
- await waitFor(() => expect(screen.getByTestId('signup-page')).toBeInTheDocument())
- })
-
- // Add more test cases for other routes
-})
diff --git a/src/ui/test/Alert.test.tsx b/src/ui/test/Alert.test.tsx
new file mode 100644
index 000000000..f40228ff6
--- /dev/null
+++ b/src/ui/test/Alert.test.tsx
@@ -0,0 +1,49 @@
+/* eslint-disable testing-library/prefer-screen-queries */
+/* eslint-disable import/no-extraneous-dependencies */
+import React from 'react'
+import { render, fireEvent } from '@testing-library/react'
+import AlertTemplate from '../Alert'
+
+describe('AlertTemplate', () => {
+ const closeMock = jest.fn()
+
+ afterEach(() => {
+ closeMock.mockClear()
+ })
+
+ test('renders an info alert', () => {
+ const { getByText, getByRole } = render(
+ <AlertTemplate message='This is an info alert' options={{ type: 'info' }} close={closeMock} />,
+ )
+
+ expect(getByText('This is an info alert')).toBeInTheDocument()
+ expect(getByRole('button')).toBeInTheDocument()
+
+ fireEvent.click(getByRole('button'))
+ expect(closeMock).toHaveBeenCalled()
+ })
+
+ test('renders a success alert', () => {
+ const { getByText, getByRole } = render(
+ <AlertTemplate message='This is a success alert' options={{ type: 'success' }} close={closeMock} />,
+ )
+
+ expect(getByText('This is a success alert')).toBeInTheDocument()
+ expect(getByRole('button')).toBeInTheDocument()
+
+ fireEvent.click(getByRole('button'))
+ expect(closeMock).toHaveBeenCalled()
+ })
+
+ test('renders an error alert', () => {
+ const { getByText, getByRole } = render(
+ <AlertTemplate message='This is an error alert' options={{ type: 'error' }} close={closeMock} />,
+ )
+
+ expect(getByText('This is an error alert')).toBeInTheDocument()
+ expect(getByRole('button')).toBeInTheDocument()
+
+ fireEvent.click(getByRole('button'))
+ expect(closeMock).toHaveBeenCalled()
+ })
+})
diff --git a/src/ui/test/Beta.test.tsx b/src/ui/test/Beta.test.tsx
new file mode 100644
index 000000000..c29066864
--- /dev/null
+++ b/src/ui/test/Beta.test.tsx
@@ -0,0 +1,31 @@
+/* eslint-disable testing-library/prefer-screen-queries */
+/* eslint-disable import/no-extraneous-dependencies */
+import React from 'react'
+import { render } from '@testing-library/react'
+import { I18nextProvider } from 'react-i18next'
+import i18n from 'i18next'
+import Beta from '../Beta'
+
+describe('Beta component', () => {
+ beforeEach(() => {
+ i18n.init({
+ lng: 'en',
+ resources: {
+ en: {
+ beta: {
+ title: 'Beta',
+ },
+ },
+ },
+ })
+ })
+
+ it('should render with a custom class name', () => {
+ const { getByText } = render(
+ <I18nextProvider i18n={i18n}>
+ <Beta className='custom-class-name' />
+ </I18nextProvider>,
+ )
+ expect(getByText('Beta')).toHaveClass('custom-class-name')
+ })
+})
diff --git a/src/ui/test/Button.test.tsx b/src/ui/test/Button.test.tsx
new file mode 100644
index 000000000..0bddb3ef1
--- /dev/null
+++ b/src/ui/test/Button.test.tsx
@@ -0,0 +1,95 @@
+/* eslint-disable import/no-extraneous-dependencies */
+/* eslint-disable testing-library/prefer-screen-queries */
+import React from 'react'
+import { render, fireEvent } from '@testing-library/react'
+import Button from '../Button'
+
+describe('Button component', () => {
+ it('renders with text', () => {
+ const { getByText } = render(<Button text='Click me' />)
+ expect(getByText('Click me')).toBeInTheDocument()
+ })
+
+ it('renders with children', () => {
+ const { getByText } = render(<Button><span>Click me</span></Button>)
+ expect(getByText('Click me')).toBeInTheDocument()
+ })
+
+ it('handles clicks', () => {
+ const onClick = jest.fn()
+ const { getByRole } = render(<Button onClick={onClick} />)
+ fireEvent.click(getByRole('button'))
+ expect(onClick).toHaveBeenCalledTimes(1)
+ })
+
+ it('renders a primary button', () => {
+ const { getByText } = render(<Button text='Click me' primary />)
+ const button = getByText('Click me')
+ expect(button).toHaveClass('bg-indigo-600')
+ })
+
+ it('renders a secondary button', () => {
+ const { getByText } = render(<Button text='Click me' secondary />)
+ const button = getByText('Click me')
+ expect(button).toHaveClass('bg-indigo-100')
+ })
+
+ it('renders a white button', () => {
+ const { getByText } = render(<Button text='Click me' white />)
+ const button = getByText('Click me')
+ expect(button).toHaveClass('bg-white')
+ })
+
+ it('renders a danger button', () => {
+ const { getByText } = render(<Button text='Click me' danger />)
+ const button = getByText('Click me')
+ expect(button).toHaveClass('bg-red-500')
+ })
+
+ it('renders a semi-danger button', () => {
+ const { getByText } = render(<Button text='Click me' semiDanger />)
+ const button = getByText('Click me')
+ expect(button).toHaveClass('border-red-600')
+ })
+
+ it('renders a small button', () => {
+ const { getByText } = render(<Button text='Click me' small />)
+ const button = getByText('Click me')
+ expect(button).toHaveClass('text-xs')
+ })
+
+ it('renders a semi-small button', () => {
+ const { getByText } = render(<Button text='Click me' semiSmall />)
+ const button = getByText('Click me')
+ expect(button).toHaveClass('text-sm')
+ })
+
+ it('renders a regular button', () => {
+ const { getByText } = render(<Button text='Click me' regular />)
+ const button = getByText('Click me')
+ expect(button).toHaveClass('text-sm')
+ })
+
+ it('renders a large button', () => {
+ const { getByText } = render(<Button text='Click me' large />)
+ const button = getByText('Click me')
+ expect(button).toHaveClass('text-base')
+ })
+
+ it('renders a giant button', () => {
+ const { getByText } = render(<Button text='Click me' giant />)
+ const button = getByText('Click me')
+ expect(button).toHaveClass('text-base')
+ })
+
+ it('renders a loading button', () => {
+ const { getByTestId } = render(<Button text='Click me' loading />)
+ expect(getByTestId('spinner')).toBeInTheDocument()
+ })
+
+ it('renders a button with no border', () => {
+ const { getByText } = render(<Button text='Click me' noBorder />)
+ const button = getByText('Click me')
+ expect(button).toHaveClass('border-0')
+ })
+})