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

fix: remove loading animation in inlineloading inactive state #17814

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
@@ -0,0 +1,90 @@
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import InlineLoading from '../InlineLoading';
import { render, screen } from '@testing-library/react';

describe('InlineLoading', () => {
it('should pass in extra classes that are passed via className', () => {
render(<InlineLoading className="custom-class" data-testid="loading-1" />);

expect(screen.getByTestId('loading-1')).toHaveClass('custom-class');
});

it('should render a loader by default', () => {
render(<InlineLoading />);

expect(screen.getByTitle('loading')).toBeInTheDocument();
});

it('should render a loader if the status is inactive', () => {
render(<InlineLoading status="inactive" />);

expect(screen.getByTitle('not loading')).toBeInTheDocument();
});

it('should render the success state if status is finished', () => {
render(<InlineLoading status="finished" />);

// eslint-disable-next-line testing-library/no-node-access
expect(document.querySelector('svg')).toHaveClass(
'cds--inline-loading__checkmark-container'
);
});

it('should render the error state if status is error', () => {
render(<InlineLoading status="error" />);

// eslint-disable-next-line testing-library/no-node-access
expect(document.querySelector('svg')).toHaveClass(
'cds--inline-loading--error'
);
});

it('should not render any text by default', () => {
render(<InlineLoading />);

expect(
// eslint-disable-next-line testing-library/no-node-access
document.querySelector('.cds--inline-loading__text')
).not.toBeInTheDocument();
});

it('should render text when the description prop is passed', () => {
render(<InlineLoading description="Loading" />);
expect(screen.getByText('Loading')).toBeInTheDocument();
});

it('should call the onSuccess prop after a delay', () => {
jest.useFakeTimers();
const onSuccess = jest.fn();

render(<InlineLoading status="finished" onSuccess={onSuccess} />);

jest.runAllTimers();
expect(onSuccess).toHaveBeenCalled();
jest.useRealTimers();
});

it('should allow users to override the onSuccess timeout', () => {
jest.useFakeTimers();
const onSuccess = jest.fn();

render(
<InlineLoading
status="finished"
onSuccess={onSuccess}
successDelay={2500}
/>
);

jest.runAllTimers();
expect(onSuccess).toHaveBeenCalled();
jest.useRealTimers();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import InlineLoading from '../InlineLoading';
import { render, screen } from '@testing-library/react';

describe('InlineLoading', () => {
it('should pass in extra classes that are passed via className', () => {
render(<InlineLoading className="custom-class" data-testid="loading-1" />);

expect(screen.getByTestId('loading-1')).toHaveClass('custom-class');
});

it('should render a loader by default', () => {
render(<InlineLoading />);

expect(screen.getByTitle('loading')).toBeInTheDocument();
});

it('should render a loader if the status is inactive', () => {
render(<InlineLoading status="inactive" />);
console.log('sceern', screen.getByTitle());
console.log('sceern', screen);

expect(screen.getByTitle('not loading')).toBeInTheDocument();
});

it('should render the success state if status is finished', () => {
render(<InlineLoading status="finished" />);

// eslint-disable-next-line testing-library/no-node-access
expect(document.querySelector('svg')).toHaveClass(
'cds--inline-loading__checkmark-container'
);
});

it('should render the error state if status is error', () => {
render(<InlineLoading status="error" />);

// eslint-disable-next-line testing-library/no-node-access
expect(document.querySelector('svg')).toHaveClass(
'cds--inline-loading--error'
);
});

it('should not render any text by default', () => {
render(<InlineLoading />);

expect(
// eslint-disable-next-line testing-library/no-node-access
document.querySelector('.cds--inline-loading__text')
).not.toBeInTheDocument();
});

it('should render text when the description prop is passed', () => {
render(<InlineLoading description="Loading" />);
expect(screen.getByText('Loading')).toBeInTheDocument();
});

it('should call the onSuccess prop after a delay', () => {
jest.useFakeTimers();
const onSuccess = jest.fn();

render(<InlineLoading status="finished" onSuccess={onSuccess} />);

jest.runAllTimers();
expect(onSuccess).toHaveBeenCalled();
jest.useRealTimers();
});

it('should allow users to override the onSuccess timeout', () => {
jest.useFakeTimers();
const onSuccess = jest.fn();

render(
<InlineLoading
status="finished"
onSuccess={onSuccess}
successDelay={2500}
/>
);

jest.runAllTimers();
expect(onSuccess).toHaveBeenCalled();
jest.useRealTimers();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import InlineLoading from '../InlineLoading';
import { render, screen } from '@testing-library/react';

describe('InlineLoading', () => {
it('should pass in extra classes that are passed via className', () => {
render(<InlineLoading className="custom-class" data-testid="loading-1" />);

expect(screen.getByTestId('loading-1')).toHaveClass('custom-class');
});

it('should render a loader by default', () => {
render(<InlineLoading />);

expect(screen.getByTitle('loading')).toBeInTheDocument();
});

it('should render a loader if the status is inactive', () => {
render(<InlineLoading status="inactive" />);
console.log('sceern', screen.getByTitle());
console.log('sceern', screen);

expect(screen.getByTitle('not loading')).toBeInTheDocument();
});

it('should render the success state if status is finished', () => {
render(<InlineLoading status="finished" />);

// eslint-disable-next-line testing-library/no-node-access
expect(document.querySelector('svg')).toHaveClass(
'cds--inline-loading__checkmark-container'
);
});

it('should render the error state if status is error', () => {
render(<InlineLoading status="error" />);

// eslint-disable-next-line testing-library/no-node-access
expect(document.querySelector('svg')).toHaveClass(
'cds--inline-loading--error'
);
});

it('should not render any text by default', () => {
render(<InlineLoading />);

expect(
// eslint-disable-next-line testing-library/no-node-access
document.querySelector('.cds--inline-loading__text')
).not.toBeInTheDocument();
});

it('should render text when the description prop is passed', () => {
render(<InlineLoading description="Loading" />);
expect(screen.getByText('Loading')).toBeInTheDocument();
});

it('should call the onSuccess prop after a delay', () => {
jest.useFakeTimers();
const onSuccess = jest.fn();

render(<InlineLoading status="finished" onSuccess={onSuccess} />);

jest.runAllTimers();
expect(onSuccess).toHaveBeenCalled();
jest.useRealTimers();
});

it('should allow users to override the onSuccess timeout', () => {
jest.useFakeTimers();
const onSuccess = jest.fn();

render(
<InlineLoading
status="finished"
onSuccess={onSuccess}
successDelay={2500}
/>
);

jest.runAllTimers();
expect(onSuccess).toHaveBeenCalled();
jest.useRealTimers();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import InlineLoading from '../InlineLoading';
import { render, screen } from '@testing-library/react';

describe('InlineLoading', () => {
it('should pass in extra classes that are passed via className', () => {
render(<InlineLoading className="custom-class" data-testid="loading-1" />);

expect(screen.getByTestId('loading-1')).toHaveClass('custom-class');
});

it('should render a loader by default', () => {
render(<InlineLoading />);

expect(screen.getByTitle('loading')).toBeInTheDocument();
});

it('should render a loader if the status is inactive', () => {
render(<InlineLoading status="inactive" />);
console.log('sceern', screen.getByTitle());
console.log('sceern', screen);
expect(
// eslint-disable-next-line testing-library/no-node-access
document.querySelector('.cds--inline-loading__inactive-status')
).not.toBeInTheDocument();

expect(screen.getByTitle('not loading')).toBeInTheDocument();
});

it('should render the success state if status is finished', () => {
render(<InlineLoading status="finished" />);

// eslint-disable-next-line testing-library/no-node-access
expect(document.querySelector('svg')).toHaveClass(
'cds--inline-loading__checkmark-container'
);
});

it('should render the error state if status is error', () => {
render(<InlineLoading status="error" />);

// eslint-disable-next-line testing-library/no-node-access
expect(document.querySelector('svg')).toHaveClass(
'cds--inline-loading--error'
);
});

it('should not render any text by default', () => {
render(<InlineLoading />);

expect(
// eslint-disable-next-line testing-library/no-node-access
document.querySelector('.cds--inline-loading__text')
).not.toBeInTheDocument();
});

it('should render text when the description prop is passed', () => {
render(<InlineLoading description="Loading" />);
expect(screen.getByText('Loading')).toBeInTheDocument();
});

it('should call the onSuccess prop after a delay', () => {
jest.useFakeTimers();
const onSuccess = jest.fn();

render(<InlineLoading status="finished" onSuccess={onSuccess} />);

jest.runAllTimers();
expect(onSuccess).toHaveBeenCalled();
jest.useRealTimers();
});

it('should allow users to override the onSuccess timeout', () => {
jest.useFakeTimers();
const onSuccess = jest.fn();

render(
<InlineLoading
status="finished"
onSuccess={onSuccess}
successDelay={2500}
/>
);

jest.runAllTimers();
expect(onSuccess).toHaveBeenCalled();
jest.useRealTimers();
});
});
Loading
Loading