-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix/bug-snowflake-key-pair-auth-private-key-does-not-get-removed-upon… #36270
base: release
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import React from "react"; | ||
import "@testing-library/jest-dom/extend-expect"; | ||
import { act, render, screen, waitFor } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { Provider } from "react-redux"; | ||
import { combineReducers, createStore } from "redux"; | ||
import { ThemeProvider } from "styled-components"; | ||
import { reducer as formReducer } from "redux-form"; | ||
import { theme } from "constants/DefaultTheme"; // Adjust the path as necessary | ||
import { BrowserRouter as Router } from "react-router-dom"; | ||
import FilePickerControl, { RenderFilePicker } from "./FilePickerControl"; // Adjust the path as necessary | ||
import { Field, reduxForm } from "redux-form"; | ||
|
||
const rootReducer = combineReducers({ | ||
form: formReducer, | ||
}); | ||
|
||
const mockStore = createStore(rootReducer); | ||
|
||
const mockInput = { | ||
value: {}, | ||
onChange: jest.fn(), | ||
}; | ||
|
||
const mockProps = { | ||
input: mockInput, | ||
meta: {}, | ||
disabled: false, | ||
onChange: jest.fn(), | ||
}; | ||
|
||
const TestForm = reduxForm({ form: "testForm" })(() => ( | ||
<Field component={RenderFilePicker} name="filePicker" {...mockProps} /> | ||
)); | ||
|
||
const renderComponent = () => | ||
render( | ||
<Provider store={mockStore}> | ||
<Router> | ||
<ThemeProvider theme={theme}> | ||
<TestForm /> | ||
</ThemeProvider> | ||
</Router> | ||
</Provider> | ||
); | ||
|
||
describe("FilePickerControl Component", () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test("renders the component", () => { | ||
renderComponent(); | ||
expect(screen.getByText("Select")).toBeInTheDocument(); | ||
}); | ||
|
||
test("selects a file and triggers onChange", async () => { | ||
renderComponent(); | ||
|
||
const file = new File(["file contents"], "example.txt", { | ||
type: "text/plain", | ||
}); | ||
|
||
userEvent.click(screen.getByText("Select")); | ||
userEvent.click(screen.getByText("Browse")); | ||
|
||
const fileInput = document.querySelector('input[type="file"]') as HTMLInputElement; | ||
|
||
await act(async () => { | ||
if (fileInput) { | ||
console.log('File input found, uploading file...'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these console logs needed here? |
||
await userEvent.upload(fileInput, file); | ||
console.log('File uploaded.'); | ||
} else { | ||
throw new Error("File input not found"); | ||
} | ||
}); | ||
|
||
await waitFor(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also add a test case for when we remove the file from file picker? Asserting that input is blank? |
||
console.log('Waiting for file name to appear...'); | ||
expect(screen.getByText("example.txt")).toBeInTheDocument(); | ||
}); | ||
|
||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import * as React from "react"; | ||
import { useState } from "react"; | ||
import { useState, useEffect, useCallback } from "react"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these useEffect and useCallback imports needed? |
||
import styled from "styled-components"; | ||
import type { ControlProps } from "./BaseControl"; | ||
import BaseControl from "./BaseControl"; | ||
|
@@ -8,7 +8,6 @@ import type { SetProgress } from "@appsmith/ads-old"; | |
import { FilePickerV2, FileType } from "@appsmith/ads-old"; | ||
import type { WrappedFieldInputProps, WrappedFieldMetaProps } from "redux-form"; | ||
import { Field } from "redux-form"; | ||
import { useEffect, useCallback } from "react"; | ||
import { replayHighlightClass } from "globalStyles/portals"; | ||
import { Button, Modal, ModalBody, ModalContent } from "@appsmith/ads"; | ||
|
||
|
@@ -48,7 +47,7 @@ type RenderFilePickerProps = FilePickerControlProps & { | |
onChange: (event: any) => void; | ||
}; | ||
|
||
function RenderFilePicker(props: RenderFilePickerProps) { | ||
export function RenderFilePicker(props: RenderFilePickerProps) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Jagadeesh-90 Is this export needed here? As we are already exporting this whole component at the bottom |
||
const [isOpen, setIsOpen] = useState(false); | ||
const [appFileToBeUploaded, setAppFileToBeUploaded] = useState<{ | ||
file: File; | ||
|
@@ -84,6 +83,9 @@ function RenderFilePicker(props: RenderFilePickerProps) { | |
}); | ||
}; | ||
} | ||
else{ | ||
props.input?.onChange(""); | ||
} | ||
}, [appFileToBeUploaded]); | ||
|
||
return ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using as, can we define type for fileInput?