This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 974
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9516 from NejcZdovc/redux/updateBar
Converts UpdateBar into redux component
- Loading branch information
Showing
4 changed files
with
197 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
const Immutable = require('immutable') | ||
const updateStatus = require('../../../js/constants/updateStatus') | ||
|
||
const isUpdateVisible = (state) => { | ||
const updates = state.get('updates', Immutable.Map()) | ||
|
||
const isVerbose = updates.get('verbose', false) | ||
const status = updates.get('status') | ||
|
||
// When verbose is not set we only want to show update available | ||
// prompts, because otherwise the check is a background check and | ||
// the user shouldn't be bothered. | ||
return !( | ||
!status || | ||
( | ||
!isVerbose && | ||
status !== updateStatus.UPDATE_AVAILABLE | ||
) || | ||
status === updateStatus.UPDATE_NONE || | ||
status === updateStatus.UPDATE_APPLYING_RESTART || | ||
status === updateStatus.UPDATE_APPLYING_NO_RESTART | ||
) | ||
} | ||
|
||
const getUpdateStatus = (state) => { | ||
let status = state.getIn(['updates', 'status']) | ||
|
||
// The only difference between the deferred and non deferred variant is that | ||
// the deferred allows hiding. Otherwise you couldn't hide available prompts. | ||
if (status === updateStatus.UPDATE_AVAILABLE_DEFERRED) { | ||
status = updateStatus.UPDATE_AVAILABLE | ||
} | ||
|
||
return status | ||
} | ||
|
||
module.exports = { | ||
isUpdateVisible, | ||
getUpdateStatus | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
/* global describe, it */ | ||
const assert = require('assert') | ||
const Immutable = require('immutable') | ||
|
||
const updateUtil = require('../../../../../app/common/state/updateState') | ||
const updateStatus = require('../../../../../js/constants/updateStatus') | ||
require('../../../braveUnit') | ||
|
||
describe('updateUtil test', function () { | ||
describe('getUpdateStatus', function () { | ||
it('update is not available', function () { | ||
const result = updateUtil.getUpdateStatus(Immutable.Map()) | ||
assert.equal(result, null) | ||
}) | ||
|
||
it('update status is UPDATE_AVAILABLE_DEFERRED', function () { | ||
const result = updateUtil.getUpdateStatus(Immutable.fromJS({ | ||
updates: { | ||
status: updateStatus.UPDATE_AVAILABLE_DEFERRED | ||
} | ||
})) | ||
assert.equal(result, updateStatus.UPDATE_AVAILABLE) | ||
}) | ||
|
||
it('update status is returned normally', function () { | ||
const result = updateUtil.getUpdateStatus(Immutable.fromJS({ | ||
updates: { | ||
status: updateStatus.UPDATE_CHECKING | ||
} | ||
})) | ||
assert.equal(result, updateStatus.UPDATE_CHECKING) | ||
}) | ||
}) | ||
|
||
describe('isUpdateVisible', function () { | ||
it('update is not available', function () { | ||
const result = updateUtil.isUpdateVisible(Immutable.Map()) | ||
assert.equal(result, false) | ||
}) | ||
|
||
it('status is not available', function () { | ||
const result = updateUtil.isUpdateVisible(Immutable.fromJS({ | ||
updates: {} | ||
})) | ||
assert.equal(result, false) | ||
}) | ||
|
||
it('update is not verbose and status is different then UPDATE_AVAILABLE', function () { | ||
const result = updateUtil.isUpdateVisible(Immutable.fromJS({ | ||
updates: { | ||
verbose: false, | ||
status: updateStatus.UPDATE_CHECKING | ||
} | ||
})) | ||
assert.equal(result, false) | ||
}) | ||
|
||
it('update is verbose and status is UPDATE_AVAILABLE', function () { | ||
const result = updateUtil.isUpdateVisible(Immutable.fromJS({ | ||
updates: { | ||
verbose: true, | ||
status: updateStatus.UPDATE_AVAILABLE | ||
} | ||
})) | ||
assert.equal(result, true) | ||
}) | ||
|
||
it('update status is UPDATE_AVAILABLE', function () { | ||
const result = updateUtil.isUpdateVisible(Immutable.fromJS({ | ||
updates: { | ||
status: updateStatus.UPDATE_AVAILABLE | ||
} | ||
})) | ||
assert.equal(result, true) | ||
}) | ||
|
||
it('update status is UPDATE_NONE', function () { | ||
const result = updateUtil.isUpdateVisible(Immutable.fromJS({ | ||
updates: { | ||
status: updateStatus.UPDATE_NONE | ||
} | ||
})) | ||
assert.equal(result, false) | ||
}) | ||
|
||
it('update status is UPDATE_APPLYING_RESTART', function () { | ||
const result = updateUtil.isUpdateVisible(Immutable.fromJS({ | ||
updates: { | ||
status: updateStatus.UPDATE_APPLYING_RESTART | ||
} | ||
})) | ||
assert.equal(result, false) | ||
}) | ||
|
||
it('update status is UPDATE_APPLYING_NO_RESTART', function () { | ||
const result = updateUtil.isUpdateVisible(Immutable.fromJS({ | ||
updates: { | ||
status: updateStatus.UPDATE_APPLYING_NO_RESTART | ||
} | ||
})) | ||
assert.equal(result, false) | ||
}) | ||
}) | ||
}) |