Skip to content
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

Refactor: Convert Explainer component & test to TypeScript #1173

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { vi } from 'vitest';
import { vi, describe, it, expect } from 'vitest';

import Explainer from './Explainer';

Expand All @@ -18,9 +17,6 @@ describe('Explainer Component', () => {
render(
<Explainer {...props} />
);
expect(screen.getByTestId('explainer')).to.exist;
expect(screen.getByTestId('explainer')).toBeTruthy();
})



});
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import React, { useEffect } from "react";
import { useEffect } from "react";
import Button from "../Button/Button";

interface ExplainerStep {
number: number;
description: string;
}

interface ExplainerProps {
instruction: string;
button_label: string;
steps?: Array<ExplainerStep>;
timer: number | null;
onNext: () => void;
}

/**
* Explainer is an block view that shows a list of steps
* If the button has not been clicked, onNext will be called automatically after the timer expires (in milliseconds).
* If timer == null, onNext will only be called after the button is clicked.
*/
const Explainer = ({ instruction, button_label, steps = [], timer = null, onNext }) => {
const Explainer = ({ instruction, button_label, steps = [], timer = null, onNext }: ExplainerProps) => {

useEffect(() => {
if (timer != null) {
Expand Down Expand Up @@ -42,8 +55,14 @@ const Explainer = ({ instruction, button_label, steps = [], timer = null, onNext
);
};

// ExplainerItems renders an item in the explainer list, with optional icon or number
const ExplainerItem = ({ number = null, description, delay = 0 }) => (
interface ExplainerItemProps {
number: number | null;
description: string;
delay?: number;
}

/** ExplainerItems renders an item in the explainer list, with optional icon or number */
const ExplainerItem = ({ number = null, description, delay = 0 }: ExplainerItemProps) => (
<li
className="anim anim-fade-in-slide-left anim-speed-300"
style={{ animationDelay: delay + "ms" }}
Expand Down
Loading