-
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.
- Loading branch information
Showing
16 changed files
with
2,789 additions
and
174 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
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,8 +1,12 @@ | ||
import React, { Component } from "react"; | ||
import ReactDOM from "react-dom"; | ||
|
||
import { Component } from "react"; | ||
import * as React from "react"; | ||
import Calculator from "./components/Calculator"; | ||
import { CalcStoreContext } from "./stores/CalculatorStore"; | ||
|
||
const App = () => <Calculator />; | ||
const App = ({ store }: { store: any }) => ( | ||
<CalcStoreContext.Provider value={store}> | ||
<Calculator /> | ||
</CalcStoreContext.Provider> | ||
); | ||
|
||
ReactDOM.render(<App />, document.getElementById("root")); | ||
export default App; |
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,126 @@ | ||
import * as React from "react"; | ||
import { mount } from "enzyme"; | ||
import Calculator from "../components/Calculator"; | ||
import calculatorStore, { CalculatorStore } from "../stores/CalculatorStore"; | ||
import { getSnapshot } from "mobx-state-tree"; | ||
import App from "../App"; | ||
|
||
describe("Calculator", () => { | ||
let store: ReturnType<typeof CalculatorStore.create>; | ||
beforeEach(() => { | ||
store = CalculatorStore.create({ | ||
recipeName: "Bread Baking Calculator", | ||
flours: [{ name: "Bread Flour", dosage: 100 }], | ||
ingredients: [{ name: "Salt", dosage: 3 }], | ||
waterPerc: 75, | ||
totalWeight: 800, | ||
starterPerc: 20, | ||
starterFlourIndex: 0, | ||
}); | ||
}); | ||
|
||
it("renders without crashing", () => { | ||
const app = mount(<App store={store} />); | ||
|
||
expect(app.find({ "data-testid": "recipeName" }).text()).toEqual( | ||
store.recipeName | ||
); | ||
}); | ||
|
||
it("can add other flours", () => { | ||
const app = mount(<App store={store} />); | ||
|
||
app | ||
.find({ "data-testid": "addAnotherFlour" }) | ||
.find("button") | ||
.simulate("click"); | ||
|
||
expect(store.flours.length).toBe(2); | ||
expect(app.find({ "data-testid": "flour" }).length).toEqual( | ||
store.flours.length | ||
); | ||
}); | ||
|
||
it("can add other ingredients", () => { | ||
const app = mount(<App store={store} />); | ||
|
||
app | ||
.find({ "data-testid": "addIngredient" }) | ||
.find("button") | ||
.simulate("click"); | ||
|
||
expect(store.ingredients.length).toBe(2); | ||
|
||
expect(app.find({ "data-testid": "ingredient" }).length).toEqual( | ||
store.ingredients.length | ||
); | ||
}); | ||
|
||
it("flours grams are recomputed properly", () => { | ||
const localStore = CalculatorStore.create({ | ||
recipeName: "Bread Baking Calculator", | ||
flours: [{ name: "Bread Flour", dosage: 100 }], | ||
ingredients: [{ name: "Salt", dosage: 3 }], | ||
waterPerc: 75, | ||
totalWeight: 800, | ||
starterPerc: 20, | ||
starterFlourIndex: 0, | ||
}); | ||
|
||
const app = mount(<App store={localStore} />); | ||
|
||
app | ||
.find({ "data-testid": "addAnotherFlour" }) | ||
.find("button") | ||
.simulate("click"); | ||
|
||
const previousValue = localStore.flourWeight( | ||
0, | ||
localStore.flours[0].dosage | ||
); | ||
localStore.replaceFlour(1, { name: "testFlour", dosage: 60 }); | ||
|
||
expect(localStore.flours.length).toEqual(2); | ||
expect(localStore.flourWeight(0, localStore.flours[0].dosage)).toBeLessThan( | ||
previousValue | ||
); | ||
|
||
localStore.removeFlour(1); | ||
expect(localStore.flourWeight(0, localStore.flours[0].dosage)).toEqual( | ||
previousValue | ||
); | ||
|
||
localStore.addIngredient(); | ||
localStore.replaceIngredient(1, { name: "ingredient1", dosage: 2 }); | ||
expect(localStore.flourWeight(0, localStore.flours[0].dosage)).toBeLessThan( | ||
previousValue | ||
); | ||
}); | ||
|
||
it("Can reflect the used flours in the levain selection", () => { | ||
const localStore = CalculatorStore.create({ | ||
recipeName: "Bread Baking Calculator", | ||
flours: [ | ||
{ name: "Bread Flour", dosage: 100 }, | ||
{ name: "Whole wheat", dosage: 10 }, | ||
], | ||
ingredients: [{ name: "Salt", dosage: 3 }], | ||
waterPerc: 75, | ||
totalWeight: 800, | ||
starterPerc: 20, | ||
starterFlourIndex: 0, | ||
}); | ||
|
||
const app = mount(<App store={localStore} />); | ||
|
||
const options = app | ||
.find({ "data-testid": "starterFlourSelect" }) | ||
.find("option"); | ||
|
||
expect(options.length).toEqual(2); | ||
expect(options.map((x) => x.text())).toEqual([ | ||
"Bread Flour", | ||
"Whole wheat", | ||
]); | ||
}); | ||
}); |
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.