test: improve coverage for some files (#33218)

This commit is contained in:
Saumya Talwani
2026-03-12 12:39:10 +05:30
committed by GitHub
parent 68982f910e
commit ed5511ce28
61 changed files with 3191 additions and 304 deletions

View File

@ -1,6 +1,5 @@
import type { CrawlOptions } from '@/models/datasets'
import { fireEvent, render, screen } from '@testing-library/react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import Options from '../options'
// Test Data Factory
@ -104,38 +103,28 @@ describe('Options', () => {
describe('Props Display', () => {
it('should display crawl_sub_pages checkbox with check icon when true', () => {
const payload = createMockCrawlOptions({ crawl_sub_pages: true })
const { container } = render(<Options payload={payload} onChange={mockOnChange} />)
render(<Options payload={payload} onChange={mockOnChange} />)
const checkboxes = getCheckboxes(container)
// First checkbox should have check icon when checked
expect(checkboxes[0].querySelector('svg')).toBeInTheDocument()
expect(screen.queryByTestId('check-icon-crawl-sub-page')).toBeInTheDocument()
})
it('should display crawl_sub_pages checkbox without check icon when false', () => {
const payload = createMockCrawlOptions({ crawl_sub_pages: false })
const { container } = render(<Options payload={payload} onChange={mockOnChange} />)
const checkboxes = getCheckboxes(container)
// First checkbox should not have check icon when unchecked
expect(checkboxes[0].querySelector('svg')).not.toBeInTheDocument()
render(<Options payload={payload} onChange={mockOnChange} />)
expect(screen.queryByTestId('check-icon-crawl-sub-page')).not.toBeInTheDocument()
})
it('should display only_main_content checkbox with check icon when true', () => {
const payload = createMockCrawlOptions({ only_main_content: true })
const { container } = render(<Options payload={payload} onChange={mockOnChange} />)
const checkboxes = getCheckboxes(container)
// Second checkbox should have check icon when checked
expect(checkboxes[1].querySelector('svg')).toBeInTheDocument()
render(<Options payload={payload} onChange={mockOnChange} />)
expect(screen.getByTestId('check-icon-only-main-content')).toBeInTheDocument()
})
it('should display only_main_content checkbox without check icon when false', () => {
const payload = createMockCrawlOptions({ only_main_content: false })
const { container } = render(<Options payload={payload} onChange={mockOnChange} />)
const checkboxes = getCheckboxes(container)
// Second checkbox should not have check icon when unchecked
expect(checkboxes[1].querySelector('svg')).not.toBeInTheDocument()
render(<Options payload={payload} onChange={mockOnChange} />)
expect(screen.queryByTestId('check-icon-only-main-content')).not.toBeInTheDocument()
})
it('should display limit value in input', () => {

View File

@ -32,9 +32,10 @@ const Options: FC<Props> = ({
}
}, [payload, onChange])
return (
<div className={cn(className, ' space-y-2')}>
<div className={cn(className, 'space-y-2')}>
<CheckboxWithLabel
label={t(`${I18N_PREFIX}.crawlSubPage`, { ns: 'datasetCreation' })}
testId="crawl-sub-page"
isChecked={payload.crawl_sub_pages}
onChange={handleChange('crawl_sub_pages')}
labelClassName="text-[13px] leading-[16px] font-medium text-text-secondary"
@ -76,6 +77,7 @@ const Options: FC<Props> = ({
</div>
<CheckboxWithLabel
label={t(`${I18N_PREFIX}.extractOnlyMainContent`, { ns: 'datasetCreation' })}
testId="only-main-content"
isChecked={payload.only_main_content}
onChange={handleChange('only_main_content')}
labelClassName="text-[13px] leading-[16px] font-medium text-text-secondary"

View File

@ -70,34 +70,26 @@ describe('Options (jina-reader)', () => {
describe('Props Display', () => {
it('should display crawl_sub_pages checkbox with check icon when true', () => {
const payload = createMockCrawlOptions({ crawl_sub_pages: true })
const { container } = render(<Options payload={payload} onChange={mockOnChange} />)
const checkboxes = getCheckboxes(container)
expect(checkboxes[0].querySelector('svg')).toBeInTheDocument()
render(<Options payload={payload} onChange={mockOnChange} />)
expect(screen.getByTestId('check-icon-crawl-sub-pages')).toBeInTheDocument()
})
it('should display crawl_sub_pages checkbox without check icon when false', () => {
const payload = createMockCrawlOptions({ crawl_sub_pages: false })
const { container } = render(<Options payload={payload} onChange={mockOnChange} />)
const checkboxes = getCheckboxes(container)
expect(checkboxes[0].querySelector('svg')).not.toBeInTheDocument()
render(<Options payload={payload} onChange={mockOnChange} />)
expect(screen.queryByTestId('check-icon-crawl-sub-pages')).not.toBeInTheDocument()
})
it('should display use_sitemap checkbox with check icon when true', () => {
const payload = createMockCrawlOptions({ use_sitemap: true })
const { container } = render(<Options payload={payload} onChange={mockOnChange} />)
const checkboxes = getCheckboxes(container)
expect(checkboxes[1].querySelector('svg')).toBeInTheDocument()
render(<Options payload={payload} onChange={mockOnChange} />)
expect(screen.getByTestId('check-icon-use-sitemap')).toBeInTheDocument()
})
it('should display use_sitemap checkbox without check icon when false', () => {
const payload = createMockCrawlOptions({ use_sitemap: false })
const { container } = render(<Options payload={payload} onChange={mockOnChange} />)
const checkboxes = getCheckboxes(container)
expect(checkboxes[1].querySelector('svg')).not.toBeInTheDocument()
render(<Options payload={payload} onChange={mockOnChange} />)
expect(screen.queryByTestId('check-icon-use-sitemap')).not.toBeInTheDocument()
})
it('should display limit value in input', () => {
@ -111,10 +103,9 @@ describe('Options (jina-reader)', () => {
describe('User Interactions', () => {
it('should call onChange with updated crawl_sub_pages when checkbox is clicked', () => {
const payload = createMockCrawlOptions({ crawl_sub_pages: true })
const { container } = render(<Options payload={payload} onChange={mockOnChange} />)
render(<Options payload={payload} onChange={mockOnChange} />)
const checkboxes = getCheckboxes(container)
fireEvent.click(checkboxes[0])
fireEvent.click(screen.getByTestId('checkbox-crawl-sub-pages'))
expect(mockOnChange).toHaveBeenCalledWith({
...payload,
@ -124,10 +115,9 @@ describe('Options (jina-reader)', () => {
it('should call onChange with updated use_sitemap when checkbox is clicked', () => {
const payload = createMockCrawlOptions({ use_sitemap: false })
const { container } = render(<Options payload={payload} onChange={mockOnChange} />)
render(<Options payload={payload} onChange={mockOnChange} />)
const checkboxes = getCheckboxes(container)
fireEvent.click(checkboxes[1])
fireEvent.click(screen.getByTestId('checkbox-use-sitemap'))
expect(mockOnChange).toHaveBeenCalledWith({
...payload,

View File

@ -87,10 +87,9 @@ describe('Options (watercrawl)', () => {
describe('Props Display', () => {
it('should display crawl_sub_pages checkbox with check icon when true', () => {
const payload = createMockCrawlOptions({ crawl_sub_pages: true })
const { container } = render(<Options payload={payload} onChange={mockOnChange} />)
render(<Options payload={payload} onChange={mockOnChange} />)
const checkboxes = getCheckboxes(container)
expect(checkboxes[0].querySelector('svg')).toBeInTheDocument()
expect(screen.getByTestId('check-icon-crawl-sub-pages')).toBeInTheDocument()
})
it('should display crawl_sub_pages checkbox without check icon when false', () => {
@ -103,10 +102,8 @@ describe('Options (watercrawl)', () => {
it('should display only_main_content checkbox with check icon when true', () => {
const payload = createMockCrawlOptions({ only_main_content: true })
const { container } = render(<Options payload={payload} onChange={mockOnChange} />)
const checkboxes = getCheckboxes(container)
expect(checkboxes[1].querySelector('svg')).toBeInTheDocument()
render(<Options payload={payload} onChange={mockOnChange} />)
expect(screen.getByTestId('check-icon-only-main-content')).toBeInTheDocument()
})
it('should display only_main_content checkbox without check icon when false', () => {