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

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdh committed Aug 24, 2016
1 parent 5dc58e6 commit ec95567
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 9 deletions.
4 changes: 2 additions & 2 deletions js/about/autofill.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ class AboutAutofill extends React.Component {
<h2 data-l10n-id='addresses' />
<div className='autofillPageContent'>
{savedAddresssPage}
<Button l10nId='addAddress' className='primaryButton' onClick={this.onAddAddress} />
<Button l10nId='addAddress' className='primaryButton addAddressButton' onClick={this.onAddAddress} />
</div>
<div className='autofillPageFooter'></div>
<h2 data-l10n-id='creditCards' />
<div className='autofillPageContent'>
{savedCreditCardsPage}
<Button l10nId='addCreditCard' className='primaryButton' onClick={this.onAddCreditCard} />
<Button l10nId='addCreditCard' className='primaryButton addCreditCardButton' onClick={this.onAddCreditCard} />
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions js/components/autofillAddressPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class AutofillAddressPanel extends ImmutableComponent {
e.stopPropagation()
}
render () {
return <Dialog onHide={this.props.onHide} className='manageAutofillDataPanel' isClickDismiss>
return <Dialog onHide={this.props.onHide} className='manageAutofillDataPanel autofillAddressPanel' isClickDismiss>
<div className='genericForm manageAutofillData' onClick={this.onClick}>
<div className='formRow manageAutofillDataTitle' data-l10n-id='editAddress' />
<div className='genericFormTable'>
Expand Down Expand Up @@ -141,7 +141,7 @@ class AutofillAddressPanel extends ImmutableComponent {
</div>
<div className='formRow'>
<Button l10nId='cancel' className='secondaryAltButton' onClick={this.props.onHide} />
<Button l10nId='save' className='primaryButton' onClick={this.onSave} />
<Button l10nId='save' className='primaryButton saveAddressButton' onClick={this.onSave} />
</div>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions js/components/autofillCreditCardPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class AutofillCreditCardPanel extends ImmutableComponent {
ExpYear.push(<option value={i}>{i}</option>)
}

return <Dialog onHide={this.props.onHide} className='manageAutofillDataPanel' isClickDismiss>
return <Dialog onHide={this.props.onHide} className='manageAutofillDataPanel autofillCreditCardPanel' isClickDismiss>
<div className='genericForm manageAutofillData' onClick={this.onClick}>
<div className='formRow manageAutofillDataTitle' data-l10n-id='editCreditCard' />
<div className='genericFormTable'>
Expand All @@ -90,17 +90,17 @@ class AutofillCreditCardPanel extends ImmutableComponent {
<div id='expirationDate' className='formRow'>
<label data-l10n-id='expirationDate' htmlFor='expirationDate' />
<select value={this.displayMonth}
onChange={this.onExpMonthChange} className='formSelect' >
onChange={this.onExpMonthChange} className='formSelect expMonthSelect' >
{ExpMonth}
</select>
<select value={this.props.currentDetail.get('year')}
onChange={this.onExpYearChange} className='formSelect' >
onChange={this.onExpYearChange} className='formSelect expYearSelect' >
{ExpYear}
</select>
</div>
<div className='formRow'>
<Button l10nId='cancel' className='secondaryAltButton' onClick={this.props.onHide} />
<Button l10nId='save' className='primaryButton' onClick={this.onSave} />
<Button l10nId='save' className='primaryButton saveCreditCardButton' onClick={this.onSave} />
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions js/contextMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ function autofillTemplateInit (suggestions, frame) {
for (let i = 0; i < suggestions.length; ++i) {
let value
let frontendId = suggestions[i].frontend_id
console.log(frontendId)
if (frontendId >= 0) { // POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY and Autofill Entry
value = suggestions[i].value
} else if (frontendId === -1) { // POPUP_ITEM_ID_WARNING_MESSAGE
Expand Down
256 changes: 256 additions & 0 deletions test/components/autofillTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
/* global describe, it, before */

const Brave = require('../lib/brave')
const {urlInput, autofillAddressPanel, autofillCreditCardPanel} = require('../lib/selectors')
const {getTargetAboutUrl} = require('../../js/lib/appUrlUtil')

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

describe('Data Management', function () {
Brave.beforeAll(this)
before(function * () {
yield setup(this.app.client)
})
const page1Url = 'about:autofill'
const addAddressButton = '.addAddressButton'
const saveAddressButton = '.saveAddressButton'
const name = 'Brave Lion'
const organization = 'Brave'
const streetAddress = '1161 Mission Street, #401'
const city = 'San Francisco'
const state = 'CA'
const postalCode = '94103-1550'
const country = 'US'
const phone = '0987654321'
const email = '[email protected]'
it('Adding Address', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(page1Url)
.url(getTargetAboutUrl(page1Url))
.waitForVisible(addAddressButton)
.click(addAddressButton)
.windowByUrl(Brave.browserWindowUrl)
.waitForVisible(autofillAddressPanel)
.click('#nameOnAddress')
.keys(name)
.click('#organization')
.keys(organization)
.click('#streetAddress')
.keys(streetAddress)
.click('#city')
.keys(city)
.click('#state')
.keys(state)
.click('#postalCode')
.keys(postalCode)
.click('#country')
.keys(country)
.click('#phone')
.keys(phone)
.click('#email')
.keys(email)
.click(saveAddressButton)
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.autofill.addresses.length === 1
})
})
.tabByUrl(this.page1Url)
.waitForVisible('.autofillPage')
.getText('.addressName').should.eventually.be.equal(name)
.getText('.organization').should.eventually.be.equal(organization)
.getText('.streetAddress').should.eventually.be.equal(streetAddress)
.getText('.city').should.eventually.be.equal(city)
.getText('.state').should.eventually.be.equal(state)
.getText('.postalCode').should.eventually.be.equal(postalCode)
.getText('.country').should.eventually.be.equal(country)
.getText('.phone').should.eventually.be.equal(phone)
.getText('.email').should.eventually.be.equal(email)
})
it('Address form test', function * () {
const page1Url = 'https://www.roboform.com/filling-test-all-fields'
yield this.app.client
.tabByIndex(0)
.loadUrl(page1Url)
.url(getTargetAboutUrl(page1Url))
.waitForVisible('<form>')
.click('[name="04fullname"]')
.click('[name="04fullname"]')
.windowByUrl(Brave.browserWindowUrl)
.ipcSendRenderer('autofill-selection-clicked', 2, name, 1, 0)
.setContextMenuDetail()
.tabByUrl(this.page1Url)
.getValue('[name="04fullname"]').should.eventually.be.equal(name)
})
it('Editing Address', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(page1Url)
.url(getTargetAboutUrl(page1Url))
.waitForVisible('[title="Edit address"]')
.click('[title="Edit address"]')
.windowByUrl(Brave.browserWindowUrl)
.waitForVisible(autofillAddressPanel)
.click('#phone')
.keys('123')
.click('#email')
.keys('mm')
.click(saveAddressButton)
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.autofill.addresses.length === 1
})
})
.tabByUrl(this.page1Url)
.waitForVisible('.autofillPage')
.getText('.addressName').should.eventually.be.equal(name)
.getText('.organization').should.eventually.be.equal(organization)
.getText('.streetAddress').should.eventually.be.equal(streetAddress)
.getText('.city').should.eventually.be.equal(city)
.getText('.state').should.eventually.be.equal(state)
.getText('.postalCode').should.eventually.be.equal(postalCode)
.getText('.country').should.eventually.be.equal(country)
.getText('.phone').should.eventually.be.equal(phone + '123')
.getText('.email').should.eventually.be.equal(email + 'mm')
})
it('Edited Address form test', function * () {
const page1Url = 'https://www.roboform.com/filling-test-all-fields'
yield this.app.client
.tabByIndex(0)
.loadUrl(page1Url)
.url(getTargetAboutUrl(page1Url))
.waitForVisible('<form>')
.click('[name="04fullname"]')
.click('[name="04fullname"]')
.windowByUrl(Brave.browserWindowUrl)
.ipcSendRenderer('autofill-selection-clicked', 2, name, 1, 0)
.setContextMenuDetail()
.tabByUrl(this.page1Url)
.getValue('[name="04fullname"]').should.eventually.be.equal(name)
.getValue('[name="23cellphon"]').should.eventually.be.equal(phone + '123')
.getValue('[name="24emailadr"]').should.eventually.be.equal(email + 'mm')
})
it('Deleting Address', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(page1Url)
.url(getTargetAboutUrl(page1Url))
.waitForVisible('[title="Delete address"]')
.click('[title="Delete address"]')
.waitForVisible('[data-l10n-id=noAddressesSaved]')
})
const addCreditCardButton = '.addCreditCardButton'
const saveCreditCardButton = '.saveCreditCardButton'
const cardName = 'Test Card'
const cardNumber = '1234567890'
const expMonth = 10
const expYear = new Date().getFullYear() + 2
it('Adding Credit Card', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(page1Url)
.url(getTargetAboutUrl(page1Url))
.waitForVisible(addCreditCardButton)
.click(addCreditCardButton)
.windowByUrl(Brave.browserWindowUrl)
.waitForVisible(autofillCreditCardPanel)
.click('#nameOnCard')
.keys(cardName)
.click('#creditCardNumber')
.keys(cardNumber)
.selectByValue('.expMonthSelect', expMonth.toString())
.selectByValue('.expYearSelect', expYear.toString())
.click(saveCreditCardButton)
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.autofill.creditCards.length === 1
})
})
.tabByUrl(this.page1Url)
.waitForVisible('.autofillPage')
.getText('.creditCardName').should.eventually.be.equal(cardName)
.getText('.creditCardNumber').should.eventually.be.equal('***' + cardNumber.slice(-4))
.getText('.creditCardPExpirationDate').should.eventually.be.equal(expMonth.toString() + '/' + expYear.toString())
})
it('Credit Card form test', function * () {
const page1Url = 'https://www.roboform.com/filling-test-all-fields'
yield this.app.client
.tabByIndex(0)
.loadUrl(page1Url)
.url(getTargetAboutUrl(page1Url))
.waitForVisible('<form>')
.click('[name="41ccnumber"]')
.click('[name="41ccnumber"]')
.windowByUrl(Brave.browserWindowUrl)
.ipcSendRenderer('autofill-selection-clicked', 2, cardNumber, 65536, 0)
.setContextMenuDetail()
.tabByUrl(this.page1Url)
.getValue('[name="41ccnumber"]').should.eventually.be.equal(cardNumber)
.getValue('[name="42ccexp_mm"]').should.eventually.be.equal(expMonth.toString())
.getValue('[name="43ccexp_yy"]').should.eventually.be.equal(expYear.toString())
})
it('Editing Credit Card', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(page1Url)
.url(getTargetAboutUrl(page1Url))
.waitForVisible('[title="Edit creditCard"]')
.click('[title="Edit creditCard"]')
.windowByUrl(Brave.browserWindowUrl)
.waitForVisible(autofillCreditCardPanel)
.click('#nameOnCard')
.keys('123')
.click('#creditCardNumber')
.keys('123')
.selectByValue('.expMonthSelect', (expMonth + 1).toString())
.selectByValue('.expYearSelect', (expYear + 1).toString())
.click(saveCreditCardButton)
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.autofill.creditCards.length === 1
})
})
.tabByUrl(this.page1Url)
.waitForVisible('.autofillPage')
.getText('.creditCardName').should.eventually.be.equal(cardName + 123)
.getText('.creditCardNumber').should.eventually.be.equal('***' + (cardNumber + 123).slice(-4))
.getText('.creditCardPExpirationDate').should.eventually.be.equal(
(expMonth + 1).toString() + '/' + (expYear + 1).toString())
})
it('Edited Credit Card form test', function * () {
const page1Url = 'https://www.roboform.com/filling-test-all-fields'
yield this.app.client
.tabByIndex(0)
.loadUrl(page1Url)
.url(getTargetAboutUrl(page1Url))
.waitForVisible('<form>')
.click('[name="41ccnumber"]')
.click('[name="41ccnumber"]')
.windowByUrl(Brave.browserWindowUrl)
.ipcSendRenderer('autofill-selection-clicked', 2, cardNumber, 65536, 0)
.setContextMenuDetail()
.tabByUrl(this.page1Url)
.getValue('[name="41ccnumber"]').should.eventually.be.equal(cardNumber + '123')
.getValue('[name="42ccexp_mm"]').should.eventually.be.equal((expMonth + 1).toString())
.getValue('[name="43ccexp_yy"]').should.eventually.be.equal((expYear + 1).toString())
})
it('Deleting Credit Card', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(page1Url)
.url(getTargetAboutUrl(page1Url))
.waitForVisible('[title="Delete creditCard"]')
.click('[title="Delete creditCard"]')
.waitForVisible('[data-l10n-id=noCreditCardsSaved]')
})
})
})
12 changes: 12 additions & 0 deletions test/lib/brave.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ var exports = {
}, message, ...param).then((response) => response.value)
})

