-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace Vuex settingsStore.js to Pinia settings.js
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
- Loading branch information
Showing
6 changed files
with
114 additions
and
98 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
This file was deleted.
Oops, something went wrong.
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,43 @@ | ||
import { setActivePinia, createPinia } from 'pinia' | ||
|
||
import { PRIVACY } from '../../constants.js' | ||
import { useSettingsStore } from '../settings.js' | ||
|
||
jest.mock('@nextcloud/initial-state', | ||
() => ({ | ||
loadState: jest.fn().mockReturnValue(0), | ||
})) | ||
|
||
jest.mock('../../services/settingsService', | ||
() => ({ | ||
setReadStatusPrivacy: jest.fn().mockReturnValue('success'), | ||
setTypingStatusPrivacy: jest.fn().mockReturnValue('success'), | ||
})) | ||
|
||
describe('settingsStore', () => { | ||
beforeEach(() => { | ||
// creates a fresh pinia and make it active, so it's automatically picked | ||
// up by any useStore() call without having to pass it to it: | ||
// `useStore(pinia)` | ||
setActivePinia(createPinia()) | ||
}) | ||
|
||
it('shows correct loaded values for statuses', () => { | ||
const settingsStore = useSettingsStore() | ||
|
||
expect(settingsStore.readStatusPrivacy).toBe(PRIVACY.PUBLIC) | ||
expect(settingsStore.typingStatusPrivacy).toBe(PRIVACY.PUBLIC) | ||
}) | ||
|
||
it('toggles statuses correctly', async () => { | ||
const settingsStore = useSettingsStore() | ||
|
||
expect(settingsStore.readStatusPrivacy).toBe(PRIVACY.PUBLIC) | ||
await settingsStore.updateReadStatusPrivacy(PRIVACY.PRIVATE) | ||
expect(settingsStore.readStatusPrivacy).toBe(PRIVACY.PRIVATE) | ||
|
||
expect(settingsStore.typingStatusPrivacy).toBe(PRIVACY.PUBLIC) | ||
await settingsStore.updateTypingStatusPrivacy(PRIVACY.PRIVATE) | ||
expect(settingsStore.typingStatusPrivacy).toBe(PRIVACY.PRIVATE) | ||
}) | ||
}) |
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,57 @@ | ||
/** | ||
* @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com> | ||
* | ||
* @author Maksim Sukharev <antreesy.web@gmail.com> | ||
* | ||
* @license AGPL-3.0-or-later | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
import { defineStore } from 'pinia' | ||
|
||
import { loadState } from '@nextcloud/initial-state' | ||
|
||
import { PRIVACY } from '../constants.js' | ||
import { setReadStatusPrivacy, setTypingStatusPrivacy } from '../services/settingsService.js' | ||
|
||
export const useSettingsStore = defineStore('settings', { | ||
state: () => ({ | ||
readStatusPrivacy: loadState('spreed', 'read_status_privacy', PRIVACY.PRIVATE), | ||
typingStatusPrivacy: loadState('spreed', 'typing_privacy', PRIVACY.PRIVATE), | ||
}), | ||
|
||
actions: { | ||
/** | ||
* Update the read status privacy for the user | ||
* | ||
* @param {number} privacy The new selected privacy | ||
*/ | ||
async updateReadStatusPrivacy(privacy) { | ||
await setReadStatusPrivacy(privacy) | ||
this.readStatusPrivacy = privacy | ||
}, | ||
|
||
/** | ||
* Update the typing status privacy for the user | ||
* | ||
* @param {number} privacy The new selected privacy | ||
*/ | ||
async updateTypingStatusPrivacy(privacy) { | ||
await setTypingStatusPrivacy(privacy) | ||
this.typingStatusPrivacy = privacy | ||
}, | ||
}, | ||
}) |