Skip to content

Commit

Permalink
Add browser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emerick committed Jul 1, 2020
1 parent d272b1e commit 5b481bd
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ void RewardsBrowserTestResponse::LoadMocks() {
path.AppendASCII("balance_resp.json"),
&balance_));

ASSERT_TRUE(base::ReadFileToString(
path.AppendASCII("user_funds_balance_resp.json"),
&user_funds_balance_resp_));

ASSERT_TRUE(base::ReadFileToString(
path.AppendASCII("uphold_auth_resp.json"),
&uphold_auth_resp_));
Expand Down Expand Up @@ -123,7 +127,11 @@ void RewardsBrowserTestResponse::Get(
"/wallet/",
PREFIX_V2,
ServerTypes::BALANCE)) {
*response = balance_;
if (user_funds_balance_) {
*response = user_funds_balance_resp_;
} else {
*response = balance_;
}
return;
}

Expand Down Expand Up @@ -301,4 +309,8 @@ void RewardsBrowserTestResponse::SetExternalBalance(
external_balance_ = balance;
}

void RewardsBrowserTestResponse::SetUserFundsBalance(const bool user_funds) {
user_funds_balance_ = user_funds;
}

} // namespace rewards_browsertest
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class RewardsBrowserTestResponse {

void SetExternalBalance(const std::string& balance);

void SetUserFundsBalance(const bool user_funds);

private:
std::string registrar_vk_;
std::string verification_;
Expand All @@ -65,13 +67,15 @@ class RewardsBrowserTestResponse {
std::string uphold_auth_resp_;
std::string uphold_transactions_resp_;
std::string uphold_commit_resp_;
std::string user_funds_balance_resp_;

std::vector<Request> requests_;
bool empty_promotion_key_ = false;
bool alternative_publisher_list_ = false;
ledger::SKUOrderPtr order_;
bool verified_wallet_ = false;
std::string external_balance_ = "0.0";
bool user_funds_balance_ = false;
};

} // namespace rewards_browsertest
Expand Down
53 changes: 52 additions & 1 deletion components/brave_rewards/browser/test/rewards_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "brave/components/brave_rewards/browser/test/common/rewards_browsertest_context_util.h"
#include "brave/components/brave_rewards/browser/test/common/rewards_browsertest_contribution.h"
#include "brave/components/brave_rewards/browser/test/common/rewards_browsertest_network_util.h"
#include "brave/components/brave_rewards/browser/test/common/rewards_browsertest_promotion.h"
#include "brave/components/brave_rewards/browser/test/common/rewards_browsertest_response.h"
#include "brave/components/brave_rewards/browser/test/common/rewards_browsertest_util.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
Expand All @@ -33,6 +34,7 @@ class RewardsBrowserTest : public InProcessBrowserTest {
RewardsBrowserTest() {
response_ = std::make_unique<RewardsBrowserTestResponse>();
contribution_ = std::make_unique<RewardsBrowserTestContribution>();
promotion_ = std::make_unique<RewardsBrowserTestPromotion>();
}

void SetUpOnMainThread() override {
Expand Down Expand Up @@ -64,6 +66,7 @@ class RewardsBrowserTest : public InProcessBrowserTest {

// Other
contribution_->Initialize(browser(), rewards_service_);
promotion_->Initialize(browser(), rewards_service_);
}

void TearDown() override {
Expand Down Expand Up @@ -102,8 +105,9 @@ class RewardsBrowserTest : public InProcessBrowserTest {

brave_rewards::RewardsServiceImpl* rewards_service_;
std::unique_ptr<net::EmbeddedTestServer> https_server_;
std::unique_ptr<RewardsBrowserTestContribution> contribution_;
std::unique_ptr<RewardsBrowserTestResponse> response_;
std::unique_ptr<RewardsBrowserTestContribution> contribution_;
std::unique_ptr<RewardsBrowserTestPromotion> promotion_;
};

IN_PROC_BROWSER_TEST_F(RewardsBrowserTest, RenderWelcome) {
Expand Down Expand Up @@ -357,4 +361,51 @@ IN_PROC_BROWSER_TEST_F(RewardsBrowserTest, ZeroBalanceWalletClaimNotCalled) {
run_loop.Run();
}

IN_PROC_BROWSER_TEST_F(RewardsBrowserTest, BackupRestoreModalHasNotice) {
rewards_browsertest_helper::EnableRewards(browser());
contribution_->AddBalance(promotion_->ClaimPromotionViaCode());

rewards_browsertest_util::WaitForElementToEqual(
contents(),
"[data-test-id='balance']",
"30.000 BAT");

// Click the settings button and wait for the backup modal to appear
rewards_browsertest_util::WaitForElementThenClick(
contents(),
"[data-test-id='settingsButton']");
rewards_browsertest_util::WaitForElementToAppear(
contents(),
"#modal");

// Ensure that verify link exists
rewards_browsertest_util::WaitForElementToAppear(
contents(),
"#backup-verify-link");
}

IN_PROC_BROWSER_TEST_F(RewardsBrowserTest, BackupRestoreModalHasNoNotice) {
response_->SetUserFundsBalance(true);
rewards_browsertest_helper::EnableRewards(browser());

rewards_browsertest_util::WaitForElementToEqual(
contents(),
"[data-test-id='balance']",
"20.000 BAT");

// Click the settings button and wait for the backup modal to appear
rewards_browsertest_util::WaitForElementThenClick(
contents(),
"[data-test-id='settingsButton']");
rewards_browsertest_util::WaitForElementToAppear(
contents(),
"#modal");

// Presence of recovery key textarea indicates notice isn't
// displayed
rewards_browsertest_util::WaitForElementToAppear(
contents(),
"#backup-recovery-key");
}

} // namespace rewards_browsertest
17 changes: 7 additions & 10 deletions components/brave_rewards/resources/page/components/pageWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const clipboardCopy = require('clipboard-copy')
interface State {
activeTabId: number
modalBackup: boolean
showBackupNotice: boolean
modalActivity: boolean
modalPendingContribution: boolean
modalVerify: boolean
Expand All @@ -47,7 +46,6 @@ class PageWallet extends React.Component<Props, State> {
this.state = {
activeTabId: 0,
modalBackup: false,
showBackupNotice: !this.hasUserFunds(),
modalActivity: false,
modalPendingContribution: false,
modalVerify: false
Expand All @@ -60,7 +58,7 @@ class PageWallet extends React.Component<Props, State> {

hasUserFunds () {
const { balance } = this.props.rewardsData
return balance.wallets['anonymous'] > 0
return balance && balance.wallets['anonymous'] > 0
}

componentDidMount () {
Expand All @@ -84,15 +82,14 @@ class PageWallet extends React.Component<Props, State> {
this.actions.onModalBackupOpen()
}

showBackupNotice = () => {
return this.state.activeTabId === 0 && !this.hasUserFunds()
}

onModalBackupTabChange = () => {
const newTabId = this.state.activeTabId === 0 ? 1 : 0
let showBackupNotice = false
if (newTabId === 0 && !this.hasUserFunds()) {
showBackupNotice = true
}
this.setState({
activeTabId: newTabId,
showBackupNotice: showBackupNotice
activeTabId: newTabId
})
}

Expand Down Expand Up @@ -805,7 +802,7 @@ class PageWallet extends React.Component<Props, State> {
? <ModalBackupRestore
activeTabId={this.state.activeTabId}
backupKey={recoveryKey}
showBackupNotice={this.state.showBackupNotice}
showBackupNotice={this.showBackupNotice()}
onTabChange={this.onModalBackupTabChange}
onClose={this.onModalBackupClose}
onCopy={this.onModalBackupOnCopy}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export default class ModalBackupRestore extends React.PureComponent<Props, State
</StyledContent>
<ControlWrapper text={getLocale('recoveryKeys')}>
<TextArea
id={'backup-recovery-key'}
value={backupKey}
disabled={true}
/>
Expand Down Expand Up @@ -202,7 +203,7 @@ export default class ModalBackupRestore extends React.PureComponent<Props, State
</StyledContent>
<StyledContent>
{getLocale('rewardsBackupNoticeText2')}
<StyledLink onClick={onVerify}>
<StyledLink onClick={onVerify} id={'backup-verify-link'}>
{getLocale('rewardsBackupNoticeText3')}
</StyledLink>
</StyledContent>
Expand Down Expand Up @@ -260,6 +261,7 @@ export default class ModalBackupRestore extends React.PureComponent<Props, State
}
>
<TextArea
id={'backup-recovery-key'}
fieldError={!!errorShown}
value={this.state.recoveryKey}
onChange={this.setRecoveryKey}
Expand Down
33 changes: 33 additions & 0 deletions test/data/rewards-data/user_funds_balance_resp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"altcurrency": "BAT",
"probi": "0",
"balance": "20.0000",
"cardBalance": "20.0",
"probi": "20000000000000000000",
"unconfirmed": "0.0000",
"parameters": {
"adFree": {
"currency": "BAT",
"fee": {
"BAT": 0
},
"choices": {
"BAT": [
10,
15,
20,
30,
50,
100
]
},
"range": {
"BAT": [
10,
100
]
},
"days": 30
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ void Create::RegisterPersonaCallback(
ledger_->SetAutoContributeEnabled(true);
braveledger_state::SetPaymentId(ledger_, payment_id);
braveledger_state::SetAnonymousCardId(ledger_, card_id);
braveledger_state::SetFetchOldBalanceEnabled(ledger_, false);
if (!ledger::is_testing) {
braveledger_state::SetFetchOldBalanceEnabled(ledger_, false);
}
ledger_->SetCreationStamp(braveledger_time_util::GetCurrentTimeStamp());
ledger_->ResetReconcileStamp();
braveledger_state::SetInlineTippingPlatformEnabled(
Expand Down

0 comments on commit 5b481bd

Please sign in to comment.