• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DaniSomoza / galactic-commander / 12728621970

11 Jan 2025 11:55PM UTC coverage: 47.963% (-4.1%) from 52.086%
12728621970

Pull #12

github

web-flow
Merge e784abf9e into a8e301a23
Pull Request #12: [fleets] Explore planets

214 of 913 branches covered (23.44%)

Branch coverage included in aggregate %.

154 of 505 new or added lines in 55 files covered. (30.5%)

10 existing lines in 9 files now uncovered.

1564 of 2794 relevant lines covered (55.98%)

3.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

16.67
/packages/frontend/src/components/unit-card/UnitCard.tsx
1
import Paper from '@mui/material/Paper'
2
import Box from '@mui/material/Box'
3
import Stack from '@mui/material/Stack'
4
import Typography from '@mui/material/Typography'
5
import Tooltip from '@mui/material/Tooltip'
6
import GroupIcon from '@mui/icons-material/Group'
7
import StarsIcon from '@mui/icons-material/Stars'
8
import RocketIcon from '@mui/icons-material/Rocket'
9
import FortIcon from '@mui/icons-material/Fort'
10

11
import { UnitType } from 'game-api-microservice/src/types/Unit'
12

13
import { useTranslations } from '../../store/TranslationContext'
14
import getImage from '../../utils/getImage'
15
import Image from '../image/Image'
16
import formatNumber from '../../utils/formatNumber'
17

18
type UnitCardProps = {
19
  showNameLabel?: boolean
20
  disableBorder?: boolean
21
  isAvailable: boolean
22
  unit: UnitType
23
  amount: number
24
  height?: number
25
  width?: number
26
  children?: JSX.Element | JSX.Element[]
27
}
28

29
const DEFAULT_HEIGHT = 200
1✔
30
const DEFAULT_WIDTH = 200
1✔
31

32
const unitIcon = {
1✔
33
  TROOP: GroupIcon,
34
  SPACESHIP: RocketIcon,
35
  DEFENSE: FortIcon
36
}
37

38
function UnitCard({
39
  showNameLabel = true,
×
40
  disableBorder = false,
×
41
  isAvailable,
42
  unit,
43
  amount,
44
  height = DEFAULT_HEIGHT,
×
45
  width = DEFAULT_WIDTH,
×
46
  children
47
}: UnitCardProps) {
48
  const { translate } = useTranslations()
×
49

50
  const UnitIconComponent = unitIcon[unit.type]
×
51

UNCOV
52
  return (
×
53
    <Box sx={{ position: 'relative' }}>
54
      <Paper variant={disableBorder ? 'elevation' : 'outlined'}>
×
55
        <Stack justifyContent="center" alignItems="center">
56
          <Image
57
            src={getImage(unit.name)}
58
            alt={translate(unit.name)}
59
            height={`${height}px`}
60
            width={`${width}px`}
61
            border={!disableBorder}
62
            disabled={!isAvailable}
63
          />
64

65
          {/* Unit name */}
66
          {showNameLabel && (
×
67
            <Box position={'absolute'} top={0} padding={1} maxWidth={width}>
68
              <Paper variant="outlined">
69
                <Stack
70
                  direction={'row'}
71
                  gap={0.5}
72
                  padding={0.4}
73
                  paddingLeft={0.6}
74
                  paddingRight={0.8}
75
                  alignItems={'center'}
76
                >
77
                  {unit.isHero && <StarsIcon fontSize="small" color="info" />}
×
78
                  <Typography variant="body1" fontSize={12} textAlign={'center'}>
79
                    {translate(unit.name)}
80
                  </Typography>
81
                </Stack>
82
              </Paper>
83
            </Box>
84
          )}
85

86
          {/* Amount of units */}
87
          <Box position={'absolute'} right={0} bottom={0} padding={1}>
88
            <Paper variant="outlined">
89
              <Tooltip
90
                title={translate('AMOUNT_OF_UNITS_TOOLTIP', formatNumber(amount, true))}
91
                arrow
92
              >
93
                <Stack
94
                  direction={'row'}
95
                  gap={0.5}
96
                  padding={0.4}
97
                  paddingLeft={0.6}
98
                  paddingRight={0.8}
99
                  alignItems={'center'}
100
                >
101
                  {unit.isHero && <StarsIcon fontSize="small" color="info" />}
×
102
                  <UnitIconComponent fontSize="small" />
103
                  <Typography fontSize={12}>{formatNumber(amount, true)}</Typography>
104
                </Stack>
105
              </Tooltip>
106
            </Paper>
107
          </Box>
108

109
          {/* additional labels */}
110
          {children}
111
        </Stack>
112
      </Paper>
113
    </Box>
114
  )
115
}
116

117
export default UnitCard
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc