From e46fb81426337123004d97986c90bdc5e4de1d9d Mon Sep 17 00:00:00 2001 From: Josefina Mancilla <32556167+jnm2377@users.noreply.github.com> Date: Thu, 23 Jun 2022 16:11:42 -0500 Subject: [PATCH] chore: update InlineLoading to rtl (#11645) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../InlineLoading/InlineLoading-test.js | 140 +++++++++--------- 1 file changed, 67 insertions(+), 73 deletions(-) diff --git a/packages/react/src/components/InlineLoading/InlineLoading-test.js b/packages/react/src/components/InlineLoading/InlineLoading-test.js index b58b402a1137..00c0954db3e9 100644 --- a/packages/react/src/components/InlineLoading/InlineLoading-test.js +++ b/packages/react/src/components/InlineLoading/InlineLoading-test.js @@ -7,91 +7,85 @@ import React from 'react'; import InlineLoading from '../InlineLoading'; -import Loading from '../Loading'; -import { mount } from 'enzyme'; - -const prefix = 'cds'; - -describe('Loading', () => { - describe('Default state renders as expected', () => { - const wrapper = mount(); - const container = wrapper.find(`.${prefix}--inline-loading`); - - it('should render with a container', () => { - expect(container.length).toEqual(1); - }); - - it('should render a loader by default', () => { - expect(wrapper.find(Loading).length).toEqual(1); - }); - - it('container has the expected classes', () => { - expect(container.hasClass(`${prefix}--inline-loading`)).toEqual(true); - }); - - it('should add extra classes that are passed via className', () => { - expect(container.hasClass('extra-class')).toEqual(true); - }); - - it('should render an animation container', () => { - expect( - wrapper.find(`.${prefix}--inline-loading__animation`).length - ).toEqual(1); - }); - - it('should not render any text', () => { - expect(wrapper.find(`.${prefix}--inline-loading__text`).length).toEqual( - 0 - ); - }); - - it('should not render the SUCCESS state', () => { - expect( - wrapper.find(`.${prefix}--inline-loading__checkmark-container`).length - ).toEqual(0); - }); +import { render, screen } from '@testing-library/react'; + +describe('InlineLoading', () => { + it('should pass in extra classes that are passed via className', () => { + render(); + + expect(screen.getByTestId('loading-1')).toHaveClass('custom-class'); + }); + + it('should render a loader by default', () => { + render(); + + expect( + screen.getByLabelText('Active loading indicator') + ).toBeInTheDocument(); }); - describe('Text rendered as expected', () => { - const wrapper = mount( - + it('should render a loader if the status is inactive', () => { + render(); + + expect( + screen.getByLabelText('Active loading indicator') + ).toBeInTheDocument(); + }); + + it('should render the success state if status is finished', () => { + render(); + + expect(document.querySelector('svg')).toHaveClass( + 'cds--inline-loading__checkmark-container' ); + }); + + it('should render the error state if status is error', () => { + render(); - it('should render the provided description', () => { - expect(wrapper.find(`.${prefix}--inline-loading__text`).length).toEqual( - 1 - ); - expect(wrapper.find(`.${prefix}--inline-loading__text`).text()).toEqual( - 'Loading Things...' - ); - }); + expect(document.querySelector('svg')).toHaveClass( + 'cds--inline-loading--error' + ); }); - describe('Success state should render properly', () => { - const wrapper = mount(); + it('should not render any text by default', () => { + render(); + + expect( + document.querySelector('.cds--inline-loading__text') + ).not.toBeInTheDocument(); + }); - it('should render the success animation', () => { - expect( - wrapper.find(`svg.${prefix}--inline-loading__checkmark-container`) - .length - ).toEqual(1); - }); + it('should render text when the description prop is passed', () => { + render(); + expect(screen.getByText('Loading')).toBeInTheDocument(); + }); - it('should not render the loading component', () => { - expect(wrapper.find(Loading).length).toEqual(0); - }); + it('should call the onSuccess prop after a delay', () => { + jest.useFakeTimers(); + const onSuccess = jest.fn(); - it('should call the onSuccess function after a delay', () => { - jest.useFakeTimers(); + render(); - const onSuccess = jest.fn(); + jest.runAllTimers(); + expect(onSuccess).toHaveBeenCalled(); + jest.useRealTimers(); + }); - mount(); + it('should allow users to override the onSuccess timeout', () => { + jest.useFakeTimers(); + const onSuccess = jest.fn(); - jest.runAllTimers(); - expect(onSuccess).toHaveBeenCalled(); + render( + + ); - jest.useRealTimers(); - }); + jest.runAllTimers(); + expect(onSuccess).toHaveBeenCalled(); + jest.useRealTimers(); }); });