From 177c8745dbf2ac152740b0cdf21caccbbfbcb9d5 Mon Sep 17 00:00:00 2001 From: First-Terraner Date: Fri, 23 Jun 2023 19:34:01 +0200 Subject: [PATCH] add some basic tests for the coin selection modal component --- test/components/CoinSelectionModal.test.tsx | 58 +++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/test/components/CoinSelectionModal.test.tsx b/test/components/CoinSelectionModal.test.tsx index e8830cb6..74dc0a5a 100644 --- a/test/components/CoinSelectionModal.test.tsx +++ b/test/components/CoinSelectionModal.test.tsx @@ -17,4 +17,62 @@ describe('Basic styling test of the CoinSelectionModal component', () => { const modal = screen.getByTestId('testCoinSelectionModal') expect(modal.props.children.props.children.props.style[0].paddingHorizontal).toBe(0) }) + it('hides the confirm button if not enough proofs are selected', () => { + render( + l('test coin selection modal')} + proofs={[ + { selected: false, amount: 4, secret: '', C: '', id: '0' }, + { selected: false, amount: 8, secret: '', C: '', id: '1' }, + ]} + setProof={() => l('proofs')} + /> + ) + expect(screen.queryByText('Confirm')).toBeNull() + }) + it('should display the confirm button if enough proofs are selected', () => { + render( + l('test coin selection modal')} + proofs={[ + { selected: true, amount: 4, secret: '', C: '', id: '0' }, + { selected: true, amount: 8, secret: '', C: '', id: '1' }, + ]} + setProof={() => l('proofs')} + /> + ) + expect(screen.getByText('Confirm')).toBeDefined() + }) + it('should display the change after selecting more proofs than needed', () => { + render( + l('test coin selection modal')} + proofs={[ + { selected: true, amount: 4, secret: '', C: '', id: '0' }, + { selected: true, amount: 8, secret: '', C: '', id: '1' }, + ]} + setProof={() => l('proofs')} + /> + ) + expect(screen.getByText('Change')).toBeDefined() + expect(screen.getByText('2 Sat')).toBeDefined() + }) + it('should not display the change after selecting the exact proofs needed', () => { + render( + l('test coin selection modal')} + proofs={[ + { selected: true, amount: 4, secret: '', C: '', id: '0' }, + { selected: true, amount: 4, secret: '', C: '', id: '1' }, + { selected: true, amount: 2, secret: '', C: '', id: '2' }, + ]} + setProof={() => l('proofs')} + /> + ) + expect(screen.queryByText('Change')).toBeNull() + }) })