-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
226 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | ||
|
||
name: Test Frontend | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [14.x, 16.x] | ||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/ | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
- run: npm ci | ||
- run: npm run build --if-present | ||
- run: npm test |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
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,18 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { Button } from "./Button"; | ||
|
||
describe("Button component", () => { | ||
it("fires onClick once when clicked", () => { | ||
const testFn = jest.fn(); | ||
|
||
render(<Button onClick={testFn}>Hello</Button>); | ||
|
||
const buttonElement = screen.getByText(/hello/i); | ||
|
||
expect(buttonElement).toBeInTheDocument(); | ||
|
||
buttonElement.click(); | ||
|
||
expect(testFn).toHaveBeenCalledTimes(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
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,61 @@ | ||
import { useState } from "react"; | ||
import { render, screen, waitFor } from "@testing-library/react"; | ||
import { Confirm } from "./Confirm"; | ||
|
||
describe("Confirm component", () => { | ||
const confirmFn = jest.fn(); | ||
const cancelFn = jest.fn(); | ||
|
||
const StatefulConfirm = () => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
return ( | ||
<> | ||
<button onClick={() => setIsOpen(true)}>Open Confirm</button> | ||
<Confirm | ||
isOpen={isOpen} | ||
close={() => setIsOpen(false)} | ||
onConfirm={confirmFn} | ||
onCancel={cancelFn} | ||
> | ||
Hello | ||
</Confirm> | ||
</> | ||
); | ||
}; | ||
|
||
it("opens and calls the confirm function", async () => { | ||
render(<StatefulConfirm />); | ||
|
||
const buttonElement = screen.getByText(/open confirm/i); | ||
|
||
buttonElement.click(); | ||
|
||
const confirmText = screen.getByText(/hello/i); | ||
const confirmButton = screen.getByText(/continue/i); | ||
|
||
await waitFor(() => expect(confirmText).toBeVisible()); | ||
|
||
confirmButton.click(); | ||
|
||
expect(confirmFn).toHaveBeenCalledTimes(1); | ||
expect(confirmText).not.toBeVisible(); | ||
}); | ||
|
||
it("opens and calls the cancel function", async () => { | ||
render(<StatefulConfirm />); | ||
const buttonElement = screen.getByText(/open confirm/i); | ||
|
||
buttonElement.click(); | ||
|
||
const confirmText = screen.getByText(/hello/i); | ||
const cancelButton = screen.getByText(/cancel/i); | ||
|
||
await waitFor(() => expect(confirmText).toBeVisible()); | ||
|
||
cancelButton.click(); | ||
|
||
expect(cancelFn).toHaveBeenCalledTimes(1); | ||
expect(confirmText).not.toBeVisible(); | ||
}); | ||
}); |
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 was deleted.
Oops, something went wrong.
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,69 @@ | ||
import { workplaceReducer } from "./WorkplaceState"; | ||
|
||
describe("WorkplaceState reducer", () => { | ||
const defaultState = workplaceReducer.init({}); | ||
|
||
const newFileState = { | ||
...defaultState, | ||
files: { | ||
...defaultState.files, | ||
"New.mo": "Hello there!", | ||
}, | ||
}; | ||
|
||
it("initializes correctly", () => { | ||
expect(defaultState.canisters).toEqual({}); | ||
expect(defaultState.selectedCanister).toBe(null); | ||
expect(defaultState.files).toEqual({ "Main.mo": "" }); | ||
expect(defaultState.selectedFile).toBe("Main.mo"); | ||
expect(defaultState.packages).toEqual({}); | ||
}); | ||
|
||
it("adds files", () => { | ||
const withNewFile = workplaceReducer.reduce(defaultState, { | ||
type: "saveFile", | ||
payload: { | ||
path: "New.mo", | ||
contents: "Hello there!", | ||
}, | ||
}); | ||
|
||
expect(withNewFile).toEqual(newFileState); | ||
}); | ||
|
||
it("selects files", () => { | ||
const withSelectedFile = workplaceReducer.reduce(newFileState, { | ||
type: "selectFile", | ||
payload: { | ||
path: "New.mo", | ||
}, | ||
}); | ||
|
||
expect(withSelectedFile.selectedFile).toBe("New.mo"); | ||
}); | ||
|
||
it("removes files", () => { | ||
const withFileRemoved = workplaceReducer.reduce(newFileState, { | ||
type: "deleteFile", | ||
payload: { | ||
path: "Main.mo", | ||
}, | ||
}); | ||
|
||
expect(withFileRemoved.files).toEqual({ "New.mo": "Hello there!" }); | ||
expect(withFileRemoved.selectedFile).toBe("New.mo"); | ||
}); | ||
|
||
it("renames files", () => { | ||
const withRenamedFile = workplaceReducer.reduce(defaultState, { | ||
type: "renameFile", | ||
payload: { | ||
path: "Main.mo", | ||
newPath: "Renamed.mo", | ||
}, | ||
}); | ||
|
||
expect(withRenamedFile.files).toEqual({ "Renamed.mo": "" }); | ||
expect(withRenamedFile.selectedFile).toBe("Renamed.mo"); | ||
}); | ||
}); |
Oops, something went wrong.