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

Disable spellcheck when language list is empty #11758

Merged
merged 1 commit into from
Nov 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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