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

chore: Add initial jest tests + code coverage #13

Merged
merged 14 commits into from
Jan 14, 2022

Conversation

bryphe-coder
Copy link
Contributor

@bryphe-coder bryphe-coder commented Jan 10, 2022

Depends on #8

  • Adds initial infra for running front-end tests (jest, ts-jest, jest.config.js, etc)

TODO:

  • Send up code coverage to codecov
  • Get coverage % threshold over bar

@bryphe-coder bryphe-coder self-assigned this Jan 10, 2022
Base automatically changed from bryphe/prototype/3-port-ui to main January 12, 2022 22:25
@codecov
Copy link

codecov bot commented Jan 12, 2022

Codecov Report

Merging #13 (a633886) into main (afc2fa3) will decrease coverage by 0.06%.
The diff coverage is 36.36%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #13      +/-   ##
==========================================
- Coverage   70.92%   70.86%   -0.07%     
==========================================
  Files          19       37      +18     
  Lines        1173     1311     +138     
  Branches        0        7       +7     
==========================================
+ Hits          832      929      +97     
- Misses        269      306      +37     
- Partials       72       76       +4     
Flag Coverage Δ
macos-latest ?
ubuntu-latest ?
unittest-go-macos-latest 63.51% <ø> (?)
unittest-go-ubuntu-latest 70.84% <ø> (?)
unittest-go-windows-latest 62.73% <ø> (?)
unittest-js 71.01% <36.36%> (?)
windows-latest ?
Impacted Files Coverage Δ
site/components/Navbar/index.tsx 100.00% <ø> (ø)
site/components/Page/index.tsx 0.00% <0.00%> (ø)
site/pages/_app.tsx 0.00% <0.00%> (ø)
site/pages/index.tsx 0.00% <0.00%> (ø)
site/test_helpers/index.tsx 100.00% <100.00%> (ø)
peer/conn.go 73.70% <0.00%> (-0.31%) ⬇️
site/components/Icons/Logo.tsx 100.00% <0.00%> (ø)
site/theme/theme.tsx 100.00% <0.00%> (ø)
site/theme/palettes.ts 100.00% <0.00%> (ø)
site/components/Button/SplitButton.tsx 89.47% <0.00%> (ø)
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update afc2fa3...a633886. Read the comment docs.

@bryphe-coder bryphe-coder marked this pull request as ready for review January 13, 2022 00:31
Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few minor nits!

jest.config.js Outdated Show resolved Hide resolved
})

it("is called when clicking option in pop-up", () => {
// Given
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we confident all tests will follow this pattern? What if there are subsequent given after a when?

I'm hesitant to say we should have these comments in all tests, because I'm not sure how else you'd write the logic anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a structure we've been using on the front-end (I believe @vapurrmaid introduced it) - in fact one of my first PRs had me add this to tests: https://github.com/coder/m/pull/9720/files#r697678791

Some tests have an extra given / when / then - @vapurrmaid would know some examples of that. Might be nice to have this documented in a front-end code standards page on Notion (our current standards are pretty empty)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://en.wikipedia.org/wiki/Given-When-Then#:~:text=Given%2DWhen%2DThen%20(GWT,to%20write%20down%20test%20cases.&text=When%20describes%20actions%20taken%20by,part%20of%20behavior%2Ddriven%20development.

^ This is a fairly standard pattern.

You're welcome to follow up whens and thens

ie:

// Given - all your givens

// When - thing

// Then - outcome

// When - other thing

// Then - other outcome

site/components/Icons/index.test.tsx Show resolved Hide resolved
import { render } from "../../test_helpers"
import { Page } from "./index"

describe("Page", () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably should have reviewed the other PR more thoroughly, but I'm hesitant to have a Page component, because if it were truly to be used on all pages, it would be idiomatic to put it in _app.tsx instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good point, that <Page /> was leftover before I moved to next. I'll port this over to our _app part of this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the <Page /> component here: 7b50658

I still left the Page folder to contain some helper stuff for the page (like the <Footer />) - but we can revisit that folder as we start building out the UI.

@bryphe-coder bryphe-coder merged commit 423611b into main Jan 14, 2022
@bryphe-coder bryphe-coder deleted the bryphe/chore/jest-tests branch January 14, 2022 02:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants