test: add unit tests for NodeStatus component

This commit is contained in:
jamaljsr 2020-04-20 20:23:49 -04:00
parent 6b77767bc4
commit 49d12a35a9
3 changed files with 48 additions and 0 deletions

View file

@ -0,0 +1,26 @@
import React from 'react';
import { renderWithProviders } from 'util/tests';
import NodeStatus from 'components/NodeStatus';
describe('NodeStatus component', () => {
const render = () => {
return renderWithProviders(<NodeStatus />);
};
it('should display the Node Status label', () => {
const { getByText } = render();
expect(getByText('Node Status')).toBeInTheDocument();
});
it('should display the lightning balance', () => {
const { getByText, store } = render();
store.balances = { channelBalance: 123, walletBalance: 0 };
expect(getByText('123 SAT')).toBeInTheDocument();
});
it('should display the bitcoin balance', () => {
const { getByText, store } = render();
store.balances = { channelBalance: 0, walletBalance: 234 };
expect(getByText('234')).toBeInTheDocument();
});
});

View file

@ -0,0 +1 @@
export { default as renderWithProviders } from './renderWithProviders';

View file

@ -0,0 +1,21 @@
import React from 'react';
import { render } from '@testing-library/react';
import { Store, StoreProvider } from 'store';
import { ThemeProvider } from 'components/theme';
/**
* Renders a component inside of the theme and mobx store providers
* to supply context items needed to render some child components
* @param component the component under test to render
*/
const renderWithProviders = (component: React.ReactElement) => {
const store = new Store();
const result = render(
<StoreProvider store={store}>
<ThemeProvider>{component}</ThemeProvider>
</StoreProvider>,
);
return { ...result, store };
};
export default renderWithProviders;