Skip to content

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

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

import type { WineInstallation } from 'common/types'
import type { ParsedProtonShorctut } from 'common/types/proton_shorctuts'

import FinishStep from './FinishStep'

const shortcuts: ParsedProtonShorctut[] = [
  {
    name: 'Battle.net',
    executable:
      '/home/user/Games/Heroic/Prefixes/default/Battle.net/drive_c/Program Files (x86)/Battle.net/Battle.net.exe'
  },
  {
    name: 'Hearthstone',
    executable:
      '/home/user/Games/Heroic/Prefixes/default/Battle.net/drive_c/Program Files (x86)/Hearthstone/Hearthstone.exe'
  }
]

const proton = {
  bin: '/usr/bin/proton',
  name: 'GE-Proton',
  type: 'proton'
} satisfies WineInstallation

const meta = {
  title: 'Overlays/FinishStep',
  component: FinishStep,
  args: {
    appPlatform: 'Windows',
    gameUrl: '',
    setGameUrl: fn(),
    customUserAgent: '',
    setCustomUserAgent: fn(),
    launchFullScreen: false,
    setLaunchFullScreen: fn(),
    winePrefix: '/home/user/Games/Heroic/Prefixes/default/Battle.net',
    wineVersion: proton,
    selectedExe: shortcuts[0].executable,
    setSelectedExe: fn(),
    fileFilters: () => [{ name: 'Executables', extensions: ['exe'] }],
    launcherMode: true,
    presetTitle: 'Battle.net'
  },
  decorators: [
    (Story) => {
      window.platform = 'linux'
      window.api.getProtonShortcuts = async () => shortcuts
      return (
        <div style={{ width: 720, maxWidth: '95vw' }}>
          <Story />
        </div>
      )
    }
  ]
} satisfies Meta<typeof FinishStep>

export default meta

type Story = StoryObj<typeof meta>

export const LauncherExecutable: Story = {
  play: async ({ canvas }) => {
    await expect(canvas.getByText(/choose the launcher/i)).toBeInTheDocument()
    await expect(
      canvas.getByRole('button', { name: /Battle.net/ })
    ).toBeEnabled()
    await expect(
      canvas.getByRole('button', { name: /Hearthstone/ })
    ).toBeDisabled()
    await expect(canvas.getByText('Game executable')).toBeInTheDocument()
  }
}

export const ManualSelectionKeepsAllOptions: Story = {
  args: {
    launcherMode: false,
    presetTitle: undefined,
    selectedExe: shortcuts[0].executable
  },
  play: async ({ canvas }) => {
    await expect(
      canvas.getByRole('button', { name: /Hearthstone/ })
    ).toBeEnabled()
  }
}