Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(Upload): add some more tests #1649

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import React, { useEffect } from 'react'
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import Upload from '../Upload'
import nbNO from '../../../shared/locales/nb-NO'
import enGB from '../../../shared/locales/en-GB'
import createMockFile from './testHelpers'
import { loadScss, axeComponent } from '../../../core/jest/jestSetup'
import { UploadAllProps } from '../types'
import useUpload from '../useUpload'
import Provider from '../../../shared/Provider'

const nb = nbNO['nb-NO'].Upload
const en = enGB['en-GB'].Upload

global.URL.createObjectURL = jest.fn(() => 'url')

Expand Down Expand Up @@ -189,6 +192,60 @@ describe('Upload', () => {

expect(element.textContent).toMatch(buttonText)
})

it('should support locale prop', () => {
const { rerender } = render(<Upload {...defaultProps} />)

const element = screen.queryByTestId('upload-title')

expect(element.textContent).toMatch(nb.title)

rerender(<Upload {...defaultProps} locale="en-GB" />)

expect(element.textContent).toMatch(en.title)
})

it('should support locale from provider', () => {
const { rerender } = render(
<Provider>
<Upload {...defaultProps} />
</Provider>
)

const element = screen.queryByTestId('upload-title')

expect(element.textContent).toMatch(nb.title)

rerender(
<Provider locale="en-GB">
<Upload {...defaultProps} />
</Provider>
)

expect(element.textContent).toMatch(en.title)

rerender(
<Provider locale="nb-NO">
<Upload {...defaultProps} />
</Provider>
)

expect(element.textContent).toMatch(nb.title)
})

it('should support spacing props', () => {
render(<Upload top="2rem" {...defaultProps} />)

const element = document.querySelector('.dnb-upload')
const attributes = Array.from(element.attributes).map(
(attr) => attr.name
)

expect(attributes).toEqual(['class', 'data-testid', 'style'])
expect(Array.from(element.classList)).toEqual(
expect.arrayContaining(['dnb-space', 'dnb-space__top--large'])
)
})
})

describe('useUpload', () => {
Expand Down