Skip to content

Commit

Permalink
Add basic tests for admin panel manage scope pages (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
byn9826 authored Oct 9, 2024
1 parent 23e699b commit 6b379ce
Show file tree
Hide file tree
Showing 11 changed files with 743 additions and 28 deletions.
2 changes: 1 addition & 1 deletion admin-panel/app/[lang]/roles/new/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ vi.mock(
() => ({ usePostApiV1RolesMutation: vi.fn() }),
)

const mockCreate = vi.fn().mockReturnValue({ data: { role: { id: 1 } } })
const mockCreate = vi.fn().mockReturnValue({ data: { role: { id: 3 } } })
describe(
'Page Component',
() => {
Expand Down
28 changes: 12 additions & 16 deletions admin-panel/app/[lang]/roles/page.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {
describe, it, expect, vi, beforeEach, Mock,
} from 'vitest'
import {
waitFor, screen,
} from '@testing-library/react'
import { screen } from '@testing-library/react'
import { render } from '../../../vitest.setup'
import Page from 'app/[lang]/roles/page'
import { roles } from 'tests/roleMock'
Expand All @@ -26,21 +24,19 @@ describe(
async () => {
render(<Page />)

await waitFor(() => {
const rows = screen.queryAllByTestId('roleRow')
expect(rows.length).toBe(2)
expect(rows[0].querySelector('td')?.innerHTML).toContain(roles[0].name)
const editLinks = rows[0].querySelector('td')?.getElementsByTagName('a')
expect(editLinks?.length).toBe(0)
const rows = screen.queryAllByTestId('roleRow')
expect(rows.length).toBe(2)
expect(rows[0].querySelector('td')?.innerHTML).toContain(roles[0].name)
const editLinks = rows[0].querySelector('td')?.getElementsByTagName('a')
expect(editLinks?.length).toBe(0)

expect(rows[1].querySelector('td')?.innerHTML).toContain(roles[1].name)
const editLinks1 = rows[1].querySelector('td')?.getElementsByTagName('a')
expect(editLinks1?.length).toBe(1)
expect(editLinks1?.[0].getAttribute('href')).toBe('/en/roles/2')
expect(rows[1].querySelector('td')?.innerHTML).toContain(roles[1].name)
const editLinks1 = rows[1].querySelector('td')?.getElementsByTagName('a')
expect(editLinks1?.length).toBe(1)
expect(editLinks1?.[0].getAttribute('href')).toBe('/en/roles/2')

const createButton = screen.getByTestId('createButton')
expect(createButton.getAttribute('href')).toBe('/en/roles/new')
})
const createButton = screen.getByTestId('createButton')
expect(createButton.getAttribute('href')).toBe('/en/roles/new')
},
)
},
Expand Down
1 change: 1 addition & 0 deletions admin-panel/app/[lang]/scopes/LocaleEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const LocaleEditor = ({
className='flex items-center gap-4'>
<p>{locale.toUpperCase()}</p>
<TextInput
data-testid='localeInput'
className='w-full'
onChange={(e) => handleSetLocale(
locale,
Expand Down
Loading

0 comments on commit 6b379ce

Please sign in to comment.