Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Dec 12, 2024
1 parent a96c1f5 commit 1dc796f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,52 @@ describe('UploadFileListCell', () => {
})
})

it('renders a span when file size is 0', () => {
const fileName = 'file.png'

render(
<UploadFileListCell
{...defaultProps}
uploadFile={{ file: createMockFile(fileName, 0, 'image/png') }}
/>
)
expect(screen.queryByText(fileName).tagName).toBe('SPAN')
expect(screen.queryByText(fileName)).toHaveClass('dnb-t')
})

it('renders a span when file size is not given', () => {
const fileName = 'file.png'

render(
<UploadFileListCell
{...defaultProps}
uploadFile={{
file: createMockFile(fileName, undefined, 'image/png'),
}}
/>
)
expect(screen.queryByText(fileName).tagName).toBe('SPAN')
expect(screen.queryByText(fileName)).toHaveClass('dnb-t')
})

it('renders a button when file size is invalid, but onClick is given', () => {
const fileName = 'file.png'

render(
<UploadFileListCell
{...defaultProps}
uploadFile={{
file: createMockFile(fileName, undefined, 'image/png'),
}}
onClick={jest.fn()}
/>
)

expect(screen.queryByText(fileName).parentElement.tagName).toBe(
'BUTTON'
)
})

describe('File Anchor', () => {
it('renders the anchor', () => {
const fileName = 'file.png'
Expand All @@ -216,7 +262,7 @@ describe('UploadFileListCell', () => {
uploadFile={{ file: createMockFile(fileName, 100, 'image/png') }}
/>
)
expect(screen.queryByText(fileName)).toBeInTheDocument()
expect(screen.queryByText(fileName).tagName).toBe('A')
})

it('renders the anchor href', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,24 @@ describe('Value.Upload', () => {
})
})

it('renders a span when file size is 0', () => {
const fileName = 'file.png'

render(
<Value.Upload
value={[
{
file: createMockFile(fileName, 0, 'image/png'),
exists: false,
id: '1',
},
]}
/>
)
expect(screen.queryByText(fileName).tagName).toBe('SPAN')
expect(screen.queryByText(fileName)).toHaveClass('dnb-t')
})

describe('File Anchor', () => {
it('renders the anchor', () => {
const fileName = 'file.png'
Expand All @@ -336,7 +354,7 @@ describe('Value.Upload', () => {
]}
/>
)
expect(screen.queryByText(fileName)).toBeInTheDocument()
expect(screen.queryByText(fileName).tagName).toBe('A')
})

it('executes onFileClick event when button is clicked', () => {
Expand Down

0 comments on commit 1dc796f

Please sign in to comment.