// @flow
import React from 'react';
import { shallowWrappedComponent } from '../../../../../utils/tests';

import { Toast } from '../toast';
import type { ToastCentreProps } from './toast-centre.proptypes';
import { ToastCentre } from './index';

const DEFAULT_PROPS: ToastCentreProps = {
  messages: ['first', 'second'].map((message) => ({
    id: `toast-${message}`,
    text: `I am the ${message} toast`,
    timerDelay: 3000,
    onClose: () => {},
  })),
};

describe('ToastCentre', () => {
  it('renders a list of toasts', () => {
    const toastCentre = shallowWrappedComponent(
      <ToastCentre {...DEFAULT_PROPS} />,
    );

    toastCentre.find(Toast).forEach((toast, index) => {
      expect(toast.props()).toEqual({
        children: DEFAULT_PROPS.messages[index].text,
        id: DEFAULT_PROPS.messages[index].id,
        timerDelay: DEFAULT_PROPS.messages[index].timerDelay,
        onClose: DEFAULT_PROPS.messages[index].onClose,
      });
    });
  });
});
