diff --git a/src/components/ViewCity.tsx b/src/components/ViewCity.tsx index e531ef2..c9d59b3 100644 --- a/src/components/ViewCity.tsx +++ b/src/components/ViewCity.tsx @@ -15,24 +15,213 @@ export default function ViewCity(arg: ViewCityProp) { ) if (isLoading) { - return

Laster

+ return ( +
+ Laster... +
+ ) } + if (error) { - return

Det skjedde en feil

+ return ( +
+ Det skjedde en feil +
+ ) } + const firstTimeStep = result?.properties.timeseries[0] const windSpeed = firstTimeStep?.data.instant.details?.wind_speed const temperature = firstTimeStep?.data.instant.details?.air_temperature + const humidity = firstTimeStep?.data.instant.details?.relative_humidity const country = data.result[0]?.country + //Weather icon based on temperature + const getWeatherIcon = () => { + if (temperature === undefined) return "🌐" + if (temperature > 20) return "☀️" + if (temperature > 10) return "⛅" + if (temperature > 0) return "☁️" + if (temperature > -10) return "🌫️" + return "❄️" + } + return ( -
-
- Været i {arg.city}, {country} +
+
+
+ {getWeatherIcon()} +
+

+ {arg.city} +

+

+ {country} +

+
+
+ +
+ +
+
+

+ Temperatur +

+

+ {temperature ? `${Math.round(temperature * 10) / 10}°C` : "N/A"} +

+
+ +
+

+ Vind +

+

+ {windSpeed ? `${Math.round(windSpeed * 10) / 10} m/s` : "N/A"} +

+
+ +
+

+ Fuktighet +

+

+ {humidity ? `${Math.round(humidity)}%` : "N/A"} +

+
-

Temperatur: {temperature}°C

-

Vindhastighet: {windSpeed} m/s

-
) } diff --git a/tests/components/ViewCity.test.tsx b/tests/components/ViewCity.test.tsx index 309134d..4937ef3 100644 --- a/tests/components/ViewCity.test.tsx +++ b/tests/components/ViewCity.test.tsx @@ -34,7 +34,11 @@ describe("ViewCity", () => { { data: { instant: { - details: { air_temperature: 12.5, wind_speed: 4.2 }, + details: { + air_temperature: 12.5, + wind_speed: 4.2, + relative_humidity: 65.5, + }, }, }, }, @@ -43,11 +47,20 @@ describe("ViewCity", () => { }, }) + mockUseGetCityCoordinates.mockReturnValue({ + result: [{ latitude: 59.9, longitude: 10.7, country: "Norway" }], + }) + render() - expect(screen.getByText("Været i Oslo,")).toBeTruthy() - expect(screen.getByText("Temperatur: 12.5°C")).toBeTruthy() - expect(screen.getByText("Vindhastighet: 4.2 m/s")).toBeTruthy() + expect(screen.getByText("Oslo")).toBeTruthy() + expect(screen.getByText("Norway")).toBeTruthy() + expect(screen.getByText("12.5°C")).toBeTruthy() + expect(screen.getByText("4.2 m/s")).toBeTruthy() + expect(screen.getByText("66%")).toBeTruthy() + expect(screen.getByText("Temperatur")).toBeTruthy() + expect(screen.getByText("Vind")).toBeTruthy() + expect(screen.getByText("Fuktighet")).toBeTruthy() expect(mockUseGetCityCoordinates).toHaveBeenCalledWith({ cityName: "Oslo" }) expect(mockUseGetWeather).toHaveBeenCalledWith(59.9, 10.7) }) @@ -57,7 +70,7 @@ describe("ViewCity", () => { render() - expect(screen.getByText("Laster")).toBeTruthy() + expect(screen.getByText("Laster...")).toBeTruthy() }) it("should render an error message when the weather request fails", () => {