Skip to content

Commit

Permalink
refactor: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn committed Aug 30, 2024
1 parent 2b8721e commit 2a5b115
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/components/UpdateNotifier/UpdateNotifier.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useEffect } from 'react'
import { useContext, useEffect } from 'react'
import { useRegisterSW } from 'virtual:pwa-register/react'

import FarmhandContext from '../Farmhand/Farmhand.context'
Expand All @@ -20,13 +20,13 @@ const UpdateNotifier = () => {

handleGameUpdateAvailable(updateServiceWorker)

// NOTE: Ensure the game is updated when the user opens the game next.
// NOTE: This ensures the game is updated when the user next opensit.
window.addEventListener('beforeunload', () => {
updateServiceWorker(true)
})
}, [appNeedsUpdate, handleGameUpdateAvailable, updateServiceWorker])

return <></>
return null
}

export default UpdateNotifier
18 changes: 9 additions & 9 deletions src/game-logic/reducers/sellItem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe('sellItem', () => {
todaysNotifications: [],
revenue: 0,
todaysRevenue: 0,
valueAdjustments: { [carrotSeed.id]: 10 },
valueAdjustments: { [carrotSeed.id]: 1 },
},
testItem({ id: carrotSeed.id }),
3
Expand Down Expand Up @@ -173,16 +173,16 @@ describe('sellItem', () => {
todaysNotifications: [],
revenue: 0,
todaysRevenue: 0,
valueAdjustments: { [carrot.id]: 10 },
valueAdjustments: { [carrot.id]: 1 },
},
testItem({ id: carrot.id }),
3
)

expect(state.loanBalance).toEqual(62.5)
expect(state.money).toEqual(812.5)
expect(state.revenue).toEqual(712.5)
expect(state.todaysRevenue).toEqual(712.5)
expect(state.loanBalance).toEqual(96.25)
expect(state.money).toEqual(171.25)
expect(state.revenue).toEqual(71.25)
expect(state.todaysRevenue).toEqual(71.25)
})
})

Expand All @@ -199,7 +199,7 @@ describe('sellItem', () => {
todaysNotifications: [],
revenue: 0,
todaysRevenue: 0,
valueAdjustments: { [carrot.id]: 10 },
valueAdjustments: { [carrot.id]: 1 },
},
testItem({ id: carrot.id }),
3
Expand All @@ -211,8 +211,8 @@ describe('sellItem', () => {
})

test('sale is reduced based on remaining loan balance', () => {
expect(state.money).toEqual(848.5)
expect(state.todaysRevenue).toEqual(748.5)
expect(state.money).toEqual(173.5)
expect(state.todaysRevenue).toEqual(73.5)
})

test('payoff notification is shown', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/img/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ import goldIngot from './ores/gold-ingot.png'

// Cows
import rainbowCow from './animals/cows/rainbow-cow.png'
// NOTE: These need to be imported as dataUri strings because the image data is
// programmatically manipulated by the getCowImage utility function.
import cowVariation1 from './animals/cows/cow-variation-1.png?dataUri'
import cowVariation2 from './animals/cows/cow-variation-2.png?dataUri'
import cowVariation3 from './animals/cows/cow-variation-3.png?dataUri'
Expand Down
4 changes: 2 additions & 2 deletions src/shell/field.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ describe('field interaction', () => {

test('can enable fertilize mode', async () => {
const field = screen.getByTestId('field')
const [, carrotSeedButton] = screen.getAllByAltText(fertilizer.name)
const [, fertilizerButton] = screen.getAllByAltText(fertilizer.name)

expect(field).not.toHaveClass('fertilize-mode')
userEvent.click(carrotSeedButton)
userEvent.click(fertilizerButton)
expect(field).toHaveClass('fertilize-mode')
})
})
13 changes: 2 additions & 11 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { manifest } from './manifest'
// NOTE: See:
// - https://stackoverflow.com/a/78012267/470685
// - https://www.codu.co/articles/converting-an-image-to-a-data-uri-string-in-node-js-dznt83ha
const base64Loader = {
const dataUriLoader = {
name: 'dataUri-loader',
transform(_, id) {
const [path, query] = id.split('?')
Expand Down Expand Up @@ -63,7 +63,7 @@ const viteConfig = defineConfig({
})
},
},
base64Loader,
dataUriLoader,
],
resolve: {
alias: [
Expand All @@ -78,15 +78,6 @@ const viteConfig = defineConfig({
// NOTE: By default, Vite doesn't include shims for NodeJS.
global: {},
},
// NOTE: This makes Vite treat .js files as .jsx (for legacy support)
// See: https://stackoverflow.com/a/76458411/470685
optimizeDeps: {
esbuildOptions: {
loader: {
'.js': 'jsx',
},
},
},
})

const vitestConfig = vitestDefineConfig({
Expand Down

0 comments on commit 2a5b115

Please sign in to comment.