feat: implement open & close capabilities of file picker#8
Merged
Conversation
jrebocho
requested changes
Mar 27, 2025
src/types.ts
Outdated
| containerId?: string; | ||
| sessionToken: string; | ||
| baseUrl?: string; | ||
| onFilesPick?: (data: unknown) => void; |
Contributor
There was a problem hiding this comment.
Suggested change
| onFilesPick?: (data: unknown) => void; | |
| onFilesPicked?: (data: unknown) => void; |
src/filePicker.ts
Outdated
| this.#onCancel = onCancel ?? (() => {}); | ||
| } | ||
|
|
||
| openFilePicker(win = window, rootElementId = 'root') { |
Contributor
There was a problem hiding this comment.
Suggested change
| openFilePicker(win = window, rootElementId = 'root') { | |
| open(win = window, rootElementId = 'root') { |
src/filePicker.ts
Outdated
| this.#iframe.src = url; | ||
| } | ||
|
|
||
| closeFilePicker() { |
Contributor
There was a problem hiding this comment.
Suggested change
| closeFilePicker() { | |
| close() { |
src/specs/filePicker.spec.ts
Outdated
Comment on lines
+5
to
+20
| let mockOnFilesPick: ReturnType<typeof vi.fn>; | ||
| let mockOnClose: ReturnType<typeof vi.fn>; | ||
| let mockOnOpen: ReturnType<typeof vi.fn>; | ||
| let mockOnCancel: ReturnType<typeof vi.fn>; | ||
|
|
||
| expect(result).toBe(true); | ||
| beforeEach(() => { | ||
| // Setup mocks | ||
| mockOnFilesPick = vi.fn(); | ||
| mockOnClose = vi.fn(); | ||
| mockOnOpen = vi.fn(); | ||
| mockOnCancel = vi.fn(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| }); |
Contributor
There was a problem hiding this comment.
Can we remove the global stuff from the tests?
src/specs/filePicker.spec.ts
Outdated
Comment on lines
+58
to
+76
| it('can be initialized with event handlers', () => { | ||
| const picker = new FilePicker({ | ||
| sessionToken: 'test-token', | ||
| onFilesPick: mockOnFilesPick, | ||
| onClose: mockOnClose, | ||
| onOpen: mockOnOpen, | ||
| onCancel: mockOnCancel, | ||
| }); | ||
|
|
||
| expect(picker).toBeInstanceOf(FilePicker); | ||
| }); | ||
|
|
||
| it('works without event handlers', () => { | ||
| const picker = new FilePicker({ | ||
| sessionToken: 'test-token', | ||
| }); | ||
|
|
||
| expect(picker).toBeInstanceOf(FilePicker); | ||
| }); |
Contributor
There was a problem hiding this comment.
This tests don't have much value. We don't want to test TypeScript functionalities.
src/specs/filePicker.spec.ts
Outdated
Comment on lines
+78
to
+87
| it('calls onClose when close() is called', () => { | ||
| const picker = new FilePicker({ | ||
| sessionToken: 'test-token', | ||
| onClose: mockOnClose, | ||
| }); | ||
|
|
||
| picker.closeFilePicker(); | ||
|
|
||
| expect(mockOnClose).toHaveBeenCalledTimes(1); | ||
| }); |
Contributor
There was a problem hiding this comment.
This tests should in a describe for the close method.
src/specs/filePicker.spec.ts
Outdated
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| describe('Initialization', () => { |
Contributor
There was a problem hiding this comment.
Suggested change
| describe('Initialization', () => { | |
| describe('.constructor', () => { |
src/specs/filePicker.spec.ts
Outdated
Comment on lines
+39
to
+55
| describe('when there are no options', () => { | ||
| it('uses default values', () => { | ||
| const picker = new FilePicker({ | ||
| sessionToken: 'test-token', | ||
| }); | ||
|
|
||
| expect(picker).toBeInstanceOf(FilePicker); | ||
| }); | ||
|
|
||
| it('accepts minimal required options', () => { | ||
| const picker = new FilePicker({ | ||
| sessionToken: 'test-token', | ||
| }); | ||
|
|
||
| expect(picker).toBeInstanceOf(FilePicker); | ||
| }); | ||
| }); |
Contributor
There was a problem hiding this comment.
This tests don't have much value, we can delete them. The constructor doesn't do much.
jrebocho
approved these changes
Mar 31, 2025
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(optional) Context
Checklist
Use the checklist below as a guide to ensure your PR is ready for review