From 20d773b9cb488e36e3e9abcbd4db3b6c874140c0 Mon Sep 17 00:00:00 2001 From: Tobias Date: Wed, 19 Oct 2022 21:19:04 +0200 Subject: [PATCH] chore(Upload): add some more tests --- .../upload/__tests__/Upload.test.tsx | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/packages/dnb-eufemia/src/components/upload/__tests__/Upload.test.tsx b/packages/dnb-eufemia/src/components/upload/__tests__/Upload.test.tsx index d62e4d509c0..30c64df4712 100644 --- a/packages/dnb-eufemia/src/components/upload/__tests__/Upload.test.tsx +++ b/packages/dnb-eufemia/src/components/upload/__tests__/Upload.test.tsx @@ -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') @@ -189,6 +192,60 @@ describe('Upload', () => { expect(element.textContent).toMatch(buttonText) }) + + it('should support locale prop', () => { + const { rerender } = render() + + const element = screen.queryByTestId('upload-title') + + expect(element.textContent).toMatch(nb.title) + + rerender() + + expect(element.textContent).toMatch(en.title) + }) + + it('should support locale from provider', () => { + const { rerender } = render( + + + + ) + + const element = screen.queryByTestId('upload-title') + + expect(element.textContent).toMatch(nb.title) + + rerender( + + + + ) + + expect(element.textContent).toMatch(en.title) + + rerender( + + + + ) + + expect(element.textContent).toMatch(nb.title) + }) + + it('should support spacing props', () => { + render() + + 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', () => {