1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-16 00:14:34 +02:00

Desktop: Fixes #10381: Fix plugin settings stored in settings.json are lost on startup (#10458)

This commit is contained in:
Henry Heino
2024-05-28 05:42:52 -07:00
committed by GitHub
parent b8caf08fac
commit 34092d8491
3 changed files with 57 additions and 4 deletions

View File

@ -84,7 +84,7 @@ describe('models/Setting', () => {
expect(Setting.value('myCustom')).toBe('123');
}));
it('should not clear old custom settings', (async () => {
it.each([SettingStorage.Database, SettingStorage.File])('should not clear old custom settings if not registered immediately', (async (storage) => {
// In general the following should work:
//
// - Plugin register a new setting
@ -105,6 +105,7 @@ describe('models/Setting', () => {
public: true,
value: 'default',
type: Setting.TYPE_STRING,
storage,
});
Setting.setValue('myCustom', '123');
@ -119,6 +120,7 @@ describe('models/Setting', () => {
public: true,
value: 'default',
type: Setting.TYPE_STRING,
storage,
});
await Setting.saveAll();
@ -126,6 +128,34 @@ describe('models/Setting', () => {
expect(Setting.value('myCustom')).toBe('123');
}));
it.each([SettingStorage.Database, SettingStorage.File])('should not clear old custom settings if not registered until restart', async (storage) => {
const registerCustom = async () => {
await Setting.registerSetting('myCustom', {
public: true,
value: 'test',
type: Setting.TYPE_STRING,
storage,
});
};
await registerCustom();
Setting.setValue('myCustom', 'test2');
await Setting.saveAll();
await Setting.reset();
await Setting.load();
// Change a file setting
Setting.setValue('sync.target', 9);
await Setting.saveAll();
await Setting.reset();
await Setting.load();
await registerCustom();
expect(Setting.value('myCustom')).toBe('test2');
});
it('should return values with correct type for custom settings', (async () => {
await Setting.registerSetting('myCustom', {
public: true,
@ -425,5 +455,4 @@ describe('models/Setting', () => {
await Setting.saveAll();
}
});
});