import { HEATER_PLUS_DEGREES_PER_TICK, ROOM_TEMPERATURE, useBiscuitOven, } from 'src/composables/biscuitOven'; import { test, expect } from 'vitest'; import { ref } from 'vue'; import { toggleTickAsync } from '../utils'; test('starts off at room temperature', () => { const tick = ref(false); const isOn = ref(false); const { currentTemperature } = useBiscuitOven(tick, isOn); expect(currentTemperature.value).toBe(ROOM_TEMPERATURE); }); test('does not heat up when off', async () => { const tick = ref(false); const isOn = ref(false); const { currentTemperature } = useBiscuitOven(tick, isOn); await toggleTickAsync(tick, 10); expect(currentTemperature.value).toBe(ROOM_TEMPERATURE); }); test('heats up when on', async () => { const tick = ref(false); const isOn = ref(true); const { currentTemperature } = useBiscuitOven(tick, isOn); const heatingUpTime = 10; await toggleTickAsync(tick, heatingUpTime); expect(currentTemperature.value).toBe( ROOM_TEMPERATURE + heatingUpTime * HEATER_PLUS_DEGREES_PER_TICK ); }); test('cools down to room temperature when turned off', async () => { const tick = ref(false); const isOn = ref(true); const { currentTemperature } = useBiscuitOven(tick, isOn); const heatingUpTime = 10; await toggleTickAsync(tick, heatingUpTime); expect(currentTemperature.value).toBe( ROOM_TEMPERATURE + heatingUpTime * HEATER_PLUS_DEGREES_PER_TICK ); isOn.value = false; const cooldownTime = 1000; await toggleTickAsync(tick, cooldownTime); expect(currentTemperature.value).toBe(ROOM_TEMPERATURE); });