Skip to content

Commit

Permalink
test: add SettingsAPI tests
Browse files Browse the repository at this point in the history
Signed-off-by: Grigorii K. Shartsev <me@shgk.me>
  • Loading branch information
ShGKme committed Sep 10, 2024
1 parent abb133a commit 6be015a
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/services/__tests__/SettingsAPI.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { jest, describe, it, expect } from '@jest/globals'

import { emit } from '@nextcloud/event-bus'

import { SettingsAPI, useCustomSettings } from '../SettingsAPI.ts'

jest.mock('@nextcloud/event-bus')

describe('SettingsAPI', () => {
it('should have open method to open settings', () => {
expect(SettingsAPI.open).toBeDefined()
SettingsAPI.open()
// Currently, a global event is used to open the settings
expect(emit).toHaveBeenCalledWith('show-settings', undefined)
})

it('should have registerSection method to register settings sections', () => {
const { customSettingsSections } = useCustomSettings()
expect(customSettingsSections).toEqual([])
expect(SettingsAPI.registerSection).toBeDefined()
SettingsAPI.registerSection({
id: 'test',
name: 'Test',
element: 'test-element',
})
SettingsAPI.registerSection({
id: 'test2',
name: 'Test 2',
element: 'test-element-two',
})
expect(customSettingsSections).toEqual([{
id: 'test',
name: 'Test',
element: 'test-element',
}, {
id: 'test2',
name: 'Test 2',
element: 'test-element-two',
}])
})

it('should have unregisterSection method to unregister settings sections', () => {
const { customSettingsSections } = useCustomSettings()
expect(customSettingsSections).toEqual([{
id: 'test',
name: 'Test',
element: 'test-element',
}, {
id: 'test2',
name: 'Test 2',
element: 'test-element-two',
}])
expect(SettingsAPI.unregisterSection).toBeDefined()
SettingsAPI.unregisterSection('test')
expect(customSettingsSections).toEqual([{
id: 'test2',
name: 'Test 2',
element: 'test-element-two',
}])
})
})

0 comments on commit 6be015a

Please sign in to comment.