Skip to content

Commit 41db4aa

Browse files
committed
determine nextAddressAccount from getNextAddressResponse rather than from the selector.
Thus decreasing interference of the tests.
1 parent 06519da commit 41db4aa

File tree

8 files changed

+345
-68
lines changed

8 files changed

+345
-68
lines changed

app/components/inputs/ReceiveAccountsSelect.jsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import AccountsSelect from "./AccountsSelect";
33
import { useSelector, useDispatch } from "react-redux";
44
import * as ca from "actions/ControlActions";
55
import * as sel from "selectors";
6+
import { compose, get, eq } from "lodash/fp";
67

78
function ReceiveAccountsSelect({
89
onChange,
@@ -12,7 +13,16 @@ function ReceiveAccountsSelect({
1213
}) {
1314
const dispatch = useDispatch();
1415
const mixedAccount = useSelector(sel.getMixedAccount);
15-
const nextAddressAccount = useSelector(sel.nextAddressAccount);
16+
const getNextAddressResponse = useSelector(sel.getNextAddressResponse);
17+
const visibleAccounts = useSelector(sel.visibleAccounts);
18+
19+
const nextAddressAccountNumber = getNextAddressResponse
20+
? getNextAddressResponse.accountNumber
21+
: null;
22+
23+
const nextAddressAccount = visibleAccounts.find(
24+
compose(eq(nextAddressAccountNumber), get("value"))
25+
);
1626

1727
const getNextAddressAttempt = useCallback(
1828
(value) => dispatch(ca.getNextAddressAttempt(value)),

app/components/shared/SendTransaction/hooks.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as ca from "actions/ControlActions";
44
import { baseOutput } from "./helpers";
55
import { useSelector, useDispatch, shallowEqual } from "react-redux";
66
import { usePrevious } from "hooks";
7+
import { compose, get, eq } from "lodash/fp";
78

89
export function useSendTransaction() {
910
const defaultSpendingAccount = useSelector(
@@ -16,7 +17,16 @@ export function useSendTransaction() {
1617
const estimatedSignedSize = useSelector(sel.estimatedSignedSize);
1718
const totalSpent = useSelector(sel.totalSpent);
1819
const nextAddress = useSelector(sel.nextAddress);
19-
const nextAddressAccount = useSelector(sel.nextAddressAccount, shallowEqual);
20+
const getNextAddressResponse = useSelector(sel.getNextAddressResponse);
21+
const visibleAccounts = useSelector(sel.visibleAccounts);
22+
23+
const nextAddressAccountNumber = getNextAddressResponse
24+
? getNextAddressResponse.accountNumber
25+
: null;
26+
27+
const nextAddressAccount = visibleAccounts.find(
28+
compose(eq(nextAddressAccountNumber), get("value"))
29+
);
2030
const constructTxLowBalance = useSelector(sel.constructTxLowBalance);
2131
const publishTxResponse = useSelector(sel.publishTxResponse);
2232
const notMixedAccounts = useSelector(

app/selectors.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,10 @@ export const buyerAccount = createSelector(
717717
);
718718
export const buyerMaxFeePercentage = get(["vsp", "maxFeePercentage"]);
719719

720-
const getNextAddressResponse = get(["control", "getNextAddressResponse"]);
720+
export const getNextAddressResponse = get([
721+
"control",
722+
"getNextAddressResponse"
723+
]);
721724
const nextAddressAccountNumber = compose(
722725
(res) => (res ? res.accountNumber : null),
723726
getNextAddressResponse

test/unit/components/views/LNPage/ConnectPage.spec.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,16 @@ test("test create new new account", async () => {
163163
});
164164

165165
test("test text toggles", async () => {
166-
const { user } = render(<ConnectPage />);
166+
const { user } = render(<ConnectPage />, {
167+
initialState: {
168+
control: {
169+
getNextAddressResponse: {
170+
accountNumber: mockDefaultAccount.value
171+
}
172+
}
173+
}
174+
});
175+
167176
await goToCreateWalletView(user);
168177

169178
expect(screen.queryByText(/attention:/i)).not.toBeInTheDocument();
@@ -194,7 +203,16 @@ test("test automatic channel creation", async () => {
194203
});
195204

196205
test("test use existing account", async () => {
197-
const { user } = render(<ConnectPage />);
206+
const { user } = render(<ConnectPage />, {
207+
initialState: {
208+
control: {
209+
getNextAddressResponse: {
210+
accountNumber: mockDefaultAccount.value
211+
}
212+
}
213+
}
214+
});
215+
198216
await goToCreateWalletView(user);
199217

200218
expect(screen.queryByText(/attention:/i)).not.toBeInTheDocument();

test/unit/components/views/PrivacyPage/PrivacyTab.spec.js

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ const mockSpendingAccounts = [
6666
mockMixedAccount,
6767
mockUnMixedAccount
6868
];
69+
70+
const mockVisibleAccounts = [
71+
mockDefaultAccount,
72+
mockMixedAccount,
73+
mockUnMixedAccount
74+
];
6975
const mockCsppServer = "mockCsppServer.decred.org";
7076
const mockCsppPort = "1234";
7177
const mockMixedAccountBranch = 0;
@@ -83,6 +89,7 @@ let mockDispatchSingleMessage;
8389
beforeEach(() => {
8490
selectors.currencyDisplay = jest.fn(() => DCR);
8591
selectors.defaultSpendingAccount = jest.fn(() => mockMixedAccount);
92+
selectors.visibleAccounts = jest.fn(() => mockVisibleAccounts);
8693
selectors.getPrivacyEnabled = jest.fn(() => true);
8794
selectors.isWatchingOnly = jest.fn(() => false);
8895
selectors.getMixedAccountName = jest.fn(() => mockMixedAccount.name);
@@ -91,7 +98,6 @@ beforeEach(() => {
9198
selectors.walletService = jest.fn(() => {
9299
return {};
93100
});
94-
selectors.nextAddressAccount = jest.fn(() => mockUnMixedAccount);
95101
selectors.nextAddress = jest.fn(() => mockNextAddress);
96102
selectors.getRunningIndicator = jest.fn(() => false);
97103

@@ -235,7 +241,16 @@ test("test insufficient unmixed account balance error message", async () => {
235241
(acc) => acc.value == acctId
236242
)
237243
);
238-
render(<PrivacyTab />);
244+
render(<PrivacyTab />, {
245+
initialState: {
246+
control: {
247+
getNextAddressResponse: {
248+
accountNumber: mockUnMixedAccount.value
249+
}
250+
}
251+
}
252+
});
253+
239254
await waitFor(() =>
240255
expect(screen.getByText("Unmixed Balance").parentNode.className).toMatch(
241256
/balanceError/i
@@ -248,7 +263,16 @@ test("test insufficient unmixed account balance error message", async () => {
248263
});
249264

250265
test("start coin mixer", async () => {
251-
const { user } = render(<PrivacyTab />);
266+
const { user } = render(<PrivacyTab />, {
267+
initialState: {
268+
control: {
269+
getNextAddressResponse: {
270+
accountNumber: mockDefaultAccount.value
271+
}
272+
}
273+
}
274+
});
275+
252276
await waitFor(() =>
253277
expect(
254278
screen.getByText("Unmixed Balance").parentNode.className
@@ -289,7 +313,15 @@ test("start coin mixer", async () => {
289313

290314
test("stop coin mixer", async () => {
291315
selectors.getAccountMixerRunning = jest.fn(() => true);
292-
const { user } = render(<PrivacyTab />);
316+
const { user } = render(<PrivacyTab />, {
317+
initialState: {
318+
control: {
319+
getNextAddressResponse: {
320+
accountNumber: mockDefaultAccount.value
321+
}
322+
}
323+
}
324+
});
293325

294326
expect(screen.getByText("Mixer is running")).toBeInTheDocument();
295327
await user.click(getStopMixerButton());
@@ -299,14 +331,30 @@ test("stop coin mixer", async () => {
299331

300332
test("mixer is disabled (Autobuyer running)", () => {
301333
selectors.getRunningIndicator = jest.fn(() => true);
302-
render(<PrivacyTab />);
334+
render(<PrivacyTab />, {
335+
initialState: {
336+
control: {
337+
getNextAddressResponse: {
338+
accountNumber: mockDefaultAccount.value
339+
}
340+
}
341+
}
342+
});
303343

304344
expect(getSendToSelfButton().disabled).toBe(true);
305345
expect(getStartMixerButton().disabled).toBe(true);
306346
});
307347

308348
test("allow sending from unmixed accounts", async () => {
309-
const { user } = render(<PrivacyTab />);
349+
const { user } = render(<PrivacyTab />, {
350+
initialState: {
351+
control: {
352+
getNextAddressResponse: {
353+
accountNumber: mockDefaultAccount.value
354+
}
355+
}
356+
}
357+
});
310358

311359
const checkbox = getPrivacyCheckbox();
312360

@@ -333,7 +381,15 @@ test("allow sending from unmixed accounts", async () => {
333381

334382
test("sending from unmixed accounts is allowed already", async () => {
335383
selectors.getAllowSendFromUnmixed = jest.fn(() => true);
336-
const { user } = render(<PrivacyTab />);
384+
const { user } = render(<PrivacyTab />, {
385+
initialState: {
386+
control: {
387+
getNextAddressResponse: {
388+
accountNumber: mockDefaultAccount.value
389+
}
390+
}
391+
}
392+
});
337393

338394
const checkbox = getPrivacyCheckbox();
339395
expect(checkbox.checked).toBe(true);
@@ -343,7 +399,16 @@ test("sending from unmixed accounts is allowed already", async () => {
343399
});
344400

345401
test("Send to Unmixed Account form", async () => {
346-
const { user } = render(<PrivacyTab />);
402+
const { user } = render(<PrivacyTab />, {
403+
initialState: {
404+
control: {
405+
getNextAddressResponse: {
406+
accountNumber: mockDefaultAccount.value
407+
}
408+
}
409+
}
410+
});
411+
347412
const sendToSelfBtn = getSendToSelfButton();
348413
const amountInput = screen.getByLabelText("Amount:");
349414
const testAmount = "12";
@@ -372,7 +437,15 @@ test("check logs", async () => {
372437
mockGetPrivacyLogs = wallet.getPrivacyLogs = jest.fn(() =>
373438
Promise.resolve(mockLogLine)
374439
);
375-
const { user } = render(<PrivacyTab />);
440+
const { user } = render(<PrivacyTab />, {
441+
initialState: {
442+
control: {
443+
getNextAddressResponse: {
444+
accountNumber: mockDefaultAccount.value
445+
}
446+
}
447+
}
448+
});
376449

377450
const logsLabel = screen.getByText("Logs");
378451

test/unit/components/views/TransactionsPage/HistoryTab/HistoryTab.spec.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,6 @@ let mockWalletService;
1313
const selectors = sel;
1414
const transactionActions = ta;
1515

16-
const initialState = {
17-
grpc: {
18-
transactionsFilter: {
19-
search: null,
20-
listDirection: "desc",
21-
types: [],
22-
directions: [],
23-
maxAmount: null,
24-
minAmount: null
25-
},
26-
regularTransactions: {},
27-
getRegularTxsAux: {
28-
noMoreTransactions: false
29-
}
30-
}
31-
};
32-
3316
const getTestTxs = (startTs) => {
3417
const txList = {};
3518
const startDate = new Date(startTs * 1000);
@@ -103,6 +86,28 @@ const mockTotalSpent = 5600005850;
10386
const mockEstimatedFee = 5850;
10487
const mockEstimatedSize = 585;
10588

89+
const initialState = {
90+
grpc: {
91+
transactionsFilter: {
92+
search: null,
93+
listDirection: "desc",
94+
types: [],
95+
directions: [],
96+
maxAmount: null,
97+
minAmount: null
98+
},
99+
regularTransactions: {},
100+
getRegularTxsAux: {
101+
noMoreTransactions: false
102+
}
103+
},
104+
control: {
105+
getNextAddressResponse: {
106+
accountNumber: mockDefaultAccount.value
107+
}
108+
}
109+
};
110+
106111
beforeEach(() => {
107112
selectors.isTestNet = jest.fn(() => false);
108113
selectors.isMainNet = jest.fn(() => false);

0 commit comments

Comments
 (0)