-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to disable
Newsletter clicks
toggle in settings (#22090)
ref https://linear.app/ghost/issue/ENG-1974/create-config-option-to-forcibly-disable-email-track-clicks - With the ability to override a setting via configuration, we also need to disable the setting's toggle in the UI to signal to the user that it cannot be changed. - This commit sets `disabled: true` on the `Newsletter clicks` toggle if `is_read_only` is set to `true` on the `email_track_clicks` setting returned from the API, and establishes a pattern that we can use for other settings in the future, if desired.
- Loading branch information
Showing
5 changed files
with
102 additions
and
3 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
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
59 changes: 59 additions & 0 deletions
59
apps/admin-x-framework/test/unit/utils/api/settings.test.tsx
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,59 @@ | ||
import {getSettingValue, getSettingValues, isSettingReadOnly} from '../../../../src/api/settings'; | ||
|
||
describe('settings utils', function () { | ||
describe('getSettingValue', function () { | ||
it('returns the value of a setting', function () { | ||
const settings = [ | ||
{key: 'test_key', value: 'test_value'} | ||
]; | ||
const value = getSettingValue(settings, 'test_key'); | ||
expect(value).toEqual('test_value'); | ||
}); | ||
|
||
it('returns null if settings is null', function () { | ||
const settings = undefined; | ||
const value = getSettingValue(settings, 'test_key'); | ||
expect(value).toEqual(null); | ||
}); | ||
}); | ||
|
||
describe('getSettingValues', function () { | ||
it('returns the values of multiple settings', function () { | ||
const settings = [ | ||
{key: 'test_key', value: 'test_value'}, | ||
{key: 'test_key_2', value: 'test_value_2'} | ||
]; | ||
const values = getSettingValues(settings, ['test_key', 'test_key_2']); | ||
expect(values).toEqual(['test_value', 'test_value_2']); | ||
}); | ||
|
||
it('returns undefined for missing keys', function () { | ||
const values = getSettingValues([], ['test_key', 'test_key_2']); | ||
expect(values).toEqual([undefined, undefined]); | ||
}); | ||
}); | ||
|
||
describe('isSettingReadOnly', function () { | ||
it('returns true if the setting has an override', function () { | ||
const settings = [ | ||
{key: 'test_key', is_read_only: true, value: 'test_value'} | ||
]; | ||
const value = isSettingReadOnly(settings, 'test_key'); | ||
expect(value).toEqual(true); | ||
}); | ||
|
||
it('returns false if the setting does not have an override', function () { | ||
const settings = [ | ||
{key: 'test_key', is_read_only: false, value: 'test_value'} | ||
]; | ||
const value = isSettingReadOnly(settings, 'test_key'); | ||
expect(value).toEqual(false); | ||
}); | ||
|
||
it('returns undefined if settings is falsy', function () { | ||
const settings = undefined; | ||
const value = isSettingReadOnly(settings, 'test_key'); | ||
expect(value).toEqual(undefined); | ||
}); | ||
}); | ||
}); |
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