Skip to content

Commit

Permalink
fix: invalid FL being sent when clicking in SimBrief button (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh authored Sep 29, 2023
1 parent 88e83c1 commit 090c33f
Show file tree
Hide file tree
Showing 5 changed files with 512 additions and 110 deletions.
7 changes: 6 additions & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
"@mach/database": "*",
"@sentry/nextjs": "^7.72.0"
},
"devDependencies": {
"@vitejs/plugin-react": "^4.1.0",
"jsdom": "^22.1.0"
},
"scripts": {
"dev": "next dev",
"build": "next build",
"pack": "next-on-pages",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"test": "vitest --watch=false"
},
"browserslist": {
"production": [
Expand Down
30 changes: 30 additions & 0 deletions packages/app/src/components/SimBriefButton/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { describe, test, expect } from 'vitest'
import SimBriefButton from './'
import { render, screen } from '@testing-library/react'

describe('SimBriefButton', () => {
test('It builds the correct URL for Simbrief', () => {
const flight = {
company: 'GLO',
flightNumber: 1827,
aircraft: {
icaoCode: 'B38M',
},
departureIcao: 'SBRF',
arrivalIcao: 'SBGR',
estimatedOffBlockTime: '0220',
route: 'DCT',
estimatedEnrouteMinutes: 125,
cruisingLevel: 380,
remarks: 'MACH',
}

render(<SimBriefButton flight={flight} />)

const button = screen.getByRole('link')

expect(button.getAttribute('href')).toEqual(
`http://www.simbrief.com/system/dispatch.php?airline=GLO&fltnum=1827&type=B38M&orig=SBRF&dest=SBGR&deph=02&depm=20&route=DCT&steh=2&stem=5&fl=38000&manualrmk=MACH`
)
})
})
16 changes: 14 additions & 2 deletions packages/app/src/components/SimBriefButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@ import { FC } from 'react'
import Button from '../Button'

type Props = {
flight: Flight
flight: Pick<
Flight,
| 'company'
| 'flightNumber'
| 'aircraft'
| 'departureIcao'
| 'arrivalIcao'
| 'estimatedOffBlockTime'
| 'route'
| 'estimatedEnrouteMinutes'
| 'cruisingLevel'
| 'remarks'
>
}

const VatsimButton: FC<Props> = ({ flight }) => {
Expand All @@ -18,7 +30,7 @@ const VatsimButton: FC<Props> = ({ flight }) => {
route: flight.route,
steh: Math.floor(flight.estimatedEnrouteMinutes / 60).toString(),
stem: (flight.estimatedEnrouteMinutes % 60).toString(),
fl: (flight.cruisingLevel ** 100).toString(),
fl: (flight.cruisingLevel * 100).toString(),
manualrmk: flight.remarks,
}

Expand Down
9 changes: 9 additions & 0 deletions packages/app/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'vitest/config'
import react from '@vitejs/plugin-react'

export default defineConfig({
plugins: [react()],
test: {
environment: 'jsdom',
},
})
Loading

0 comments on commit 090c33f

Please sign in to comment.