Skip to content

Commit

Permalink
determine nextAddressAccount from getNextAddressResponse rather than …
Browse files Browse the repository at this point in the history
…from the selector.

Thus decreasing interference of the tests.
  • Loading branch information
bgptr committed Jul 2, 2023
1 parent 06519da commit 41db4aa
Show file tree
Hide file tree
Showing 8 changed files with 345 additions and 68 deletions.
12 changes: 11 additions & 1 deletion app/components/inputs/ReceiveAccountsSelect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import AccountsSelect from "./AccountsSelect";
import { useSelector, useDispatch } from "react-redux";
import * as ca from "actions/ControlActions";
import * as sel from "selectors";
import { compose, get, eq } from "lodash/fp";

function ReceiveAccountsSelect({
onChange,
Expand All @@ -12,7 +13,16 @@ function ReceiveAccountsSelect({
}) {
const dispatch = useDispatch();
const mixedAccount = useSelector(sel.getMixedAccount);
const nextAddressAccount = useSelector(sel.nextAddressAccount);
const getNextAddressResponse = useSelector(sel.getNextAddressResponse);
const visibleAccounts = useSelector(sel.visibleAccounts);

const nextAddressAccountNumber = getNextAddressResponse
? getNextAddressResponse.accountNumber
: null;

const nextAddressAccount = visibleAccounts.find(
compose(eq(nextAddressAccountNumber), get("value"))
);

const getNextAddressAttempt = useCallback(
(value) => dispatch(ca.getNextAddressAttempt(value)),
Expand Down
12 changes: 11 additions & 1 deletion app/components/shared/SendTransaction/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as ca from "actions/ControlActions";
import { baseOutput } from "./helpers";
import { useSelector, useDispatch, shallowEqual } from "react-redux";
import { usePrevious } from "hooks";
import { compose, get, eq } from "lodash/fp";

export function useSendTransaction() {
const defaultSpendingAccount = useSelector(
Expand All @@ -16,7 +17,16 @@ export function useSendTransaction() {
const estimatedSignedSize = useSelector(sel.estimatedSignedSize);
const totalSpent = useSelector(sel.totalSpent);
const nextAddress = useSelector(sel.nextAddress);
const nextAddressAccount = useSelector(sel.nextAddressAccount, shallowEqual);
const getNextAddressResponse = useSelector(sel.getNextAddressResponse);
const visibleAccounts = useSelector(sel.visibleAccounts);

const nextAddressAccountNumber = getNextAddressResponse
? getNextAddressResponse.accountNumber
: null;

const nextAddressAccount = visibleAccounts.find(
compose(eq(nextAddressAccountNumber), get("value"))
);
const constructTxLowBalance = useSelector(sel.constructTxLowBalance);
const publishTxResponse = useSelector(sel.publishTxResponse);
const notMixedAccounts = useSelector(
Expand Down
5 changes: 4 additions & 1 deletion app/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,10 @@ export const buyerAccount = createSelector(
);
export const buyerMaxFeePercentage = get(["vsp", "maxFeePercentage"]);

const getNextAddressResponse = get(["control", "getNextAddressResponse"]);
export const getNextAddressResponse = get([
"control",
"getNextAddressResponse"
]);
const nextAddressAccountNumber = compose(
(res) => (res ? res.accountNumber : null),
getNextAddressResponse
Expand Down
22 changes: 20 additions & 2 deletions test/unit/components/views/LNPage/ConnectPage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,16 @@ test("test create new new account", async () => {
});

test("test text toggles", async () => {
const { user } = render(<ConnectPage />);
const { user } = render(<ConnectPage />, {
initialState: {
control: {
getNextAddressResponse: {
accountNumber: mockDefaultAccount.value
}
}
}
});

await goToCreateWalletView(user);

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

test("test use existing account", async () => {
const { user } = render(<ConnectPage />);
const { user } = render(<ConnectPage />, {
initialState: {
control: {
getNextAddressResponse: {
accountNumber: mockDefaultAccount.value
}
}
}
});

await goToCreateWalletView(user);

expect(screen.queryByText(/attention:/i)).not.toBeInTheDocument();
Expand Down
91 changes: 82 additions & 9 deletions test/unit/components/views/PrivacyPage/PrivacyTab.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ const mockSpendingAccounts = [
mockMixedAccount,
mockUnMixedAccount
];

const mockVisibleAccounts = [
mockDefaultAccount,
mockMixedAccount,
mockUnMixedAccount
];
const mockCsppServer = "mockCsppServer.decred.org";
const mockCsppPort = "1234";
const mockMixedAccountBranch = 0;
Expand All @@ -83,6 +89,7 @@ let mockDispatchSingleMessage;
beforeEach(() => {
selectors.currencyDisplay = jest.fn(() => DCR);
selectors.defaultSpendingAccount = jest.fn(() => mockMixedAccount);
selectors.visibleAccounts = jest.fn(() => mockVisibleAccounts);
selectors.getPrivacyEnabled = jest.fn(() => true);
selectors.isWatchingOnly = jest.fn(() => false);
selectors.getMixedAccountName = jest.fn(() => mockMixedAccount.name);
Expand All @@ -91,7 +98,6 @@ beforeEach(() => {
selectors.walletService = jest.fn(() => {
return {};
});
selectors.nextAddressAccount = jest.fn(() => mockUnMixedAccount);
selectors.nextAddress = jest.fn(() => mockNextAddress);
selectors.getRunningIndicator = jest.fn(() => false);

Expand Down Expand Up @@ -235,7 +241,16 @@ test("test insufficient unmixed account balance error message", async () => {
(acc) => acc.value == acctId
)
);
render(<PrivacyTab />);
render(<PrivacyTab />, {
initialState: {
control: {
getNextAddressResponse: {
accountNumber: mockUnMixedAccount.value
}
}
}
});

await waitFor(() =>
expect(screen.getByText("Unmixed Balance").parentNode.className).toMatch(
/balanceError/i
Expand All @@ -248,7 +263,16 @@ test("test insufficient unmixed account balance error message", async () => {
});

test("start coin mixer", async () => {
const { user } = render(<PrivacyTab />);
const { user } = render(<PrivacyTab />, {
initialState: {
control: {
getNextAddressResponse: {
accountNumber: mockDefaultAccount.value
}
}
}
});

await waitFor(() =>
expect(
screen.getByText("Unmixed Balance").parentNode.className
Expand Down Expand Up @@ -289,7 +313,15 @@ test("start coin mixer", async () => {

test("stop coin mixer", async () => {
selectors.getAccountMixerRunning = jest.fn(() => true);
const { user } = render(<PrivacyTab />);
const { user } = render(<PrivacyTab />, {
initialState: {
control: {
getNextAddressResponse: {
accountNumber: mockDefaultAccount.value
}
}
}
});

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

test("mixer is disabled (Autobuyer running)", () => {
selectors.getRunningIndicator = jest.fn(() => true);
render(<PrivacyTab />);
render(<PrivacyTab />, {
initialState: {
control: {
getNextAddressResponse: {
accountNumber: mockDefaultAccount.value
}
}
}
});

expect(getSendToSelfButton().disabled).toBe(true);
expect(getStartMixerButton().disabled).toBe(true);
});

test("allow sending from unmixed accounts", async () => {
const { user } = render(<PrivacyTab />);
const { user } = render(<PrivacyTab />, {
initialState: {
control: {
getNextAddressResponse: {
accountNumber: mockDefaultAccount.value
}
}
}
});

const checkbox = getPrivacyCheckbox();

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

test("sending from unmixed accounts is allowed already", async () => {
selectors.getAllowSendFromUnmixed = jest.fn(() => true);
const { user } = render(<PrivacyTab />);
const { user } = render(<PrivacyTab />, {
initialState: {
control: {
getNextAddressResponse: {
accountNumber: mockDefaultAccount.value
}
}
}
});

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

test("Send to Unmixed Account form", async () => {
const { user } = render(<PrivacyTab />);
const { user } = render(<PrivacyTab />, {
initialState: {
control: {
getNextAddressResponse: {
accountNumber: mockDefaultAccount.value
}
}
}
});

const sendToSelfBtn = getSendToSelfButton();
const amountInput = screen.getByLabelText("Amount:");
const testAmount = "12";
Expand Down Expand Up @@ -372,7 +437,15 @@ test("check logs", async () => {
mockGetPrivacyLogs = wallet.getPrivacyLogs = jest.fn(() =>
Promise.resolve(mockLogLine)
);
const { user } = render(<PrivacyTab />);
const { user } = render(<PrivacyTab />, {
initialState: {
control: {
getNextAddressResponse: {
accountNumber: mockDefaultAccount.value
}
}
}
});

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,6 @@ let mockWalletService;
const selectors = sel;
const transactionActions = ta;

const initialState = {
grpc: {
transactionsFilter: {
search: null,
listDirection: "desc",
types: [],
directions: [],
maxAmount: null,
minAmount: null
},
regularTransactions: {},
getRegularTxsAux: {
noMoreTransactions: false
}
}
};

const getTestTxs = (startTs) => {
const txList = {};
const startDate = new Date(startTs * 1000);
Expand Down Expand Up @@ -103,6 +86,28 @@ const mockTotalSpent = 5600005850;
const mockEstimatedFee = 5850;
const mockEstimatedSize = 585;

const initialState = {
grpc: {
transactionsFilter: {
search: null,
listDirection: "desc",
types: [],
directions: [],
maxAmount: null,
minAmount: null
},
regularTransactions: {},
getRegularTxsAux: {
noMoreTransactions: false
}
},
control: {
getNextAddressResponse: {
accountNumber: mockDefaultAccount.value
}
}
};

beforeEach(() => {
selectors.isTestNet = jest.fn(() => false);
selectors.isMainNet = jest.fn(() => false);
Expand Down
Loading

0 comments on commit 41db4aa

Please sign in to comment.