generated from graasp/graasp-app-starter-ts-vite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add indoor temperature setting (#75)
- Loading branch information
Showing
9 changed files
with
152 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/modules/scenes/SimulationControlPanel/TemperatureControl.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { Slider, Stack, Typography } from '@mui/material'; | ||
|
||
import { SIMULATION_INDOOR_TEMPERATURE_CELCIUS } from '@/config/simulation'; | ||
import { useSimulation } from '@/context/SimulationContext'; | ||
|
||
export const TemperatureControl = (): JSX.Element => { | ||
const { t } = useTranslation('SIMULATION_CONTROL_PANEL', { | ||
keyPrefix: 'TEMPERATURES_CONTROL_PANEL', | ||
}); | ||
|
||
const { indoorTemperature, updateIndoorTemperature } = useSimulation(); | ||
const { MIN: minTemperature, MAX: maxTemperature } = | ||
SIMULATION_INDOOR_TEMPERATURE_CELCIUS; | ||
|
||
const formatTemperature = (value: number): string => `${value} °C`; | ||
|
||
return ( | ||
<Stack> | ||
<Typography variant="caption">{t('INDOOR_TEMPERATURE_LABEL')}</Typography> | ||
|
||
<Stack direction="row" alignItems="flex-start" spacing={2}> | ||
<Stack flexGrow={1}> | ||
<Slider | ||
value={indoorTemperature} | ||
onChange={(_, value) => { | ||
if (typeof value === 'number') { | ||
updateIndoorTemperature(value); | ||
} | ||
}} | ||
valueLabelDisplay="auto" | ||
min={minTemperature} | ||
max={maxTemperature} | ||
role="slider" | ||
aria-label="indoor-temperature" | ||
data-testid="indoor-temperature-slider" | ||
/> | ||
<Stack justifyContent="space-between" direction="row"> | ||
<Typography>{formatTemperature(minTemperature)}</Typography> | ||
<Typography>{formatTemperature(maxTemperature)}</Typography> | ||
</Stack> | ||
</Stack> | ||
{/* padding use to align with the slider */} | ||
<Typography | ||
data-testid="indoor-temperature-label" | ||
variant="caption" | ||
pt={0.5} | ||
> | ||
{formatTemperature(indoorTemperature)} | ||
</Typography> | ||
</Stack> | ||
</Stack> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
import { HousePage } from './HousePage'; | ||
|
||
test('changing indoor temperature should update the informations', async ({ | ||
page, | ||
}) => { | ||
const housePage = new HousePage(page); | ||
await housePage.goto(); | ||
|
||
const newValue = await housePage.setIndoorTemperature(10); | ||
await expect(housePage.indoorTemperatureInfo).toHaveText(newValue); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Locator, Page, expect } from '@playwright/test'; | ||
|
||
export const changeSlider = async ( | ||
page: Page, | ||
slider: Locator, | ||
targetPercentage: number, | ||
): Promise<void> => { | ||
await expect(slider).toBeVisible(); | ||
|
||
const sliderBoundingBox = await slider.boundingBox(); | ||
|
||
if (!sliderBoundingBox) { | ||
throw new Error('SliderBoundingBox is null'); | ||
} | ||
|
||
const startPoint = { | ||
x: sliderBoundingBox.x, | ||
y: sliderBoundingBox.y + sliderBoundingBox.height / 2, | ||
}; | ||
|
||
// Slide it to some endpoint determined by the target percentage | ||
const endPoint = { | ||
x: sliderBoundingBox.x + (sliderBoundingBox.width * targetPercentage) / 100, | ||
y: startPoint.y, | ||
}; | ||
|
||
await page.mouse.move(startPoint.x, startPoint.y); | ||
await page.mouse.down(); | ||
await page.mouse.move(endPoint.x, endPoint.y); | ||
await page.mouse.up(); | ||
}; |