Skip to content

A games launcher for GOG, Amazon and Epic Games for Linux, Windows and macOS.

1.9 KB
Raw Blame
import { expect, fn, userEvent } from 'storybook/test'
import type { Meta, StoryObj } from '@storybook/react-vite'

import PresetInstallStep from './PresetInstallStep'

const meta = {
  title: 'Overlays/PresetInstallStep',
  component: PresetInstallStep,
  args: {
    appName: 'preset-battlenet',
    presetTitle: 'Battle.net',
    phase: 'downloading',
    downloadProgress: 42,
    onContinue: fn(),
    onRetry: fn(),
    onCheckAgain: fn(),
    onSelectManually: fn(),
    onCancel: fn(),
    canRetryInteractive: true,
    onRetryInteractive: fn()
  },
  render: (args) => (
    <div style={{ width: 720, maxWidth: '95vw' }}>
      <PresetInstallStep {...args} />
    </div>
  ),
  parameters: {
    docs: {
      description: {
        component:
          'Installer step used by launcher presets. It shows download progress, the live installer log, and recovery actions when the executable cannot be found.'
      }
    }
  }
} satisfies Meta<typeof PresetInstallStep>

export default meta

type Story = StoryObj<typeof meta>

export const Downloading: Story = {
  play: async ({ canvas }) => {
    await expect(
      canvas.getByText(/Downloading the installer/i)
    ).toBeInTheDocument()
    await expect(canvas.getByText('42%')).toBeInTheDocument()
  }
}

export const Running: Story = {
  args: { phase: 'running' }
}

export const NotFound: Story = {
  args: { phase: 'error', error: 'not-found' },
  play: async ({ canvas }) => {
    await expect(canvas.getByText(/Check again/i)).toBeInTheDocument()
  }
}

export const InstallerError: Story = {
  args: { phase: 'error', error: 'installer-exit-1' }
}

export const RetriesInteractively: Story = {
  args: { phase: 'error', error: 'not-found' },
  play: async ({ canvas, args }) => {
    await userEvent.click(
      canvas.getByRole('button', { name: /Run installer interactively/i })
    )
    await expect(args.onRetryInteractive).toHaveBeenCalled()
  }
}