Skip to content

Commit 16da6b3

Browse files
test: Allow mockAppRoot().withSetting() to mock setting structure (RocketChat#37162)
1 parent 7c1f5d2 commit 16da6b3

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import type { ISetting } from '@rocket.chat/apps-engine/definition/settings';
2+
import { mockAppRoot } from '@rocket.chat/mock-providers';
3+
import { useSettingStructure } from '@rocket.chat/ui-contexts';
4+
import { renderHook } from '@testing-library/react';
5+
6+
describe('useSettingStructure', () => {
7+
it('should return setting structure from context', () => {
8+
const settingStructure = {
9+
_id: 'Force_SSL',
10+
type: 'boolean' as const,
11+
public: true,
12+
env: false,
13+
blocked: false,
14+
packageValue: true,
15+
i18nLabel: 'Force_SSL',
16+
sorter: 0,
17+
ts: new Date(),
18+
createdAt: new Date(),
19+
required: false,
20+
id: 'Force_SSL',
21+
value: true,
22+
} as ISetting;
23+
24+
const { result } = renderHook(() => useSettingStructure('Force_SSL'), {
25+
wrapper: mockAppRoot().withSetting('Force_SSL', true, settingStructure).build(),
26+
});
27+
28+
expect(result.current).toEqual(settingStructure);
29+
});
30+
31+
it('should return undefined when setting does not exist', () => {
32+
const { result } = renderHook(() => useSettingStructure('non-existent-setting'), {
33+
wrapper: mockAppRoot().build(),
34+
});
35+
36+
expect(result.current).toBeUndefined();
37+
});
38+
});

packages/mock-providers/src/MockedAppRootBuilder.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,9 @@ export class MockedAppRootBuilder {
468468
return this;
469469
}
470470

471-
withSetting(id: string, value: SettingValue): this {
471+
withSetting(id: string, value: SettingValue, settingStructure?: Partial<ISetting>): this {
472472
const setting = {
473+
...settingStructure,
473474
_id: id,
474475
value,
475476
} as ISetting;

0 commit comments

Comments
 (0)