UNPKG

@jeremyckahn/farmhand

Version:
92 lines (78 loc) • 3.24 kB
import { huggingMachine } from '../../data/items.js' import { generateCow } from '../../utils/generateCow.js' import { saveDataStubFactory } from '../../test-utils/stubs/saveDataStubFactory.js' import { INFINITE_STORAGE_LIMIT } from '../../constants.js' import { changeCowAutomaticHugState } from './changeCowAutomaticHugState.js' describe('changeCowAutomaticHugState', () => { describe('setting isUsingHuggingMachine to true', () => { test('sets isUsingHuggingMachine to true', () => { const cow = generateCow() const inputState = saveDataStubFactory({ cowInventory: [cow], inventory: [{ id: huggingMachine.id, quantity: 1 }], inventoryLimit: INFINITE_STORAGE_LIMIT, }) const { cowInventory: [{ isUsingHuggingMachine }], inventory, } = changeCowAutomaticHugState(inputState, cow, true) expect(isUsingHuggingMachine).toEqual(true) expect(inventory).toEqual([]) }) describe('there are no hugging machines in inventory', () => { test('no-ops', () => { const cow = generateCow() const inputState = saveDataStubFactory({ cowInventory: [cow], inventory: [], inventoryLimit: INFINITE_STORAGE_LIMIT, }) const state = changeCowAutomaticHugState(inputState, cow, true) expect(state).toBe(inputState) }) }) describe('isUsingHuggingMachine is already true', () => { test('no-ops', () => { const cow = generateCow({ isUsingHuggingMachine: true }) const inputState = saveDataStubFactory({ cowInventory: [cow], inventory: [{ id: huggingMachine.id, quantity: 1 }], inventoryLimit: INFINITE_STORAGE_LIMIT, }) const state = changeCowAutomaticHugState(inputState, cow, true) expect(state).toBe(inputState) }) }) }) describe('setting isUsingHuggingMachine to false', () => { test('sets isUsingHuggingMachine to false', () => { const cow = generateCow({ isUsingHuggingMachine: true }) const inputState = saveDataStubFactory({ cowInventory: [cow], inventory: [], inventoryLimit: INFINITE_STORAGE_LIMIT, }) const { cowInventory: [{ isUsingHuggingMachine }], inventory, } = changeCowAutomaticHugState(inputState, cow, false) expect(isUsingHuggingMachine).toEqual(false) expect(inventory).toEqual([{ id: huggingMachine.id, quantity: 1 }]) }) }) describe('re-applying a hugging machine after removing it', () => { test('applies the hugging machine again', () => { const cow = generateCow() let state = saveDataStubFactory({ cowInventory: [cow], inventory: [{ id: huggingMachine.id, quantity: 2 }], inventoryLimit: INFINITE_STORAGE_LIMIT, }) state = changeCowAutomaticHugState(state, state.cowInventory[0], true) state = changeCowAutomaticHugState(state, state.cowInventory[0], false) state = changeCowAutomaticHugState(state, state.cowInventory[0], true) expect(state.cowInventory[0].isUsingHuggingMachine).toEqual(true) expect(state.inventory).toEqual([{ id: huggingMachine.id, quantity: 1 }]) }) }) })