Skip to content

Commit

Permalink
test(intg): ensure entry and evaluation screens
Browse files Browse the repository at this point in the history
  • Loading branch information
lemredd committed Dec 20, 2022
1 parent 6dfd958 commit eb695b6
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/components/CalculatorContainer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import Component from "./CalculatorContainer.vue"
describe("Component: CalculatorContainer", () => {
it("can evaluate a proper expression", async() => {
const wrapper = mount(Component)
const calculatorScreen = wrapper.find(".evaluation-screen").element as HTMLInputElement
const evaluationScrn = wrapper.find(".evaluation-screen").element as HTMLInputElement
const entryScrn = wrapper.find(".entry-screen").element as HTMLInputElement

const wrapperInternals = wrapper.vm as any
const evaluateExpressionSpy = vitest.spyOn(wrapperInternals, "evaluateExpression")
Expand All @@ -14,23 +15,24 @@ describe("Component: CalculatorContainer", () => {
const digitalBtns = wrapper.findAll(".digital-button")
const [digital1Btn] = digitalBtns.filter(btn => btn.text() === "1")
await digital1Btn.trigger("click")
expect(calculatorScreen.value).toEqual("1")
expect(entryScrn.value).toEqual("1")
expect(evaluationScrn.value).toEqual("")

// Find the Addition button and click it
const operationalBtns = wrapper.findAll(".operational-button")
const [additionBtn] = operationalBtns.filter(btn => btn.text() === "+")
await additionBtn.trigger("click")
expect(calculatorScreen.value).toEqual("1 +")
expect(evaluationScrn.value).toEqual("1 +")

// click digit "1" button again
await digital1Btn.trigger("click")
expect(calculatorScreen.value).toEqual("1 + 1")
expect(entryScrn.value).toEqual("1")

// Find the Equal button and click it
// // Find the Equal button and click it
const evaluationBtns = wrapper.findAll(".evaluation-button")
const [equalBtn] = evaluationBtns.filter(btn => btn.text() === "=")
await equalBtn.trigger("click")
expect(calculatorScreen.value).toEqual("1 + 1 =")
expect(evaluationScrn.value).toEqual("1 + 1 =")

expect(evaluateExpressionSpy).toHaveReturnedWith(2)
})
Expand Down

0 comments on commit eb695b6

Please sign in to comment.