-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MM-62701] [MM-62176]Edit custom profile attributes in user profile (#…
…8557) * feat: Add support for custom profile attributes in edit profile form feat: Add support for custom profile attributes in edit profile refactor: Normalize whitespace in CustomAttribute type definition fix: Resolve type mismatch for customAttributes in UserInfo interface test: Add test for udpateCustomProfileAttributeValues method fix typing, submit changes to server missing files test: Add tests for CustomProfileField component fix naming fix imports fix feat: Add field_refs hook for managing field references feat: Make `setRef` ref parameter optional with default no-op implementation refactor: Replace CustomProfileField with useFieldRefs for profile form refactor: Optimize edit profile screen imports and custom attributes handling refactor: Move custom attributes logic to remote actions in user.ts address PR reviews test: Add tests for custom attributes in edit profile test: Add tests for EditProfile component with custom attributes fix: Add UserModel type assertion to currentUser in edit profile tests test: Add tests for ProfileForm custom attributes functionality test: Add comprehensive tests for useFieldRefs hook test: Add tests for fetchCustomAttributes and updateCustomAttributes add tests remove unneeded files review changes remove counter from hook remove package.resolved create interface for reuse of record * fix signature type
- Loading branch information
1 parent
8e02e06
commit bcc4259
Showing
15 changed files
with
706 additions
and
135 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 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 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 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,103 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import {renderHook, act} from '@testing-library/react-hooks'; | ||
|
||
import useFieldRefs from './field_refs'; | ||
|
||
describe('useFieldRefs', () => { | ||
it('should initialize with empty refs', () => { | ||
const {result} = renderHook(() => useFieldRefs()); | ||
const [getRef] = result.current; | ||
|
||
expect(getRef('test')).toBeUndefined(); | ||
}); | ||
|
||
it('should set and get refs', () => { | ||
const {result} = renderHook(() => useFieldRefs()); | ||
const [getRef, setRef] = result.current; | ||
|
||
const mockRef = { | ||
blur: jest.fn(), | ||
focus: jest.fn(), | ||
isFocused: jest.fn(), | ||
}; | ||
|
||
act(() => { | ||
setRef('testField')(mockRef); | ||
}); | ||
|
||
expect(getRef('testField')).toBe(mockRef); | ||
}); | ||
|
||
it('should track number of refs', () => { | ||
const {result} = renderHook(() => useFieldRefs()); | ||
const [, setRef] = result.current; | ||
|
||
const mockRef1 = { | ||
blur: jest.fn(), | ||
focus: jest.fn(), | ||
isFocused: jest.fn(), | ||
}; | ||
|
||
const mockRef2 = { | ||
blur: jest.fn(), | ||
focus: jest.fn(), | ||
isFocused: jest.fn(), | ||
}; | ||
|
||
act(() => { | ||
setRef('field1')(mockRef1); | ||
setRef('field2')(mockRef2); | ||
}); | ||
}); | ||
|
||
it('should remove refs when cleanup function is called', () => { | ||
const {result} = renderHook(() => useFieldRefs()); | ||
const [getRef, setRef] = result.current; | ||
|
||
const mockRef = { | ||
blur: jest.fn(), | ||
focus: jest.fn(), | ||
isFocused: jest.fn(), | ||
}; | ||
|
||
let cleanup: () => void; | ||
act(() => { | ||
cleanup = setRef('testField')(mockRef); | ||
}); | ||
|
||
expect(getRef('testField')).toBe(mockRef); | ||
|
||
act(() => { | ||
cleanup!(); | ||
}); | ||
|
||
expect(getRef('testField')).toBeUndefined(); | ||
}); | ||
|
||
it('should handle multiple refs independently', () => { | ||
const {result} = renderHook(() => useFieldRefs()); | ||
const [getRef, setRef] = result.current; | ||
|
||
const mockRef1 = { | ||
blur: jest.fn(), | ||
focus: jest.fn(), | ||
isFocused: jest.fn(), | ||
}; | ||
|
||
const mockRef2 = { | ||
blur: jest.fn(), | ||
focus: jest.fn(), | ||
isFocused: jest.fn(), | ||
}; | ||
|
||
act(() => { | ||
setRef('field1')(mockRef1); | ||
setRef('field2')(mockRef2); | ||
}); | ||
|
||
expect(getRef('field1')).toBe(mockRef1); | ||
expect(getRef('field2')).toBe(mockRef2); | ||
}); | ||
}); |
Oops, something went wrong.