This commit is contained in:
Marcos Rodriguez Velez 2024-11-19 22:16:26 -04:00
parent 018e4dc39f
commit 20c807a49c
6 changed files with 10 additions and 9483 deletions

View File

@ -50,7 +50,6 @@ DefaultPreference.set('my key', 'my value').then(function() {console.log('done')
```
## API
```typescript
function get(key: string): Promise<string | undefined | null>;
function set(key: string, value: string): Promise<void>;

View File

@ -136,7 +136,7 @@ describe.each(['ios', 'android'])('DefaultPreference on %s', (platform) => {
// Act
await DefaultPreference.setGroupName(currentGroupName);
const groupName = await DefaultPreference.getGroupName();
const groupName = await DefaultPreference.getName();
// Assert
expect(RNDefaultPreference.setName).toHaveBeenCalledWith(currentGroupName);

View File

@ -7,9 +7,9 @@ export interface RNDefaultPreferenceKeys {
}
class DefaultPreference {
private static groupName: string = 'default'; // Renamed from 'name' to 'groupName'
private static groupName: string = 'default';
static setGroupName(name: string = 'default') { // Renamed method
static setName(name: string = 'default') {
DefaultPreference.groupName = name;
if (name !== 'default') {
RNDefaultPreference.setName(name);
@ -48,7 +48,7 @@ class DefaultPreference {
return RNDefaultPreference.clearAll(DefaultPreference.groupName);
}
static async getGroupName(): Promise<string> { // Renamed method
static async getName(): Promise<string> {
return DefaultPreference.groupName;
}
}

9473
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
{
"compilerOptions": {
"esModuleInterop": true,
"lib": ["es2015", "dom"]
},
}

View File

@ -14,12 +14,12 @@ describe('useDefaultPreference', () => {
const mockClearMultiple = jest.fn();
const mockGetAll = jest.fn();
const mockClearAll = jest.fn();
const mockGetGroupName = jest.fn();
const mockgetName = jest.fn();
beforeEach(() => {
(DefaultPreference as unknown as jest.Mock).mockImplementation(() => ({
setGroupName: mockSetName, // Updated mock method
getGroupName: mockGetGroupName, // Added mock method
getName: mockgetName, // Added mock method
get: mockGet,
set: mockSet,
clear: mockClear,
@ -56,17 +56,17 @@ describe('useDefaultPreference', () => {
it('should retrieve the current group name', async () => {
// Arrange
const currentGroupName = 'testGroup';
mockGetGroupName.mockResolvedValue(currentGroupName);
mockgetName.mockResolvedValue(currentGroupName);
// Act
const { result, waitForNextUpdate } = renderHook(() => useDefaultPreference());
// Assuming the hook exposes a method to get the group name
// If not, this test should be adjusted based on the hook's implementation
const groupName = await DefaultPreference.getGroupName();
const groupName = await DefaultPreference.getName();
// Assert
expect(mockGetGroupName).toHaveBeenCalled();
expect(mockgetName).toHaveBeenCalled();
expect(groupName).toBe(currentGroupName);
});