Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker authored and langz committed Dec 13, 2024
1 parent 68d4944 commit d3f363c
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-span')
})

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-span')
})

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 @@ -322,6 +322,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-span')
})

describe('File Anchor', () => {
it('renders the anchor', () => {
const fileName = 'file.png'
Expand All @@ -337,7 +355,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 d3f363c

Please sign in to comment.