this.app.client.addCommand('ipcSendRenderer', function (message, ...param) {
return this.execute(function (message, ...param) {
return require('electron').ipcRenderer.send(message, ...param)
}, message, ...param).then((response) => response.value)
})

var windowHandlesOrig = this.app.client.windowHandles
Object.getPrototypeOf(this.app.client).windowHandles = function () {
return windowHandlesOrig.apply(this)
Expand Down Expand Up @@ -196,6 +202,12 @@ var exports = {
})
})

this.app.client.addCommand('setContextMenuDetail', function () {
return this.execute(function () {
return window.windowActions.setContextMenuDetail()
})
})

this.app.client.addCommand('showFindbar', function (show) {
return this.execute(function (show) {
window.windowActions.setFindbarShown(Object.assign({
Expand Down
5 changes: 4 additions & 1 deletion test/lib/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@ module.exports = {
clearBrowsingDataPanel: '.clearBrowsingDataPanel',
clearBrowsingDataButton: '.clearBrowsingDataButton',
saveButton: '[data-l10n-id="save"]',
securityTab: '[data-l10n-id="security"]'
securityTab: '[data-l10n-id="security"]',
saveButton: '[data-l10n-id="save"]',
autofillAddressPanel: '.autofillAddressPanel',
autofillCreditCardPanel: '.autofillCreditCardPanel'
}

0 comments on commit ec95567

Please sign in to comment.