package de.fitsample.timerecording.ui;

import javax.swing.table.TableModel;

import fit.Fixture;

/**
 * The Fixture for UI based FIT testing.
 * 
 * @author Ralf
 */
public class TimeRecordingUIFixture extends Fixture {

    /**
     * The UI to test.
     */
    private TimeRecordingUI timeRecordingUI;

    /**
     * Creates a TimeRecordingUIFicture.
     */
    public TimeRecordingUIFixture() {
        timeRecordingUI = new TimeRecordingUI();
        timeRecordingUI.pack();
        timeRecordingUI.setVisible(true);
        timeRecordingUI.toFront();
    }

    /**
     * Method for entering the <code>day</code> value.
     * 
     * @param tag the <code>day</code> value to enter.
     */
    public void day(String day) {
        timeRecordingUI.dayTextField.setText(day);
    }

    /**
     * Method for entering the <code>from</code> value.
     * 
     * @param from the <code>from</code> value to enter.
     */
    public void from(String from) {
        timeRecordingUI.fromTextField.setText(from);
    }

    /**
     * Method for entering the <code>to</code> value.
     * 
     * @param to the <code>to</code> value to enter.
     */
    public void to(String to) {
        timeRecordingUI.toTextField.setText(to);
    }

    /**
     * Method for pressing the <code>add</code> button.
     */
    public void add() {
        timeRecordingUI.addButton.doClick();
    }

    /**
     * @return the <code>working time</code> to check.
     */
    public double workingTime() {
        TableModel model = timeRecordingUI.timeRecordTable.getModel();
        Object value = model.getValueAt(model.getRowCount() - 1,
                TimeRecordingTableModel.WORKING_TIME_COLUMN);
        return ((Double) value).doubleValue();
    }

    /**
     * @return the <code>sum</code> to check.
     */
    public double sum() {
        TableModel model = timeRecordingUI.timeRecordTable.getModel();
        Object value = model.getValueAt(model.getRowCount() - 1,
                TimeRecordingTableModel.SUM_COLUMN);
        return ((Double) value).doubleValue();
    }

}
