Skip to content

Commit

Permalink
fix: reset tooltip message when unformatted code is change
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiensun committed Oct 27, 2023
1 parent 01b53e8 commit b293713
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
24 changes: 10 additions & 14 deletions src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// eslint-disable-next-line import/no-unassigned-import
import "@testing-library/jest-dom/vitest";
import { App } from "./App";
import { render, screen, waitFor } from "@testing-library/react";
import { render, screen } from "@testing-library/react";
import { userEvent } from "@testing-library/user-event";
import { afterEach, expect, test, vi } from "vitest";

Expand Down Expand Up @@ -52,9 +52,9 @@ test("happy path", async () => {
);

// Assert
waitFor(() =>
expect(screen.getByText(/copied to clipboard/iu)).toBeVisible(),
);
expect(
screen.getByRole("tooltip", { name: /copied to clipboard/iu }),
).toBeVisible();
});

test("on paste", async () => {
Expand All @@ -80,11 +80,9 @@ test("on paste", async () => {
await user.hover(screen.getByRole("button", { name: formattedCode }));

// Assert
waitFor(() =>
expect(
screen.getByRole("tooltip", { name: /copied to clipboard/iu }),
).toBeVisible(),
);
expect(
screen.getByRole("tooltip", { name: /copied to clipboard/iu }),
).toBeVisible();
});

test("on hover", async () => {
Expand Down Expand Up @@ -119,9 +117,7 @@ test("on hover", async () => {
await user.hover(formattedCode);

// Assert
waitFor(() =>
expect(
screen.getByRole("tooltip", { name: /copy to clipboard/iu }),
).toBeVisible(),
);
expect(
screen.getByRole("tooltip", { name: /copy to clipboard/iu }),
).toBeVisible();
});
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const App = (): JSX.Element => {
<div>
<UnformattedCode
copiedMessage={COPIED_MESSAGE}
resetTooltipMessage={resetTooltipMessage}
setFormattedCode={setFormattedCode}
setTooltipToCopied={setTooltipToCopied}
setUnformattedCode={setUnformattedCode}
Expand All @@ -51,7 +52,6 @@ export const App = (): JSX.Element => {
<div>
<FormattedCode
formattedCode={formattedCode}
resetTooltipMessage={resetTooltipMessage}
setTooltipToCopied={setTooltipToCopied}
tooltipMessage={tooltipMessage}
/>
Expand Down
1 change: 0 additions & 1 deletion src/formatted-code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { type JSX, useState } from "react";

type FormattedCodeProps = {
readonly formattedCode: string;
readonly resetTooltipMessage: () => void;
readonly setTooltipToCopied: () => void;
readonly tooltipMessage: string;
};
Expand Down
3 changes: 3 additions & 0 deletions src/unformatted-code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { type ChangeEvent, type ClipboardEvent, type JSX } from "react";

type UnformattedCodeProps = {
readonly copiedMessage: string;
readonly resetTooltipMessage: () => void;
readonly setFormattedCode: (code: string) => void;
readonly setTooltipToCopied: () => void;
readonly setUnformattedCode: (code: string) => void;
Expand All @@ -13,6 +14,7 @@ type UnformattedCodeProps = {

export const UnformattedCode = ({
copiedMessage,
resetTooltipMessage,
setFormattedCode,
setTooltipToCopied,
setUnformattedCode,
Expand All @@ -36,6 +38,7 @@ export const UnformattedCode = ({
}

setFormattedCode(formattedCode);
resetTooltipMessage();
};

const handlePaste = async (
Expand Down

0 comments on commit b293713

Please sign in to comment.