import * as React from 'react';
import * as sinon from 'sinon';
import PaymentMethodList from './PaymentMethodList';
import BaseDriver from '../../../test/BaseDriver';

export default class CashierPaymentsDriver extends BaseDriver {
  component: any;
  handleMethodChange: any;

  constructor() {
    super();
    this.handleMethodChange = sinon.spy();
  }

  when = {
    render: () => {
      this.component = this._render(<PaymentMethodList
        paymentMethods={[{value: 'payPal', label: 'PayPal'}]}
        selectedMethod="payPal"
        onPaymentMethodChanged={this.handleMethodChange}
      />);
      return this;
    },
    click: () => {
      this.get.input().simulate('click');
      return this;
    }
  };

  has = {
    root: () => this.get.root().exists(),
    item: () => this.get.item().length === 1,
  };

  get = {
    root: () => this.findByDataHook(`wcn-payment-method-list`),
    item: () => this.findByDataHook(`wcn-payment-method-item`),
    input: () => this.findByDataHook(`wcn-payment-method-item-input-payPal`),
    handleMethodChange: () => this.handleMethodChange,
  };
}
