2021-11-23 17:52:50 +01:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import { renderWithProvider } from '../../../../../../test/jest';
|
2021-12-09 22:34:38 +01:00
|
|
|
import { GasFeeContext } from '../../../../../contexts/gasFee';
|
2021-11-23 17:52:50 +01:00
|
|
|
import configureStore from '../../../../../store/store';
|
|
|
|
|
|
|
|
import StatusSlider from './status-slider';
|
|
|
|
|
2021-12-09 22:34:38 +01:00
|
|
|
const renderComponent = ({ networkCongestion }) => {
|
|
|
|
const component = (
|
|
|
|
<GasFeeContext.Provider value={{ gasFeeEstimates: { networkCongestion } }}>
|
2021-11-23 17:52:50 +01:00
|
|
|
<StatusSlider />
|
2021-12-09 22:34:38 +01:00
|
|
|
</GasFeeContext.Provider>
|
2021-11-23 17:52:50 +01:00
|
|
|
);
|
2021-12-09 22:34:38 +01:00
|
|
|
|
|
|
|
const store = configureStore();
|
|
|
|
|
|
|
|
return renderWithProvider(component, store);
|
2021-11-23 17:52:50 +01:00
|
|
|
};
|
|
|
|
|
2021-12-09 22:34:38 +01:00
|
|
|
describe('StatusSlider', () => {
|
|
|
|
it('should show "Not busy" when networkCongestion is less than 0.33', () => {
|
2022-01-07 20:18:02 +01:00
|
|
|
const { getByText } = renderComponent({ networkCongestion: 0.32 });
|
|
|
|
expect(getByText('Not busy')).toBeInTheDocument();
|
2021-12-09 22:34:38 +01:00
|
|
|
});
|
|
|
|
|
2022-01-07 20:18:02 +01:00
|
|
|
it('should show "Stable" when networkCongestion is 0.33', () => {
|
|
|
|
const { getByText } = renderComponent({ networkCongestion: 0.33 });
|
|
|
|
expect(getByText('Stable')).toBeInTheDocument();
|
2021-12-09 22:34:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should show "Stable" when networkCongestion is between 0.33 and 0.66', () => {
|
2022-01-07 20:18:02 +01:00
|
|
|
const { getByText } = renderComponent({ networkCongestion: 0.5 });
|
|
|
|
expect(getByText('Stable')).toBeInTheDocument();
|
2021-12-09 22:34:38 +01:00
|
|
|
});
|
|
|
|
|
2022-01-07 20:18:02 +01:00
|
|
|
it('should show "Busy" when networkCongestion is 0.66', () => {
|
|
|
|
const { getByText } = renderComponent({ networkCongestion: 0.66 });
|
|
|
|
expect(getByText('Busy')).toBeInTheDocument();
|
2021-12-09 22:34:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should show "Busy" when networkCongestion is greater than 0.66', () => {
|
2022-01-07 20:18:02 +01:00
|
|
|
const { getByText } = renderComponent({ networkCongestion: 0.67 });
|
|
|
|
expect(getByText('Busy')).toBeInTheDocument();
|
2021-12-09 22:34:38 +01:00
|
|
|
});
|
|
|
|
|
2022-01-07 20:18:02 +01:00
|
|
|
it('should show "Stable" if networkCongestion is not available yet', () => {
|
2021-12-09 22:34:38 +01:00
|
|
|
const { getByText } = renderComponent({});
|
|
|
|
expect(getByText('Stable')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should position the arrow based on converting networkCongestion to a percentage rounded to the nearest 10', () => {
|
|
|
|
const { getByTestId } = renderComponent({ networkCongestion: 0.23 });
|
|
|
|
expect(getByTestId('status-slider-arrow-border')).toHaveStyle(
|
|
|
|
'margin-left: 20%',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should position the arrow in the middle if networkCongestion has not been set yet', () => {
|
|
|
|
const { getByTestId } = renderComponent({});
|
|
|
|
expect(getByTestId('status-slider-arrow-border')).toHaveStyle(
|
|
|
|
'margin-left: 50%',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should color the arrow and label based on converting networkCongestion to a percentage rounded to the nearest 10', () => {
|
|
|
|
const { getByTestId } = renderComponent({ networkCongestion: 0.23 });
|
|
|
|
expect(getByTestId('status-slider-arrow')).toHaveStyle(
|
|
|
|
'border-top-color: #2D70BA',
|
|
|
|
);
|
|
|
|
expect(getByTestId('status-slider-label')).toHaveStyle('color: #2D70BA');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should color the arrow and label for the end position if networkCongestion rounds to 100%', () => {
|
|
|
|
const { getByTestId } = renderComponent({ networkCongestion: 0.95 });
|
|
|
|
expect(getByTestId('status-slider-arrow')).toHaveStyle(
|
|
|
|
'border-top-color: #D73A49',
|
|
|
|
);
|
|
|
|
expect(getByTestId('status-slider-label')).toHaveStyle('color: #D73A49');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should color the arrow and label for the middle position if networkCongestion has not been set yet', () => {
|
|
|
|
const { getByTestId } = renderComponent({});
|
|
|
|
expect(getByTestId('status-slider-arrow')).toHaveStyle(
|
|
|
|
'border-top-color: #6A5D92',
|
|
|
|
);
|
|
|
|
expect(getByTestId('status-slider-label')).toHaveStyle('color: #6A5D92');
|
2021-11-23 17:52:50 +01:00
|
|
|
});
|
|
|
|
});
|