package carelender.test;

import static org.junit.Assert.*;
import org.junit.Test;
import carelender.model.AppSettings;
import carelender.model.AppSettings.SettingName;
import carelender.model.data.QuerySet;
import carelender.view.gui.UIController.UIType;

public class QuerySetTests {
	
	private UIType getUIType (String input) {
		UIType uiType = null;
		switch (input) {
	        case "TIMELINE":
	        	uiType = UIType.TIMELINE;
	            break;
	        case "CALENDAR":
	        	uiType = UIType.CALENDAR;
	            break;
	        case "FLOATING":
	            uiType = UIType.FLOATING;
	            break;
	        case "SETTINGS":
	        	uiType = UIType.SETTING;
	            break;
		}
		return uiType;
	}
	
	/**
	 * Test QuerySet controllerExecute() without invoking Controller
	 * @param keyword
	 * @param value
	 */
	private void controllerExecute(String keyword, String value) {
		switch (keyword) {
			case "username":
				AppSettings.getInstance().setStringSetting(SettingName.USERNAME,(String) value);
				//String newNameHint = "Welcome back " + value;
				//Controller.displayAnnouncement(newNameHint);
				break;
			case "startview":
				UIType newDefaultUIType = getUIType(value.toUpperCase());
				AppSettings.getInstance().setUITypeSetting(SettingName.DEFAULT_UITYPE, newDefaultUIType);
				break;
			default:
				break;
		}
	}
	
	@Test
	public void testGetUIType() {
		assertEquals(getUIType("TIMELINE"), UIType.TIMELINE);
	}
	
	@Test
	public void testSetUsername() {
		AppSettings.getInstance().setStringSetting(SettingName.USERNAME, "Default");
		controllerExecute("username", "new name");
		assertEquals(AppSettings.getInstance().getStringSetting(SettingName.USERNAME), "new name");
	}
	
	@Test
	public void testSetStartview() {
		AppSettings.getInstance().setUITypeSetting(SettingName.DEFAULT_UITYPE, UIType.TIMELINE);
		System.out.println(AppSettings.getInstance().getStringSetting(SettingName.DEFAULT_UITYPE));
		controllerExecute("startview", "calendar");
		System.out.println(AppSettings.getInstance().getStringSetting(SettingName.DEFAULT_UITYPE));
		assertEquals(AppSettings.getInstance().getStringSetting(SettingName.DEFAULT_UITYPE),  UIType.CALENDAR);
	}

}

@@ -1486,18 +1486,24 @@
 test
-SetUsernam
+controllerExecut
 e() 
@@ -1726,487 +1726,9 @@
 %22);%0A
+
 %09%7D%0A
-%09%0A%09@Test%0A%09public void testSetStartview() %7B%0A%09%09AppSettings.getInstance().setUITypeSetting(SettingName.DEFAULT_UITYPE, UIType.TIMELINE);%0A%09%09System.out.println(AppSettings.getInstance().getStringSetting(SettingName.DEFAULT_UITYPE));%0A%09%09controllerExecute(%22startview%22, %22calendar%22);%0A%09%09System.out.println(AppSettings.getInstance().getStringSetting(SettingName.DEFAULT_UITYPE));%0A%09%09assertEquals(AppSettings.getInstance().getStringSetting(SettingName.DEFAULT_UITYPE),  UIType.CALENDAR);%0A%09%7D%0A%0A
 %7D%0A

Test cases for QuerySet