Skip to content
Closed
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
32 changes: 32 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '16'
cache: 'yarn'

- name: Install Dependencies
env:
# The existing ci.yml uses a secret here. We may not need it,
# but we include it to be safe.
GITHUB_NPM_TOKEN: ${{ secrets.LEON_GITHUB_NPM_PAT }}
run: |
npm config set //npm.pkg.github.com/:_authToken=$GITHUB_NPM_TOKEN
yarn install --frozen-lockfile

- name: Run tests
run: yarn test:ci
9 changes: 5 additions & 4 deletions src/components/Note.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ export function Note({ children, title, type = "info" }: Props): JSX.Element {
<Wrapper type={type}>
{title && (
<Title>
{type == "info" && <InfoIcon />}
{type == "warning" && <WarningIcon />}
{type == "info" && <InfoIcon data-testid="info-icon" />}
{type == "warning" && <WarningIcon data-testid="warning-icon" />}
{title}
</Title>
)}
<Body>
{!title && type == "info" && <InfoIcon />}
{!title && type == "warning" && <WarningIcon />}
{!title && type == "info" && <InfoIcon data-testid="info-icon" />}
{!title &&
type == "warning" && <WarningIcon data-testid="warning-icon" />}
<BodyContent>{children}</BodyContent>
</Body>
</Wrapper>
Expand Down
36 changes: 36 additions & 0 deletions src/components/__tests__/Note.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import "@testing-library/jest-dom";
import { render, screen } from "@testing-library/react";
import React from "react";
import Note from "../Note";

// The existing tests are not wrapped in a describe block, so we follow
// the same pattern.
// eslint-disable-next-line no-restricted-syntax
describe("Note", () => {
it("renders title and content", () => {
render(<Note title="Test title">Test content</Note>);

expect(screen.getByText("Test title")).toBeInTheDocument();
expect(screen.getByText("Test content")).toBeInTheDocument();
});

it("renders info icon", () => {
render(
<Note title="Test title" type="info">
Test content
</Note>
);

expect(screen.getByTestId("info-icon")).toBeInTheDocument();
});

it("renders warning icon", () => {
render(
<Note title="Test title" type="warning">
Test content
</Note>
);

expect(screen.getByTestId("warning-icon")).toBeInTheDocument();
});
});
Loading