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

Commit

Permalink
Refactor clearBrowsingDataPanel.js with commonForm
Browse files Browse the repository at this point in the history
Closes #8192
Addresses #7989

- Added CommonFormSmall to commonForm.js
- Added data-test-id and testIds
- Removed clearBrowsingDataPanel from forms.less
- Updated test code

Auditors:

Test Plan:
1. Open Clear browsing data panel from the menu
2. Test the cancel button works
3. Reopen the panel
4. Test the clear button works
  • Loading branch information
Suguru Hirahara committed Apr 23, 2017
1 parent f578f23 commit bbf1457
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 94 deletions.
15 changes: 15 additions & 0 deletions app/renderer/components/commonForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ class CommonFormMedium extends ImmutableComponent {
}
}

class CommonFormSmall extends ImmutableComponent {
render () {
return <div className={css(
commonStyles.flyoutDialog,
styles.commonForm,
styles.commonFormSmall
)} {...this.props} />
}
}

class CommonFormLarge extends ImmutableComponent {
render () {
return <div className={css(
Expand Down Expand Up @@ -133,6 +143,10 @@ const styles = StyleSheet.create({
// maxHeight: '100%'
},

commonFormSmall: {
maxWidth: globalStyles.spacing.dialogSmallWidth
},

commonFormMedium: {
maxWidth: globalStyles.spacing.dialogMediumWidth
},
Expand Down Expand Up @@ -208,6 +222,7 @@ const commonFormStyles = StyleSheet.create({

module.exports = {
CommonForm,
CommonFormSmall,
CommonFormMedium,
CommonFormLarge,
CommonFormBookmarkHanger,
Expand Down
1 change: 1 addition & 0 deletions app/renderer/components/styles/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ const globalStyles = {
closeIconSize: '13px',
narrowIconSize: '12px',
dialogWidth: '422px',
dialogSmallWidth: '350px',
dialogMediumWidth: '500px',
dialogLargeWidth: '600px',
dialogTopOffset: '30px',
Expand Down
6 changes: 5 additions & 1 deletion js/about/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ class AboutHistory extends React.Component {
: <span className='fa fa-search searchInputPlaceholder' />
}
</div>
<Button l10nId='clearBrowsingDataNow' className='primaryButton clearBrowsingDataButton' onClick={this.clearBrowsingDataNow} />
<Button className='primaryButton'
l10nId='clearBrowsingDataNow'
testId='clearBrowsingDataButton'
onClick={this.clearBrowsingDataNow}
/>
</div>
</div>

Expand Down
6 changes: 5 additions & 1 deletion js/about/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,11 @@ class SecurityTab extends ImmutableComponent {
<SettingCheckbox dataL10nId='autocompleteData' prefKey={settings.SHUTDOWN_CLEAR_AUTOCOMPLETE_DATA} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingCheckbox dataL10nId='autofillData' prefKey={settings.SHUTDOWN_CLEAR_AUTOFILL_DATA} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingCheckbox dataL10nId='savedSiteSettings' prefKey={settings.SHUTDOWN_CLEAR_SITE_SETTINGS} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<Button l10nId='clearBrowsingDataNow' className='primaryButton clearBrowsingDataButton' onClick={this.clearBrowsingDataNow} />
<Button className='primaryButton'
l10nId='clearBrowsingDataNow'
testId='clearBrowsingDataButton'
onClick={this.clearBrowsingDataNow}
/>
</SettingsList>
<DefaultSectionTitle data-l10n-id='passwordsAndForms' />
<SettingsList>
Expand Down
84 changes: 64 additions & 20 deletions js/components/clearBrowsingDataPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ const appActions = require('../actions/appActions')
const ipc = require('electron').ipcRenderer
const messages = require('../constants/messages')

const {
CommonFormSmall,
CommonFormSection,
CommonFormTitle,
CommonFormButtonWrapper,
CommonFormBottomWrapper
} = require('../../app/renderer/components/commonForm')

class ClearBrowsingDataPanel extends React.Component {
constructor (props) {
super()
Expand Down Expand Up @@ -42,27 +50,63 @@ class ClearBrowsingDataPanel extends React.Component {
}
}
render () {
return <Dialog onHide={this.props.onHide} className='clearBrowsingDataPanel' isClickDismiss>
<div className='clearBrowsingData' onClick={(e) => e.stopPropagation()}>
<div className='formSection clearBrowsingDataTitle' data-l10n-id='clearBrowsingData' />
<div className='formSection clearBrowsingDataOptions'>
<SwitchControl className='browserHistorySwitch' rightl10nId='browserHistory' checkedOn={this.state.clearBrowsingDataDetail.get('browserHistory')} onClick={this.onToggleBrowserHistory} />
<SwitchControl rightl10nId='downloadHistory' checkedOn={this.state.clearBrowsingDataDetail.get('downloadHistory')} onClick={this.onToggleDownloadHistory} />
<SwitchControl rightl10nId='cachedImagesAndFiles' checkedOn={this.state.clearBrowsingDataDetail.get('cachedImagesAndFiles')} onClick={this.onToggleCachedImagesAndFiles} />
<SwitchControl rightl10nId='savedPasswords' checkedOn={this.state.clearBrowsingDataDetail.get('savedPasswords')} onClick={this.onToggleSavedPasswords} />
<SwitchControl rightl10nId='allSiteCookies' checkedOn={this.state.clearBrowsingDataDetail.get('allSiteCookies')} onClick={this.onToggleAllSiteCookies} />
<SwitchControl className='autocompleteDataSwitch' rightl10nId='autocompleteData' checkedOn={this.state.clearBrowsingDataDetail.get('autocompleteData')} onClick={this.onToggleAutocompleteData} />
<SwitchControl className='autofillDataSwitch' rightl10nId='autofillData' checkedOn={this.state.clearBrowsingDataDetail.get('autofillData')} onClick={this.onToggleAutofillData} />
<SwitchControl className='siteSettingsSwitch' rightl10nId='savedSiteSettings' checkedOn={this.state.clearBrowsingDataDetail.get('savedSiteSettings')} onClick={this.onToggleSavedSiteSettings} />
</div>
<div className='formSection clearBrowsingDataButtons'>
<Button l10nId='cancel' className='whiteButton' onClick={this.props.onHide} />
<Button l10nId='clear' className='primaryButton clearDataButton' onClick={this.onClear} />
</div>
<div className='formSection clearBrowsingDataWarning'>
return <Dialog onHide={this.props.onHide} testId='clearBrowsingDataPanel' isClickDismiss>
<CommonFormSmall onClick={(e) => e.stopPropagation()}>
<CommonFormTitle data-l10n-id='clearBrowsingData' />
<CommonFormSection>
<SwitchControl
rightl10nId='browserHistory'
testId='browserHistorySwitch'
checkedOn={this.state.clearBrowsingDataDetail.get('browserHistory')}
onClick={this.onToggleBrowserHistory} />
<SwitchControl
rightl10nId='downloadHistory'
checkedOn={this.state.clearBrowsingDataDetail.get('downloadHistory')}
onClick={this.onToggleDownloadHistory} />
<SwitchControl
rightl10nId='cachedImagesAndFiles'
checkedOn={this.state.clearBrowsingDataDetail.get('cachedImagesAndFiles')}
onClick={this.onToggleCachedImagesAndFiles} />
<SwitchControl
rightl10nId='savedPasswords'
checkedOn={this.state.clearBrowsingDataDetail.get('savedPasswords')}
onClick={this.onToggleSavedPasswords} />
<SwitchControl
rightl10nId='allSiteCookies'
checkedOn={this.state.clearBrowsingDataDetail.get('allSiteCookies')}
onClick={this.onToggleAllSiteCookies} />
<SwitchControl
rightl10nId='autocompleteData'
testId='autocompleteDataSwitch'
checkedOn={this.state.clearBrowsingDataDetail.get('autocompleteData')}
onClick={this.onToggleAutocompleteData} />
<SwitchControl
rightl10nId='autofillData'
testId='autofillDataSwitch'
checkedOn={this.state.clearBrowsingDataDetail.get('autofillData')}
onClick={this.onToggleAutofillData} />
<SwitchControl
rightl10nId='savedSiteSettings'
testId='siteSettingsSwitch'
checkedOn={this.state.clearBrowsingDataDetail.get('savedSiteSettings')}
onClick={this.onToggleSavedSiteSettings} />
</CommonFormSection>
<CommonFormButtonWrapper>
<Button className='whiteButton'
l10nId='cancel'
testId='cancelButton'
onClick={this.props.onHide}
/>
<Button className='primaryButton'
l10nId='clear'
testId='clearDataButton'
onClick={this.onClear}
/>
</CommonFormButtonWrapper>
<CommonFormBottomWrapper>
<div data-l10n-id='clearDataWarning' />
</div>
</div>
</CommonFormBottomWrapper>
</CommonFormSmall>
</Dialog>
}
}
Expand Down
6 changes: 3 additions & 3 deletions js/components/loginRequired.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ class LoginRequired extends React.Component {
<CommonFormSection data-l10n-id='basicAuthMessage' data-l10n-args={JSON.stringify(l10nArgs)} />
<CommonFormSection>
<div className={css(styles.sectionWrapper)}>
<div data-test-id='loginLabel'
className={css(commonFormStyles.inputWrapper,
<div className={css(
commonFormStyles.inputWrapper,
commonFormStyles.inputWrapper__label
)}>
)} data-test-id='loginLabel'>
<label data-l10n-id='basicAuthUsernameLabel' htmlFor='loginUsername' />
<label className={css(commonFormStyles.input__bottomRow)} data-l10n-id='basicAuthPasswordLabel' htmlFor='loginPassword' />
</div>
Expand Down
1 change: 1 addition & 0 deletions js/components/switchControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class SwitchControl extends ImmutableComponent {
hasTopText: this.props.topl10nId
})}
data-switch-status={this.props.checkedOn}
data-test-id={this.props.testId}
>
{
this.props.leftl10nId && this.props.topl10nId
Expand Down
45 changes: 0 additions & 45 deletions less/forms.less
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,6 @@ select {
top: @dialogTopOffset;
}

.clearBrowsingDataPanel {
.clearBrowsingData {
.flyoutDialog;
background-color: #f7f7f7;
border-radius: @borderRadius;
max-width: 325px;
padding: 0;
text-align: left;
width: 473px;
user-select: none;
cursor: default;
color: #3B3B3B;
overflow-y: auto;
max-height: 100%;

.clickable {
color: #5B5B5B;
&:hover {
color: #000;
}
}

.formSection {
padding: 16px 30px;
&.clearBrowsingDataWarning {
background-color: #dddee0;
}

&.clearBrowsingDataTitle {
color: #ff5000;
font-size: 1.2em;
}

&.clearBrowsingDataOptions {
padding: 0 30px;
}

&.clearBrowsingDataButtons {
text-align: right;
padding: 16px 10px;
}
}
}
}

.braveryPanelContainer {
.braveryPanel {
.flyoutDialog;
Expand Down
23 changes: 11 additions & 12 deletions test/bravery-components/clearBrowsingDataPanelTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const Brave = require('../lib/brave')
const {urlInput, braveMenu, noScriptSwitch, braveryPanel, notificationBar, clearBrowsingDataButton, securityTab, clearDataButton} = require('../lib/selectors')
const {getTargetAboutUrl} = require('../../js/lib/appUrlUtil')
const aboutPreferencesUrl = getTargetAboutUrl('about:preferences')
const {getHistory} = require('../../app/common/lib/historyUtil')
const messages = require('../../js/constants/messages')

Expand All @@ -25,7 +26,7 @@ describe('Clear Browsing Panel', function () {
function * openClearBrowsingDataPanel (client) {
return client
.tabByIndex(0)
.loadUrl(getTargetAboutUrl('about:preferences'))
.loadUrl(aboutPreferencesUrl)
.waitForVisible(securityTab)
.click(securityTab)
.waitForVisible(clearBrowsingDataButton)
Expand All @@ -46,12 +47,11 @@ describe('Clear Browsing Panel', function () {

it('saves the history switch state', function * () {
const page1Url = Brave.server.url('page1.html')
const browserHistorySwitch = '.browserHistorySwitch'
yield openClearBrowsingDataPanel(this.app.client)
yield this.app.client
.waitForVisible(browserHistorySwitch)
.waitForVisible('[data-test-id="browserHistorySwitch"]')
.waitForVisible(clearDataButton)
.click(`${browserHistorySwitch} .switchBackground`)
.click('[data-test-id="browserHistorySwitch"] .switchBackground')
.click(clearDataButton)
.waitUntil(function () {
return this.getAppState().then((val) => {
Expand All @@ -69,7 +69,7 @@ describe('Clear Browsing Panel', function () {
})
yield openClearBrowsingDataPanel(this.app.client)
yield this.app.client
.waitForVisible(`${browserHistorySwitch} .switchedOn`)
.waitForVisible('[data-test-id="browserHistorySwitch"] .switchedOn')
.waitForVisible(clearDataButton)
.click(clearDataButton)
.waitUntil(function () {
Expand Down Expand Up @@ -99,10 +99,9 @@ describe('Clear Browsing Panel', function () {
})

it('shows clearing options', function * () {
const clearBrowsingDataButton = '.clearBrowsingDataButton'
yield this.app.client
.tabByIndex(0)
.loadUrl(getTargetAboutUrl('about:preferences'))
.loadUrl(aboutPreferencesUrl)
.waitForVisible(securityTab)
.click(securityTab)
.waitForVisible(clearBrowsingDataButton)
Expand All @@ -111,13 +110,13 @@ describe('Clear Browsing Panel', function () {
it('clears the browsing history', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(getTargetAboutUrl('about:preferences'))
.loadUrl(aboutPreferencesUrl)
.waitForVisible(securityTab)
.click(securityTab)
.waitForVisible(clearBrowsingDataButton)
.click(clearBrowsingDataButton)
.waitForBrowserWindow()
.waitForVisible('.browserHistorySwitch')
.waitForVisible('[data-test-id="browserHistorySwitch"]')
.waitForVisible(clearDataButton)
.click(clearDataButton)
.waitUntil(function () {
Expand Down Expand Up @@ -200,14 +199,14 @@ describe('Clear Browsing Panel', function () {
it('clears site settings and permissions', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(getTargetAboutUrl('about:preferences'))
.loadUrl(aboutPreferencesUrl)
.waitForVisible(securityTab)
.click(securityTab)
.waitForVisible(clearBrowsingDataButton)
.click(clearBrowsingDataButton)
.waitForBrowserWindow()
.waitForVisible('.siteSettingsSwitch')
.click('.siteSettingsSwitch .switchBackground')
.waitForVisible('[data-test-id="siteSettingsSwitch"]')
.click('[data-test-id="siteSettingsSwitch"] .switchBackground')
.waitForVisible(clearDataButton)
.click(clearDataButton)
.waitUntil(function () {
Expand Down
18 changes: 9 additions & 9 deletions test/contents/autofillTest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global describe, it, before, beforeEach */

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

const addAddressButton = '[data-test-id="addAddressButton"]'
Expand Down Expand Up @@ -417,10 +417,10 @@ describe('Autofill', function () {
.waitForVisible(clearBrowsingDataButton)
.click(clearBrowsingDataButton)
.waitForBrowserWindow()
.waitForVisible('.autofillDataSwitch')
.click('.autofillDataSwitch .switchMiddle')
.waitForVisible('.clearDataButton')
.click('.clearDataButton')
.waitForVisible('[data-test-id="autofillDataSwitch"]')
.click('[data-test-id="autofillDataSwitch"] .switchMiddle')
.waitForVisible(clearDataButton)
.click(clearDataButton)
})
it('does not autofill in regular tab', function * () {
yield this.app.client
Expand Down Expand Up @@ -591,10 +591,10 @@ describe('Autofill', function () {
.waitForVisible(clearBrowsingDataButton)
.click(clearBrowsingDataButton)
.waitForBrowserWindow()
.waitForVisible('.autocompleteDataSwitch')
.click('.autocompleteDataSwitch .switchMiddle')
.waitForVisible('.clearDataButton')
.click('.clearDataButton')
.waitForVisible('[data-test-id="autocompleteDataSwitch"]')
.click('[data-test-id="autocompleteDataSwitch"] .switchMiddle')
.waitForVisible(clearDataButton)
.click(clearDataButton)
})
it('does not autofill in regular tab', function * () {
yield this.app.client
Expand Down
6 changes: 3 additions & 3 deletions test/lib/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ module.exports = {
backButton: '.backforward .backButton',
forwardButton: '.backforward .forwardButton',
reloadButton: '.reloadButton',
clearBrowsingDataPanel: '.clearBrowsingDataPanel',
clearBrowsingDataButton: '.clearBrowsingDataButton',
clearDataButton: '.clearDataButton',
clearBrowsingDataButton: '[data-test-id="clearBrowsingDataButton"]',
clearBrowsingDataPanel: '[data-test-id="clearBrowsingDataPanel"]',
clearDataButton: '[data-test-id="clearDataButton"]',
securityTab: '[data-l10n-id="security"]',
paymentsTab: '[data-l10n-id="payments"]',
syncTab: '[data-l10n-id="sync"]',
Expand Down

0 comments on commit bbf1457

Please sign in to comment.