package tests;
import javax.swing.JButton;
import javax.swing.JTextField;

import abbot.tester.JTextComponentTester;
import frames.MainFrame;
import junit.extensions.abbot.ComponentTestFixture;
import panels.ShowHistoryPanel;
import resources.Customer;
import resources.CustomersModel;

public class GUITestPayment extends ComponentTestFixture {
    
    public GUITestPayment(String name) {
    	super(name); 
    }
    
    public static void main(String[] args) {
    	GUITestPayment test = new GUITestPayment("Payment");
    	test.doTest();
    }

	private void doTest() {
		JTextComponentTester tester = new JTextComponentTester();
		MainFrame mainFrame = new MainFrame();
		mainFrame.setVisible(true);
		tester.waitForIdle();
		tester.actionClick(mainFrame.getMainPanel().getAddButton());
		tester.waitForIdle();
		tester.actionClick(mainFrame.getMainPanel().getPanelTable());
		tester.waitForIdle();
		tester.actionClick(mainFrame.getMainPanel().getShowHistoryButton());
		tester.waitForIdle();
		
		ShowHistoryPanel historyPanel = mainFrame.getHistoryPanel();
		JTextField textField = historyPanel.getTextField();
		JButton payButton = historyPanel.getPayButton();
		tester.actionEnterText(textField, "100");
		tester.waitForIdle();
		Customer customer = mainFrame.getModel().getCustomers().get(0);
		
		long time = System.nanoTime();
		for (int i = 0; i < 1000; i++) {
//			customer.purchase(100);
			tester.actionClick(payButton);
		}
		System.out.println(System.nanoTime() - time);
		time = System.nanoTime();
		for (int i = 0; i < 1000; i++) {
			int total = customer.getTotal();
		}
		System.out.println(System.nanoTime() - time);
	}
    
}
