Skip to content

Commit

Permalink
Remove references to document to de-flake unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje committed Feb 6, 2025
1 parent 1744e4d commit 025d63b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { useState } from 'react';
import { useRef, useState } from 'react';
import { SupersetTheme, t } from '@superset-ui/core';
import { Button, AntdSelect } from 'src/components';
import InfoTooltip from 'src/components/InfoTooltip';
Expand Down Expand Up @@ -46,6 +46,7 @@ export const EncryptedField = ({
db,
editNewDb,
}: FieldPropTypes) => {
const selectedFileInputRef = useRef<HTMLInputElement | null>(null);
const [uploadOption, setUploadOption] = useState<number>(
CredentialInfoOptions.JsonUpload.valueOf(),
);
Expand Down Expand Up @@ -152,9 +153,7 @@ export const EncryptedField = ({
{!fileToUpload && (
<Button
className="input-upload-btn"
onClick={() =>
document?.getElementById('selectedFile')?.click()
}
onClick={() => selectedFileInputRef.current?.click()}
>
{t('Choose File')}
</Button>
Expand All @@ -178,6 +177,7 @@ export const EncryptedField = ({
)}

<input
ref={selectedFileInputRef}
id="selectedFile"
accept=".json"
className="input-upload"
Expand All @@ -196,9 +196,9 @@ export const EncryptedField = ({
checked: false,
},
});
(
document.getElementById('selectedFile') as HTMLInputElement
).value = null as any;
if (selectedFileInputRef.current) {
selectedFileInputRef.current.value = null as any;
}
}}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ test('CSV form post', async () => {

// Select a file from the file dialog
const file = new File(['test'], 'test.csv', { type: 'text' });
const inputElement = document.querySelector('input[type="file"]');
const inputElement = screen.getByTestId('model-file-input');

if (inputElement) {
userEvent.upload(inputElement as HTMLElement, file);
Expand Down Expand Up @@ -680,7 +680,7 @@ test('Excel form post', async () => {

// Select a file from the file dialog
const file = new File(['test'], 'test.xls', { type: 'text' });
const inputElement = document.querySelector('input[type="file"]');
const inputElement = screen.getByTestId('model-file-input');

if (inputElement) {
userEvent.upload(inputElement as HTMLElement, file);
Expand Down Expand Up @@ -738,7 +738,7 @@ test('Columnar form post', async () => {

// Select a file from the file dialog
const file = new File(['test'], 'test.parquet', { type: 'text' });
const inputElement = document.querySelector('input[type="file"]');
const inputElement = screen.getByTestId('model-file-input');

if (inputElement) {
userEvent.upload(inputElement as HTMLElement, file);
Expand Down

0 comments on commit 025d63b

Please sign in to comment.