Skip to content

feat: implement open & close capabilities of file picker#8

Merged
jpmiguel merged 3 commits intomainfrom
eng-6787/file-picker
Mar 31, 2025
Merged

feat: implement open & close capabilities of file picker#8
jpmiguel merged 3 commits intomainfrom
eng-6787/file-picker

Conversation

@jpmiguel
Copy link
Copy Markdown
Contributor

(optional) Context

Checklist

Use the checklist below as a guide to ensure your PR is ready for review

  • 📝 PR has description (comment /describe to generate a description via the PR agent)
  • 🧪 PR includes tests
  • 🪵 PR includes logs
  • 📸 PR includes screenshots demonstrating the impact (eg: UI screenshots, stack diffs, perf improvements etc.)
  • 📜 Docs have been updated where relevant (eg: README.md, docs.stackone.com, hub.stackone.com etc.)

@jpmiguel jpmiguel requested a review from a team as a code owner March 26, 2025 15:12
@jpmiguel jpmiguel requested a review from jrebocho March 26, 2025 15:12
@jpmiguel jpmiguel changed the title chore: file picker v1 feat: Initial implementation of file-picker Mar 27, 2025
src/types.ts Outdated
containerId?: string;
sessionToken: string;
baseUrl?: string;
onFilesPick?: (data: unknown) => void;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
onFilesPick?: (data: unknown) => void;
onFilesPicked?: (data: unknown) => void;

this.#onCancel = onCancel ?? (() => {});
}

openFilePicker(win = window, rootElementId = 'root') {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
openFilePicker(win = window, rootElementId = 'root') {
open(win = window, rootElementId = 'root') {

this.#iframe.src = url;
}

closeFilePicker() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
closeFilePicker() {
close() {

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();
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the global stuff from the tests?

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);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests don't have much value. We don't want to test TypeScript functionalities.

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);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests should in a describe for the close method.

vi.restoreAllMocks();
});

describe('Initialization', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
describe('Initialization', () => {
describe('.constructor', () => {

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);
});
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests don't have much value, we can delete them. The constructor doesn't do much.

@jrebocho jrebocho changed the title feat: Initial implementation of file-picker feat: implement open & close capabilities of file picker Mar 27, 2025
@jpmiguel jpmiguel requested a review from jrebocho March 28, 2025 09:46
@jpmiguel jpmiguel merged commit a20b1c7 into main Mar 31, 2025
2 checks passed
@jpmiguel jpmiguel deleted the eng-6787/file-picker branch March 31, 2025 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants