All files / components/TabComponent DownloadsTabComponent.jsx

100% Statements 8/8
100% Branches 0/0
100% Functions 4/4
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48            214x 1x     214x 1x 1x     214x 1x     214x                                                        
import React from "react";
import { Button } from "react-bootstrap";
import CourseDownloadsForm from "../Courses/CourseDownloadsForm";
import { toast } from "react-toastify";
 
export default function DownloadsTabComponent({ courseId, testIdPrefix }) {
  const onSuccessDownloadTriggered = () => {
    toast("Download successfully initiated.");
  };
 
  const handleSubmit = () => {
    console.log(`Frontend form submit action captured for course: ${courseId}`);
    onSuccessDownloadTriggered();
  };
 
  const downloadFormattedTeamsCsv = () => {
    window.open(`/api/csv/formattedteams?courseId=${courseId}`, "_blank");
  };
 
  return (
    <div data-testid={`${testIdPrefix}-downloadsTab`}>
      <CourseDownloadsForm
        downloadAction={handleSubmit}
        testIdPrefix={testIdPrefix}
      />
      <h4
        className="mt-4"
        data-testid={`${testIdPrefix}-downloads-teams-header`}
      >
        Teams
      </h4>
      <p data-testid={`${testIdPrefix}-downloads-teams-description`}>
        Every student&apos;s name and team, listed first by name and then by
        team, in side-by-side columns. Imported into Google Sheets, it only
        needs some formatting and splitting into two tabs to become a team
        sheet.
      </p>
      <Button
        variant="primary"
        onClick={downloadFormattedTeamsCsv}
        data-testid={`${testIdPrefix}-btn-download-formatted-teams-csv`}
      >
        Download Formatted Teams CSV
      </Button>
    </div>
  );
}