-
Notifications
You must be signed in to change notification settings - Fork 1
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 #209 from mberlanda/jest
Add jest support and ts unit tests
- Loading branch information
Showing
12 changed files
with
2,871 additions
and
101 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
113 changes: 113 additions & 0 deletions
113
...avascript/components/event/__tests__/__snapshots__/availability_progressbar.spec.tsx.snap
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,113 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`EventAvailabilityProgressbar when availability: 1, currentUser: {"canBook":true} 1`] = ` | ||
<div | ||
className="progress event-progress" | ||
> | ||
<div | ||
aria-valuemax={100} | ||
aria-valuemin={0} | ||
aria-valuenow={0} | ||
className="progress-bar progress-bar-danger" | ||
role="progressbar" | ||
style={ | ||
Object { | ||
"width": "99%", | ||
} | ||
} | ||
> | ||
<span | ||
className="sr-only" | ||
> | ||
99% | ||
</span> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`EventAvailabilityProgressbar when availability: 26, currentUser: {"canBook":true} 1`] = ` | ||
<div | ||
className="progress event-progress" | ||
> | ||
<div | ||
aria-valuemax={100} | ||
aria-valuemin={0} | ||
aria-valuenow={0} | ||
className="progress-bar progress-bar-warning" | ||
role="progressbar" | ||
style={ | ||
Object { | ||
"width": "74%", | ||
} | ||
} | ||
> | ||
<span | ||
className="sr-only" | ||
> | ||
74% | ||
</span> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`EventAvailabilityProgressbar when availability: 51, currentUser: {"canBook":true} 1`] = ` | ||
<div | ||
className="progress event-progress" | ||
> | ||
<div | ||
aria-valuemax={100} | ||
aria-valuemin={0} | ||
aria-valuenow={0} | ||
className="progress-bar progress-bar-info" | ||
role="progressbar" | ||
style={ | ||
Object { | ||
"width": "49%", | ||
} | ||
} | ||
> | ||
<span | ||
className="sr-only" | ||
> | ||
49% | ||
</span> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`EventAvailabilityProgressbar when availability: 76, currentUser: {"canBook":true} 1`] = ` | ||
<div | ||
className="progress event-progress" | ||
> | ||
<div | ||
aria-valuemax={100} | ||
aria-valuemin={0} | ||
aria-valuenow={0} | ||
className="progress-bar progress-bar-success" | ||
role="progressbar" | ||
style={ | ||
Object { | ||
"width": "24%", | ||
} | ||
} | ||
> | ||
<span | ||
className="sr-only" | ||
> | ||
24% | ||
</span> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`EventAvailabilityProgressbar when availability: 100, currentUser: {"canBook":false} 1`] = ` | ||
<div | ||
className="progress event-progress" | ||
/> | ||
`; | ||
|
||
exports[`EventAvailabilityProgressbar when availability: 100, currentUser: undefined 1`] = ` | ||
<div | ||
className="progress event-progress" | ||
/> | ||
`; |
136 changes: 136 additions & 0 deletions
136
app/javascript/components/event/__tests__/__snapshots__/icon.spec.tsx.snap
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,136 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`EventIcon when status: "available" and audience: "gold" 1`] = ` | ||
<div | ||
className="pull-right" | ||
> | ||
<Icon | ||
className="fa fa-calendar-check-o icon-green" | ||
message="Prenotabile" | ||
/> | ||
<Icon | ||
className="fa fa-trophy icon-yellow" | ||
message="Solo Corieristi Gold" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`EventIcon when status: "available" and audience: "preferred" 1`] = ` | ||
<div | ||
className="pull-right" | ||
> | ||
<Icon | ||
className="fa fa-calendar-check-o icon-green" | ||
message="Prenotabile" | ||
/> | ||
<Icon | ||
className="fa fa-star icon-yellow" | ||
message="Solo Corieristi Semper Fidelis" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`EventIcon when status: "available" and audience: "undefined" 1`] = ` | ||
<div | ||
className="pull-right" | ||
> | ||
<Icon | ||
className="fa fa-calendar-check-o icon-green" | ||
message="Prenotabile" | ||
/> | ||
<Icon | ||
className="hidden" | ||
message="" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`EventIcon when status: "fully_booked" and audience: "gold" 1`] = ` | ||
<div | ||
className="pull-right" | ||
> | ||
<Icon | ||
className="fa fa-calendar-times-o icon-red" | ||
message="Disponibilità Esaurita" | ||
/> | ||
<Icon | ||
className="fa fa-trophy icon-yellow" | ||
message="Solo Corieristi Gold" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`EventIcon when status: "fully_booked" and audience: "preferred" 1`] = ` | ||
<div | ||
className="pull-right" | ||
> | ||
<Icon | ||
className="fa fa-calendar-times-o icon-red" | ||
message="Disponibilità Esaurita" | ||
/> | ||
<Icon | ||
className="fa fa-star icon-yellow" | ||
message="Solo Corieristi Semper Fidelis" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`EventIcon when status: "fully_booked" and audience: "undefined" 1`] = ` | ||
<div | ||
className="pull-right" | ||
> | ||
<Icon | ||
className="fa fa-calendar-times-o icon-red" | ||
message="Disponibilità Esaurita" | ||
/> | ||
<Icon | ||
className="hidden" | ||
message="" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`EventIcon when status: "undefined" and audience: "gold" 1`] = ` | ||
<div | ||
className="pull-right" | ||
> | ||
<Icon | ||
className="hidden" | ||
message="" | ||
/> | ||
<Icon | ||
className="fa fa-trophy icon-yellow" | ||
message="Solo Corieristi Gold" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`EventIcon when status: "undefined" and audience: "preferred" 1`] = ` | ||
<div | ||
className="pull-right" | ||
> | ||
<Icon | ||
className="hidden" | ||
message="" | ||
/> | ||
<Icon | ||
className="fa fa-star icon-yellow" | ||
message="Solo Corieristi Semper Fidelis" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`EventIcon when status: "undefined" and audience: "undefined" 1`] = ` | ||
<div | ||
className="pull-right" | ||
> | ||
<Icon | ||
className="hidden" | ||
message="" | ||
/> | ||
<Icon | ||
className="hidden" | ||
message="" | ||
/> | ||
</div> | ||
`; |
25 changes: 25 additions & 0 deletions
25
app/javascript/components/event/__tests__/availability_progressbar.spec.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 { configure } from "enzyme"; | ||
import * as Adapter from "@wojtekmaj/enzyme-adapter-react-17"; | ||
configure({ adapter: new Adapter() }); | ||
import { EventAvailabilityProgressbar } from ".."; | ||
import { Game } from "../../../models"; | ||
|
||
describe("EventAvailabilityProgressbar", () => { | ||
[ | ||
{ availability: 100 }, | ||
{ availability: 100, currentUser: { canBook: false } }, | ||
{ availability: 1, currentUser: { canBook: true } }, | ||
{ availability: 26, currentUser: { canBook: true } }, | ||
{ availability: 51, currentUser: { canBook: true } }, | ||
{ availability: 76, currentUser: { canBook: true } }, | ||
].forEach((game: Partial<Game>) => { | ||
test(`when availability: ${game.availability}, currentUser: ${ | ||
game.currentUser && JSON.stringify(game.currentUser) | ||
}`, () => { | ||
const progressBar = new EventAvailabilityProgressbar({ | ||
game: game, | ||
}); | ||
expect(progressBar.render()).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
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,24 @@ | ||
import { configure } from "enzyme"; | ||
import * as Adapter from "@wojtekmaj/enzyme-adapter-react-17"; | ||
configure({ adapter: new Adapter() }); | ||
|
||
import { EventIcon } from ".."; | ||
|
||
describe("EventIcon", () => { | ||
const STATUSES = [undefined, "available", "fully_booked"]; | ||
const AUDIENCES = [undefined, "preferred", "gold"]; | ||
|
||
STATUSES.forEach((status: string) => { | ||
AUDIENCES.forEach((audience: string) => { | ||
test(`when status: "${status}" and audience: "${audience}"`, () => { | ||
const statusProp = status ? { status: status } : {}; | ||
const audienceProp = audience ? { audience: audience } : {}; | ||
const eventIcon = new EventIcon({ | ||
game: { ...statusProp, ...audienceProp }, | ||
}); | ||
|
||
expect(eventIcon.render()).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import * as ReactRailsUJS from "react_ujs"; | ||
// By default, this pack is loaded for server-side rendering. | ||
// It must expose react_ujs as `ReactRailsUJS` and prepare a require context. | ||
const componentRequireContext = require.context("components", true); | ||
const componentRequireContext = require.context( | ||
"components", | ||
true, | ||
/^(?!.*__tests__\/.*$).+\.[jt]sx?$/ | ||
); | ||
|
||
ReactRailsUJS.useContext(componentRequireContext); |
Oops, something went wrong.