import React from 'react';
import '@testing-library/jest-dom'
import { render, fireEvent } from "@testing-library/react-native";
import { OrganismReadReferralCode } from './index';


describe('[Native] OrganismReadReferralCode', () => {
    const mockedAction = jest.fn();
    it('Render OrganismReadReferralCode', () => {
        let component = render(
            <OrganismReadReferralCode 
            headline= {'Invited by a friend?'}
            text = {'Enter their code for 250 points. If not “Skip” to continue. '}
            handleClick={mockedAction}
            skipFunction={mockedAction}
  />
        )
    });

    it('Clic skip button', () => {
        let component = render(
            <OrganismReadReferralCode 
                handleClick={mockedAction}
                skipFunction={mockedAction}
            />
        )
        const actionButton = component.getByTestId('skip');
        fireEvent.press(actionButton);
        expect(mockedAction).toBeCalled();
    });

    it('click redeem button and change text', () => {
        let referralCode = 'code'
        let component = render(
            <OrganismReadReferralCode 
                handleClick={mockedAction}
                skipFunction={mockedAction}
                referredCode={referralCode}
            />
        )
        const input = component.getByTestId('input');
        fireEvent.changeText(input,'query');


        const actionButton = component.getByTestId('redeem');
        fireEvent.press(actionButton);
        expect(mockedAction).toBeCalled();
    });
});