-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #354 from ashik-75/work
add test for github issue and setup msw
- Loading branch information
Showing
9 changed files
with
662 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { rest } from "msw"; | ||
|
||
export const handlers = [ | ||
rest.post( | ||
"https://api.github.com/repos/:owner/:repo/issues", | ||
(_, res, ctx) => { | ||
return res( | ||
ctx.json({ | ||
title: "Created Issue", | ||
html_url: "https://github.com/owner/repo/issues/1", | ||
}) | ||
); | ||
} | ||
), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { setupServer } from "msw/node"; | ||
import { handlers } from "./handlers"; | ||
|
||
export const server = setupServer(...handlers); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { describe, expect, test } from "vitest"; | ||
import GithubIssue from "."; | ||
|
||
describe(`#GithubIssue`, () => { | ||
test("render component without a crash", () => { | ||
render(<GithubIssue />); | ||
}); | ||
|
||
test("Saved Issue", async () => { | ||
render(<GithubIssue />); | ||
|
||
const exists = await screen.findByText("Saved Issue"); | ||
expect(exists).toBeInTheDocument(); | ||
|
||
const downloadButton = screen.getByText(/Download csv/i); | ||
|
||
expect(downloadButton).toBeInTheDocument(); | ||
expect(downloadButton).not.toBeDisabled(); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
ui/src/pages/Automation/GithubIssue/components/DownloadCsv.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from "react"; | ||
import { SavedIssueType } from "pages/Automation/GithubIssue/types"; | ||
import { Button } from "antd"; | ||
import { saveAs } from "file-saver"; | ||
import { generateCsvData } from "pages/Automation/GithubIssue/utils/helper"; | ||
|
||
interface DownloadCsvProps { | ||
savedIssues: SavedIssueType[]; | ||
} | ||
|
||
const DownloadCsv: React.FC<DownloadCsvProps> = ({ savedIssues }) => { | ||
const downloadCSV = () => { | ||
const csvContent = generateCsvData(savedIssues); | ||
|
||
const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8" }); | ||
saveAs(blob, "data.csv"); | ||
}; | ||
return ( | ||
<Button disabled={savedIssues.length === 0} onClick={downloadCSV}> | ||
Download CSV | ||
</Button> | ||
); | ||
}; | ||
|
||
export default DownloadCsv; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.