Browse Source

fix(utils): fix the delay util func not returning the promise

master
jamaljsr 5 years ago
parent
commit
6f477ae39d
  1. 5
      src/components/designer/bitcoind/BitcoindDetails.spec.tsx
  2. 27
      src/components/designer/lightning/actions/ChangeBackendModal.spec.tsx
  3. 30
      src/components/designer/lightning/actions/OpenChannelModal.spec.tsx
  4. 5
      src/components/designer/lightning/actions/PayInvoiceModal.spec.tsx
  5. 5
      src/components/designer/link/Backend.spec.tsx
  6. 1
      src/store/models/lightning.ts
  7. 4
      src/utils/async.ts

5
src/components/designer/bitcoind/BitcoindDetails.spec.tsx

@ -16,6 +16,11 @@ describe('BitcoindDetails', () => {
network: {
networks: [network],
},
bitcoind: {
nodes: {
backend1: {},
},
},
};
const node = network.nodes.bitcoin[0];
const cmp = <BitcoindDetails node={node} />;

27
src/components/designer/lightning/actions/ChangeBackendModal.spec.tsx

@ -102,8 +102,9 @@ describe('ChangeBackendModal', () => {
});
expect(store.getState().designer.activeChart.links[linkId]).toBeTruthy();
fireEvent.click(getByText('Cancel'));
await wait();
expect(store.getState().designer.activeChart.links[linkId]).toBeUndefined();
await wait(() => {
expect(store.getState().designer.activeChart.links[linkId]).toBeUndefined();
});
});
it('should display the compatibility warning for older bitcoin node', async () => {
@ -130,8 +131,9 @@ describe('ChangeBackendModal', () => {
it('should do nothing if an invalid node is selected', async () => {
const { getByText } = await renderComponent(Status.Stopped, 'invalid');
fireEvent.click(getByText('Change Backend'));
await wait();
expect(getByText('Change Backend')).toBeInTheDocument();
await wait(() => {
expect(getByText('Change Backend')).toBeInTheDocument();
});
});
describe('with form submitted', () => {
@ -140,8 +142,9 @@ describe('ChangeBackendModal', () => {
fireEvent.click(getByLabelText('Bitcoin Node'));
fireEvent.click(getByText('backend2'));
fireEvent.click(getByText('Change Backend'));
await wait();
expect(store.getState().modals.changeBackend.visible).toBe(false);
await wait(() => {
expect(store.getState().modals.changeBackend.visible).toBe(false);
});
expect(
getByText('The alice node will pull chain data from backend2'),
).toBeInTheDocument();
@ -153,8 +156,9 @@ describe('ChangeBackendModal', () => {
fireEvent.click(getByLabelText('Bitcoin Node'));
fireEvent.click(getByText('backend2'));
fireEvent.click(getByText('Change Backend'));
await wait();
expect(store.getState().modals.changeBackend.visible).toBe(false);
await wait(() => {
expect(store.getState().modals.changeBackend.visible).toBe(false);
});
expect(
getByText('The alice node will pull chain data from backend2'),
).toBeInTheDocument();
@ -165,9 +169,10 @@ describe('ChangeBackendModal', () => {
fireEvent.click(getByLabelText('Bitcoin Node'));
fireEvent.click(getByText('backend2'));
fireEvent.click(getByText('Change Backend'));
await wait();
expect(injections.dockerService.stopNode).toBeCalledTimes(1);
expect(injections.dockerService.startNode).toBeCalledTimes(1);
await wait(() => {
expect(injections.dockerService.stopNode).toBeCalledTimes(1);
expect(injections.dockerService.startNode).toBeCalledTimes(1);
});
});
});
});

30
src/components/designer/lightning/actions/OpenChannelModal.spec.tsx

@ -73,8 +73,9 @@ describe('OpenChannelModal', () => {
expect(btn).toBeInTheDocument();
expect(btn.parentElement).toBeInstanceOf(HTMLButtonElement);
fireEvent.click(getByText('Cancel'));
await wait();
expect(queryByText('Cancel')).not.toBeInTheDocument();
await wait(() => {
expect(queryByText('Cancel')).not.toBeInTheDocument();
});
});
it('should remove chart link when cancel is clicked', async () => {
@ -91,8 +92,9 @@ describe('OpenChannelModal', () => {
});
expect(store.getState().designer.activeChart.links[linkId]).toBeTruthy();
fireEvent.click(getByText('Cancel'));
await wait();
expect(store.getState().designer.activeChart.links[linkId]).toBeUndefined();
await wait(() => {
expect(store.getState().designer.activeChart.links[linkId]).toBeUndefined();
});
});
it('should display an error if unable to fetch node balances', async () => {
@ -118,8 +120,9 @@ describe('OpenChannelModal', () => {
);
fireEvent.change(getByLabelText('Capacity (sats)'), { target: { value: '1000' } });
fireEvent.click(getByText('Open Channel'));
await wait();
expect(getByText('Open Channel')).toBeInTheDocument();
await wait(() => {
expect(getByText('Open Channel')).toBeInTheDocument();
});
});
describe('with form submitted', () => {
@ -143,8 +146,9 @@ describe('OpenChannelModal', () => {
fireEvent.change(getByLabelText('Capacity (sats)'), { target: { value: '1000' } });
fireEvent.click(getByLabelText('Deposit enough funds to bob to open the channel'));
fireEvent.click(getByText('Open Channel'));
await wait();
expect(store.getState().modals.openChannel.visible).toBe(false);
await wait(() => {
expect(store.getState().modals.openChannel.visible).toBe(false);
});
const node2 = network.nodes.lightning[1];
expect(lightningServiceMock.openChannel).toBeCalledWith(node2, 'asdf@host', 1000);
expect(bitcoindServiceMock.mine).toBeCalledTimes(1);
@ -155,8 +159,9 @@ describe('OpenChannelModal', () => {
act(() => store.getActions().modals.showOpenChannel({ from: 'bob', to: 'alice' }));
fireEvent.change(getByLabelText('Capacity (sats)'), { target: { value: '1000' } });
fireEvent.click(getByText('Open Channel'));
await wait();
expect(store.getState().modals.openChannel.visible).toBe(false);
await wait(() => {
expect(store.getState().modals.openChannel.visible).toBe(false);
});
const node2 = network.nodes.lightning[1];
expect(lightningServiceMock.openChannel).toBeCalledWith(node2, 'asdf@host', 1000);
expect(bitcoindServiceMock.mine).toBeCalledTimes(2);
@ -171,8 +176,9 @@ describe('OpenChannelModal', () => {
fireEvent.change(getByLabelText('Capacity (sats)'), { target: { value: '1000' } });
fireEvent.click(getByLabelText('Deposit enough funds to bob to open the channel'));
fireEvent.click(getByText('Open Channel'));
await wait();
expect(getByText('Unable to open the channel')).toBeInTheDocument();
await wait(() => {
expect(getByText('Unable to open the channel')).toBeInTheDocument();
});
expect(getByText('error-msg')).toBeInTheDocument();
});
});

5
src/components/designer/lightning/actions/PayInvoiceModal.spec.tsx

@ -63,8 +63,9 @@ describe('PayInvoiceModal', () => {
expect(btn).toBeInTheDocument();
expect(btn.parentElement).toBeInstanceOf(HTMLButtonElement);
fireEvent.click(getByText('Cancel'));
await wait();
expect(queryByText('Cancel')).not.toBeInTheDocument();
await wait(() => {
expect(queryByText('Cancel')).not.toBeInTheDocument();
});
});
it('should display an error if form is not valid', async () => {

5
src/components/designer/link/Backend.spec.tsx

@ -65,7 +65,8 @@ describe('Backend component', () => {
const { getByText, store } = renderComponent();
expect(store.getState().modals.changeBackend.visible).toBe(false);
fireEvent.click(getByText('Change Backend'));
await wait();
expect(store.getState().modals.changeBackend.visible).toBe(true);
await wait(() => {
expect(store.getState().modals.changeBackend.visible).toBe(true);
});
});
});

1
src/store/models/lightning.ts

@ -249,7 +249,6 @@ const lightningModel: LightningModel = {
(d, node) => Math.max(d, nodeDelays[node.implementation]),
0,
);
await delay(longestDelay * 1000);
}),
mineListener: thunkOn(

4
src/utils/async.ts

@ -2,9 +2,9 @@
* Returns a promise that will be reolved after the specified timeout
* @param timeout the amount of ms to wait
*/
export const delay = async (timeout: number) => {
export const delay = (timeout: number) => {
if (process.env.NODE_ENV === 'test') timeout = 10;
new Promise(resolve => setTimeout(resolve, timeout));
return new Promise(resolve => setTimeout(resolve, timeout));
};
/**

Loading…
Cancel
Save