Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: make http dependency more explicit
  • Loading branch information
Parkreiner committed May 12, 2024
commit 8dfe4229b159523f29db3c0dd3feaf48b067690e
6 changes: 5 additions & 1 deletion site/src/hooks/useClipboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
type UseClipboardResult,
COPY_FAILED_MESSAGE,
useClipboard,
HTTP_FALLBACK_DATA_ID,
} from "./useClipboard";

// execCommand is the workaround for copying text to the clipboard on HTTP-only
Expand Down Expand Up @@ -93,7 +94,10 @@ function setupMockClipboard(isSecure: boolean): SetupMockClipboardResult {
throw new Error("Failed to execute command 'copy'");
}

const dummyInput = document.querySelector("input[data-testid=dummy]");
const dummyInput = document.querySelector(
`input[data-testid=${HTTP_FALLBACK_DATA_ID}]`,
);

const inputIsFocused =
dummyInput instanceof HTMLInputElement &&
document.activeElement === dummyInput;
Expand Down
3 changes: 2 additions & 1 deletion site/src/hooks/useClipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { displayError } from "components/GlobalSnackbar/utils";

const CLIPBOARD_TIMEOUT_MS = 1_000;
export const COPY_FAILED_MESSAGE = "Failed to copy text to clipboard";
export const HTTP_FALLBACK_DATA_ID = "http-fallback";

export type UseClipboardInput = Readonly<{
textToCopy: string;
Expand Down Expand Up @@ -99,7 +100,7 @@ function simulateClipboardWrite(textToCopy: string): boolean {
const dummyInput = document.createElement("input");

// Have to add test ID to dummy element for mocking purposes in tests
dummyInput.setAttribute("data-testid", "dummy");
dummyInput.setAttribute("data-testid", HTTP_FALLBACK_DATA_ID);

// Using visually-hidden styling to ensure that inserting the element doesn't
// cause any content reflows on the page (removes any risk of UI flickers).
Expand Down