Skip to content

Commit

Permalink
update some mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
lstebner committed Jan 14, 2024
1 parent e56aae0 commit 05d3cc7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
24 changes: 10 additions & 14 deletions src/game-logic/reducers/processWeather.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { testCrop } from '../../test-utils'

jest.mock('../../data/maps')
import { shouldPrecipitateToday } from '../../utils'

import { processWeather } from './processWeather'

// TODO: Dependency-inject external constants rather than mocking them out.
jest.mock('../../data/maps')
jest.mock('../../utils', () => ({
...jest.requireActual('../../utils'),
shouldPrecipitateToday: jest.fn(),
}))

describe('processWeather', () => {
test('does not water plants when there is no precipitation', () => {
jest.resetModules()
jest.mock('../../constants', () => ({
PRECIPITATION_CHANCE: 0,
}))

const { processWeather } = jest.requireActual('./processWeather')
shouldPrecipitateToday.mockReturnValue(false)

const state = processWeather({
field: [[testCrop()]],
Expand All @@ -22,12 +23,7 @@ describe('processWeather', () => {
})

test('does water plants on a rainy day', () => {
jest.resetModules()
jest.mock('../../constants', () => ({
PRECIPITATION_CHANCE: 1,
}))

const { processWeather } = jest.requireActual('./processWeather')
shouldPrecipitateToday.mockReturnValue(true)

const state = processWeather({
field: [[testCrop()]],
Expand Down
30 changes: 15 additions & 15 deletions src/game-logic/reducers/purchaseField.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { testCrop } from '../../test-utils'
import { EXPERIENCE_VALUES } from '../../constants'
import { EXPERIENCE_VALUES, PURCHASEABLE_FIELD_SIZES } from '../../constants'

import { purchaseField } from './purchaseField'

Expand Down Expand Up @@ -27,15 +27,16 @@ describe('purchaseField', () => {

describe('field expansion', () => {
test('field expands without destroying existing data', () => {
jest.resetModules()
jest.mock('../../constants', () => ({
EXPERIENCE_VALUES: {},
PURCHASEABLE_FIELD_SIZES: new Map([
[1, { columns: 3, rows: 4, price: 1000 }],
]),
}))
const expectedField = []
const fieldSize = PURCHASEABLE_FIELD_SIZES.get(1)

const { purchaseField } = jest.requireActual('./purchaseField')
for (let y = 0; y < fieldSize.rows; y++) {
const row = []
for (let x = 0; x < fieldSize.columns; x++) {
row.push(null)
}
expectedField.push(row)
}

const { field } = purchaseField(
{
Expand All @@ -46,12 +47,11 @@ describe('purchaseField', () => {
},
1
)
expect(field).toEqual([
[testCrop(), null, null],
[null, testCrop(), null],
[null, null, null],
[null, null, null],
])

expectedField[0][0] = testCrop()
expectedField[1][1] = testCrop()

expect(field).toEqual(expectedField)
})
})
})

0 comments on commit 05d3cc7

Please sign in to comment.