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

Commit

Permalink
Merge pull request #11758 from brave/issue-11739
Browse files Browse the repository at this point in the history
Disable spellcheck when language list is empty
  • Loading branch information
bsclifton committed Nov 3, 2017
1 parent 3e7e96b commit 13e6e16
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
7 changes: 4 additions & 3 deletions app/browser/reducers/spellCheckerReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ const migrate = (state) => {
}

const setSpellCheckerSettings = () => {
const enabled = getSetting(settings.SPELLCHECK_ENABLED)
const langs = getSetting(settings.SPELLCHECK_LANGUAGES)
const enabled = getSetting(settings.SPELLCHECK_ENABLED) && !!langs.size

setUserPref('browser.enable_spellchecking', enabled)
if (enabled) {
setUserPref('spellcheck.dictionaries',
getSetting(settings.SPELLCHECK_LANGUAGES))
setUserPref('spellcheck.dictionaries', langs)
}
}

Expand Down
6 changes: 5 additions & 1 deletion js/about/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ class GeneralTab extends ImmutableComponent {
}

onSpellCheckLangsChange (value) {
this.props.onChangeSetting(settings.SPELLCHECK_LANGUAGES, value.split(','))
if (!value) {
this.props.onChangeSetting(settings.SPELLCHECK_LANGUAGES, [])
} else {
this.props.onChangeSetting(settings.SPELLCHECK_LANGUAGES, value.split(','))
}
}

setAsDefaultBrowser () {
Expand Down
27 changes: 26 additions & 1 deletion test/unit/app/browser/reducers/spellCheckerReducerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ describe('spellCheckerReducer unit tests', function () {
let getWebContentsSpy, replaceMisspellingSpy, replaceSpy, addWordSpy, removeWordSpy,
setUserPrefSpy, getSettingSpy
let spellCheckEnabled
let dicts
const dictionaryWord = 'braave'
const dictionarySuggestion = 'brave'
const tabId = 111
const enabledPref = 'browser.enable_spellchecking'
const dictsPref = 'spellcheck.dictionaries'
const dicts = ['en-US', 'fr-FR']

before(function () {
mockery.enable({
Expand Down Expand Up @@ -158,6 +158,7 @@ describe('spellCheckerReducer unit tests', function () {
getSettingSpy.reset()
setUserPrefSpy.reset()
spellCheckEnabled = true
dicts = Immutable.fromJS(['en-US', 'fr-FR'])
spellCheckerReducer(Immutable.Map(), Immutable.fromJS({
actionType: appConstants.APP_WINDOW_CREATED
}))
Expand All @@ -174,6 +175,7 @@ describe('spellCheckerReducer unit tests', function () {
getSettingSpy.reset()
setUserPrefSpy.reset()
spellCheckEnabled = false
dicts = Immutable.fromJS(['en-US', 'fr-FR'])
spellCheckerReducer(Immutable.Map(), Immutable.fromJS({
actionType: appConstants.APP_WINDOW_CREATED
}))
Expand All @@ -193,6 +195,7 @@ describe('spellCheckerReducer unit tests', function () {
getSettingSpy.reset()
setUserPrefSpy.reset()
spellCheckEnabled = true
dicts = Immutable.fromJS(['en-US', 'fr-FR'])
spellCheckerReducer(Immutable.Map(), Immutable.fromJS({
actionType: appConstants.APP_CHANGE_SETTING,
key: settings.SPELLCHECK_ENABLED
Expand All @@ -210,6 +213,7 @@ describe('spellCheckerReducer unit tests', function () {
getSettingSpy.reset()
setUserPrefSpy.reset()
spellCheckEnabled = false
dicts = Immutable.fromJS(['en-US', 'fr-FR'])
spellCheckerReducer(Immutable.Map(), Immutable.fromJS({
actionType: appConstants.APP_CHANGE_SETTING,
key: settings.SPELLCHECK_ENABLED
Expand All @@ -227,6 +231,7 @@ describe('spellCheckerReducer unit tests', function () {
getSettingSpy.reset()
setUserPrefSpy.reset()
spellCheckEnabled = true
dicts = Immutable.fromJS(['en-US', 'fr-FR'])
spellCheckerReducer(Immutable.Map(), Immutable.fromJS({
actionType: appConstants.APP_CHANGE_SETTING,
key: settings.SPELLCHECK_LANGUAGES
Expand All @@ -239,11 +244,30 @@ describe('spellCheckerReducer unit tests', function () {
assert(setUserPrefSpy.withArgs(dictsPref, dicts).calledOnce)
})
})
describe('empty SPELLCHECK_LANGUAGES with enabled', function () {
before(function () {
getSettingSpy.reset()
setUserPrefSpy.reset()
spellCheckEnabled = true
dicts = Immutable.fromJS([])
spellCheckerReducer(Immutable.Map(), Immutable.fromJS({
actionType: appConstants.APP_CHANGE_SETTING,
key: settings.SPELLCHECK_LANGUAGES
}))
})
it('not calls setUserPref to set enabledPref to true', function () {
assert(setUserPrefSpy.withArgs(enabledPref, true).notCalled)
})
it('not calls setUserPref to set dictionaries', function () {
assert(setUserPrefSpy.withArgs(dictsPref, dicts).notCalled)
})
})
describe('SPELLCHECK_LANGUAGES with disabled', function () {
before(function () {
getSettingSpy.reset()
setUserPrefSpy.reset()
spellCheckEnabled = false
dicts = Immutable.fromJS(['en-US', 'fr-FR'])
spellCheckerReducer(Immutable.Map(), Immutable.fromJS({
actionType: appConstants.APP_CHANGE_SETTING,
key: settings.SPELLCHECK_LANGUAGES
Expand All @@ -261,6 +285,7 @@ describe('spellCheckerReducer unit tests', function () {
getSettingSpy.reset()
setUserPrefSpy.reset()
spellCheckEnabled = false
dicts = Immutable.fromJS(['en-US', 'fr-FR'])
spellCheckerReducer(Immutable.Map(), Immutable.fromJS({
actionType: appConstants.APP_CHANGE_SETTING,
key: 'other-settings'
Expand Down

0 comments on commit 13e6e16

Please sign in to comment.