From dcb5f85403dcdfe5bc7b03d29034972ffcd58aec Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Thu, 10 Aug 2023 15:26:31 +0300 Subject: [PATCH] testing: add `HealthInfoSection` stories --- src/components/HealthInfoSection.stories.tsx | 70 ++++++++++++++++++++ src/components/HealthInfoSection.tsx | 2 +- 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/components/HealthInfoSection.stories.tsx diff --git a/src/components/HealthInfoSection.stories.tsx b/src/components/HealthInfoSection.stories.tsx new file mode 100644 index 00000000..4036e0fb --- /dev/null +++ b/src/components/HealthInfoSection.stories.tsx @@ -0,0 +1,70 @@ +import type { Meta, StoryObj } from '@storybook/react' + +import HealthInfoSection from './HealthInfoSection' + +const meta = { + title: 'Device Health/HealthInfoSection', + component: HealthInfoSection, + parameters: { + layout: 'centered', + }, + tags: ['autodocs'], +} satisfies Meta + +export default meta +type Story = StoryObj + +export const AllGoodStats: Story = { + args: { + usedStorage: 79 * 1024 * 1024 * 1024, + maxStorage: 100 * 1024 * 1024 * 1024, + usedRamMemory: 32 * 1024 * 1024 * 1024, + maxRamMemory: 64 * 1024 * 1024 * 1024, + cpuClockRate: 2.4, + networkLatency: 50, + }, +} + +export const StorageBad: Story = { + args: { + usedStorage: 80 * 1024 * 1024 * 1024, + maxStorage: 100 * 1024 * 1024 * 1024, + usedRamMemory: 32 * 1024 * 1024 * 1024, + maxRamMemory: 64 * 1024 * 1024 * 1024, + cpuClockRate: 2.5, + networkLatency: 50, + }, +} + +export const CpuBad: Story = { + args: { + usedStorage: 79 * 1024 * 1024 * 1024, + maxStorage: 100 * 1024 * 1024 * 1024, + usedRamMemory: 32 * 1024 * 1024 * 1024, + maxRamMemory: 64 * 1024 * 1024 * 1024, + cpuClockRate: 2.3, + networkLatency: 50, + }, +} + +export const RamBad: Story = { + args: { + usedStorage: 79 * 1024 * 1024 * 1024, + maxStorage: 100 * 1024 * 1024 * 1024, + usedRamMemory: 56 * 1024 * 1024 * 1024, + maxRamMemory: 64 * 1024 * 1024 * 1024, + cpuClockRate: 2.4, + networkLatency: 50, + }, +} + +export const LatencyBad: Story = { + args: { + usedStorage: 79 * 1024 * 1024 * 1024, + maxStorage: 100 * 1024 * 1024 * 1024, + usedRamMemory: 32 * 1024 * 1024 * 1024, + maxRamMemory: 64 * 1024 * 1024 * 1024, + cpuClockRate: 2.4, + networkLatency: 101, + }, +} diff --git a/src/components/HealthInfoSection.tsx b/src/components/HealthInfoSection.tsx index ebd88242..6144735e 100644 --- a/src/components/HealthInfoSection.tsx +++ b/src/components/HealthInfoSection.tsx @@ -26,7 +26,7 @@ const HealthInfoSection = (props: HealthInfoSectionProps) => { const usedStoragePercentage = (usedStorage / maxStorage) * 100 const usedRamMemoryPercentage = (usedRamMemory / maxRamMemory) * 100 - const cpuClockRatePercentage = cpuClockRate > 2.4 ? 100 : 0 + const cpuClockRatePercentage = cpuClockRate < 2.4 ? 100 : 0 const networkLatencyPercentage = networkLatency > 100 ? 100 : 0 return (