Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Start adding tests for payments panel
Browse files Browse the repository at this point in the history
address #3249

Auditors: @bbondy
  • Loading branch information
diracdeltas committed Sep 1, 2016
1 parent d51c09b commit 980e664
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1118,8 +1118,11 @@ const pathSuffix = { development: '-dev', test: '-test' }[process.env.NODE_ENV]

var pathName = (name) => {
var parts = path.parse(name)
var basePath = process.env.NODE_ENV === 'test'
? path.join(process.env.HOME, '.brave-test-ledger')
: app.getPath('userData')

return path.join(app.getPath('userData'), parts.name + pathSuffix + parts.ext)
return path.join(basePath, parts.name + pathSuffix + parts.ext)

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas Sep 1, 2016

Author Member

@mrose17 heads up on this change. i don't think tests can know where the the userData directory is, so test state files are in ~/.brave-test-ledger

This comment has been minimized.

Copy link
@mrose17

mrose17 via email Sep 1, 2016

Member
}

/**
Expand Down
2 changes: 1 addition & 1 deletion js/about/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ class PaymentsTab extends ImmutableComponent {
</SettingItem>
</SettingsList>
</td>
<td data-l10n-id={this.walletStatus.id}
<td id='walletStatus' data-l10n-id={this.walletStatus.id}
data-l10n-args={this.walletStatus.args ? JSON.stringify(this.walletStatus.args) : null} />
</tr>
</tbody>
Expand Down
88 changes: 88 additions & 0 deletions test/components/ledgerPanelTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/* global describe, it, beforeEach */

const Brave = require('../lib/brave')
const {urlInput, addFundsButton, paymentsStatus, paymentsWelcomePage, paymentsTab, walletSwitch} = require('../lib/selectors')
const assert = require('assert')

const prefsUrl = 'about:preferences'

describe('Payments Panel', function () {
function * setup (client) {
yield client
.waitUntilWindowLoaded()
.waitForUrl(Brave.newTabUrl)
.waitForBrowserWindow()
.waitForVisible('#window')
.waitForVisible(urlInput)
}

describe('can setup payments', function () {
Brave.beforeEach(this)
beforeEach(function * () {
yield setup(this.app.client)
})

it('shows welcome page', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(prefsUrl)
.waitForVisible(paymentsTab)
.click(paymentsTab)
.waitForVisible(paymentsWelcomePage)
let background = yield this.app.client.getCssProperty(walletSwitch, 'background-color')
assert.equal(background.value, 'rgba(211,211,211,1)')
})

it('payments can be enabled', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(prefsUrl)
.waitForVisible(paymentsTab)
.click(paymentsTab)
.waitForVisible(paymentsWelcomePage)
.click(walletSwitch)
.windowByUrl(Brave.browserWindowUrl)
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.settings['payments.enabled'] === true &&
val.value.settings['payments.notifications'] === true
})
})
})

it('payments can be disabled', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(prefsUrl)
.waitForVisible(paymentsTab)
.click(paymentsTab)
.waitForVisible(paymentsWelcomePage)
.click(walletSwitch)
.click(walletSwitch)
.windowByUrl(Brave.browserWindowUrl)
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.settings['payments.enabled'] === false &&
val.value.settings['payments.notifications'] === false
})
})
})

it('can create wallet', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(prefsUrl)
.waitForVisible(paymentsTab)
.click(paymentsTab)
.waitForVisible(paymentsWelcomePage)
.click(walletSwitch)
.waitUntil(function () {
return this.getText(paymentsStatus).then((val) => val.includes('get started'))
})
.click(addFundsButton)
.waitUntil(function () {
return this.getText(paymentsStatus).then((val) => val.includes('Creating'))
})
})
})
})
12 changes: 12 additions & 0 deletions test/lib/brave.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,22 @@ var exports = {

startApp: function (cleanSessionStore = true) {
if (cleanSessionStore) {
let ledgerDir = path.join(process.env.HOME, '.brave-test-ledger')
try {
fs.unlinkSync(path.join(process.env.HOME, '.brave-test-session-store-1'))
} catch (e) {
}
try {
['publisher', 'state', 'scores', 'synopsis'].forEach((name) => {
try {
fs.unlinkSync(path.join(ledgerDir, `ledger-${name}-test.json`))
} catch (e) {
}
})
} catch (e) {
// probably ledgerDir does not exist yet
fs.mkdirSync(ledgerDir)
}
}
this.app = new Application({
path: './node_modules/.bin/electron',
Expand Down
12 changes: 12 additions & 0 deletions test/lib/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,20 @@ module.exports = {
clearBrowsingDataPanel: '.clearBrowsingDataPanel',
clearBrowsingDataButton: '.clearBrowsingDataButton',
securityTab: '[data-l10n-id="security"]',
paymentsTab: '[data-l10n-id="payments"]',
saveButton: '[data-l10n-id="save"]',
walletSwitch: '.enablePaymentsSwitch .switchBackground',
addFundsButton: '.addFunds',
fundsSelectBox: '#fundsSelectBox',
paymentsStatus: '#walletStatus',
ledgerTable: '.ledgerTable',
bitcoinDashboard: '#bitcoinDashboard',
modalCloseButton: 'button.close',
coinbaseBuyButton: '[data-l10n-id="add"]',
paymentQRCode: '[title="Brave wallet QR code"]',
deleteButton: '[data-l10n-id="delete"]',
paymentHistoryButton: '.paymentHistoryButton',
paymentsWelcomePage: '.paymentsMessage',
autofillAddressPanel: '.autofillAddressPanel',
autofillCreditCardPanel: '.autofillCreditCardPanel'
}

0 comments on commit 980e664

Please sign in to comment.