Skip to content

Commit

Permalink
refactor(component): split historyItem
Browse files Browse the repository at this point in the history
This also adds `result` based on `historyItem`
  • Loading branch information
lemredd committed Jan 10, 2023
1 parent 4b1e85a commit 1febe7d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
23 changes: 0 additions & 23 deletions src/components/CalculatorContainer/HistoryContainer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,6 @@ describe("Component: CalculatorContainer/HistoryContainer", () => {
expect(historyListHiddenByDefault.exists()).toBeTruthy()
})

it("can display a history item properly", async() => {
const historyItem = {
"leftOperand": 1,
"operation": "+" as Operations,
"rightOperand": 1
}
const historyList = [ historyItem ]
const props = {
historyList
}
const wrapper = shallowMount(Component, { props })

// mock `isShowingHistoryList = true`
const wrapperInternals = wrapper.vm as any
wrapperInternals.isShowingHistoryList = true
await nextTick()

const historyListHiddenByDefault = wrapper.find(".history-list.hidden-by-default")
const [historyListItem1] = historyListHiddenByDefault.findAll("li.history-item")
const expectedTextValue = `${historyItem.leftOperand} ${historyItem.operation} ${ historyItem.rightOperand} =`
expect(historyListItem1.text()).toEqual(expectedTextValue)
})

it("should emit to revert evaluation to chosen history item", async() => {
const historyItem = {
"leftOperand": 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script setup lang="ts">
import type { HistoryItem } from "@/types/history"
import evaluate from "@/CalculatorContainer/helpers/evaluate"
import joinHistoryItemParts from "@/CalculatorContainer/HistoryContainer/helpers/joinHistoryItemParts"
interface Props {
historyItem: HistoryItem
}
const props = defineProps<Props>()
const result = evaluate(joinHistoryItemParts(props.historyItem))
</script>

<template>
<li class="history-item">
<h3 class="expression">
{{ joinHistoryItemParts(historyItem) }} =
</h3>
<h1 class="result">
{{ result }}
</h1>
</li>
</template>

0 comments on commit 1febe7d

Please sign in to comment.