{"size": 3510, "ext": "js", "max_stars_repo_path": "src/components/price-calculator.test.js", "max_stars_repo_name": "bebcovi/waldorfcamp-web", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/price-calculator.test.js", "max_issues_repo_name": "bebcovi/waldorfcamp-web", "max_issues_repo_issues_event_min_datetime": "2015-06-06T17:44:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-15T11:26:46.000Z", "max_forks_repo_path": "src/components/price-calculator.test.js", "max_forks_repo_name": "bebcovi/waldorfcamp-web", "max_forks_repo_forks_event_min_datetime": "2015-06-06T18:07:04.000Z", "max_forks_repo_forks_event_max_datetime": "2015-06-06T18:07:04.000Z"}
{"max_stars_count": null, "max_issues_count": 38, "max_forks_count": 1, "avg_line_length": 35.1, "max_line_length": 82, "alphanum_fraction": 0.5849002849}
// @flow
import React from 'react'
import { render, fireEvent } from '@testing-library/react'
import { ThemeProvider } from 'styled-components'
import { theme } from '../theme'
import PriceCalculator from './price-calculator'
import site from '../site'

const { price } = site

const renderWithTheme = element =>
  render(<ThemeProvider theme={theme}>{element}</ThemeProvider>)

describe.skip('price calculator', () => {
  describe('participation fee', () => {
    it.skip('applies discounts for children based on age and order', async () => {
      const { getByTestId } = renderWithTheme(
        <PriceCalculator price={price} days={14} />,
      )
      const countField = getByTestId('people-count')
      fireEvent.change(countField, { target: { value: '5' } })
      const peopleIndices = ['2', '3', '4', '5']
      peopleIndices.forEach(index => {
        const isChildCheckbox = getByTestId(`person-is-child-${index}`)
        fireEvent.change(isChildCheckbox, { target: { checked: true } })
        const ageField = getByTestId(`person-age-${index}`)
        fireEvent.change(ageField, {
          target: {
            value: {
              '2': '4',
              '3': '5',
              '4': '6',
              '5': '7',
            }[index],
          },
        })
      })
      const totalParticipationFee = Number(
        getByTestId('total-participation-fee').textContent,
      )
      expect(totalParticipationFee).toBe(
        price.participationFee +
          price.participationFee * 0 +
          price.participationFee * 0.5 +
          price.participationFee * 0.6 +
          price.participationFee * 0.2,
      )
    })

    it('applies discount for the 2nd twin', async () => {
      const { getByTestId } = renderWithTheme(
        <PriceCalculator price={price} days={14} />,
      )
      const countField = getByTestId('people-count')
      fireEvent.change(countField, { target: { value: '3' } })
      const peopleIndices = ['2', '3']
      peopleIndices.forEach(index => {
        const isChildCheckbox = getByTestId(`person-is-child-${index}`)
        fireEvent.click(isChildCheckbox)
        fireEvent.change(isChildCheckbox)
        const ageField = getByTestId(`person-age-${index}`)
        fireEvent.change(ageField, { target: { value: '6' } })
      })
      const totalParticipationFee = Number(
        getByTestId('total-participation-fee').textContent,
      )
      expect(totalParticipationFee).toBe(
        price.participationFee +
          price.participationFee +
          price.participationFee * 0.8,
      )
    })
  })

  describe('lunch', () => {
    it('applies discount for children under 13', () => {
      const DAYS = 14
      const { getByTestId } = renderWithTheme(
        <PriceCalculator price={price} days={DAYS} />,
      )
      const countField = getByTestId('people-count')
      fireEvent.change(countField, { target: { value: '3' } })
      fireEvent.change(getByTestId('person-is-child-1'), {
        target: { checked: true },
      })
      fireEvent.change(getByTestId('person-age-1'), { target: { value: '6' } })
      fireEvent.change(getByTestId('person-is-child-2'), {
        target: { checked: true },
      })
      fireEvent.change(getByTestId('person-age-2'), { target: { value: '13' } })
      expect(getByTestId('lunch-total')).toHaveTextContent(
        `Lunch: ${Math.round(
          (price.lunch + price.lunch + price.discounts.lunch.byAge[0].amount) *
            DAYS,
        )} €`,
      )
    })
  })
})
