Creating CPU Temperature Icon which displays only when temperature is too high.

This commit is contained in:
Roland 2023-08-13 10:54:43 -06:00
parent e2535a49ee
commit 1e4644e15c
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
5 changed files with 77 additions and 19 deletions

View file

@ -1,6 +1,6 @@
import React from "react";
import {getByTestId, render, screen} from '@testing-library/react';
import {DisableDownloadsToggle} from "./Common";
import {getByTestId, queryByTestId, render, screen} from '@testing-library/react';
import {CPUTemperatureIcon, DisableDownloadsToggle} from "./Common";
import {StatusContext} from "../contexts/contexts";
import {startDownloads} from "../components/Common";
@ -54,3 +54,35 @@ test('DownloadsToggle is on if downloading is On', async () => {
const label = getByTestId(container, 'toggle-label');
expect(label).toHaveTextContent('Downloading Enabled');
});
test('CPUTemperatureIcon high', async () => {
const statusValue = {status: {cpu_info: {temperature: 80, high_temperature: 75, critical_temperature: 90}}};
const {container} = render(<StatusContext.Provider value={statusValue}>
<CPUTemperatureIcon/>
</StatusContext.Provider>);
const icon = getByTestId(container, 'cpuTemperatureIcon');
expect(icon).toHaveClass('thermometer');
expect(icon).toHaveClass('half');
});
test('CPUTemperatureIcon critical', async () => {
const statusValue = {status: {cpu_info: {temperature: 100, high_temperature: 75, critical_temperature: 90}}};
const {container} = render(<StatusContext.Provider value={statusValue}>
<CPUTemperatureIcon/>
</StatusContext.Provider>);
const icon = getByTestId(container, 'cpuTemperatureIcon');
expect(icon).toHaveClass('thermometer');
expect(icon).not.toHaveClass('half');
});
test('CPUTemperatureIcon hidden', async () => {
const statusValue = {status: {cpu_info: {temperature: 35, high_temperature: 75, critical_temperature: 90}}};
const {container} = render(<StatusContext.Provider value={statusValue}>
<CPUTemperatureIcon/>
</StatusContext.Provider>);
const icon = queryByTestId(container, 'cpuTemperatureIcon');
expect(icon).toBeNull();
});