Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gui tests #139

Merged
merged 32 commits into from Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a0c1b5f
add Phone card handle
EugeneTeu Oct 17, 2019
18903a1
add handle for cards except schedule
EugeneTeu Oct 17, 2019
06f2c37
set up test fx, added handlers
EugeneTeu Oct 18, 2019
a4f699e
Merge branch 'master' of https://github.com/EugeneTeu/main into GUI-t…
EugeneTeu Oct 20, 2019
464162b
add panels handle
EugeneTeu Oct 20, 2019
98f2200
ported unit tests from AB4
EugeneTeu Oct 20, 2019
1716c0f
ported AB4 unit tests
EugeneTeu Oct 20, 2019
724b1bd
fix checkstyle
EugeneTeu Oct 20, 2019
7bfff68
add customer panel test
EugeneTeu Oct 22, 2019
30edf70
fixed checkstyle
EugeneTeu Oct 22, 2019
e30d01a
phone list and card unit tests
EugeneTeu Oct 22, 2019
ac0c115
fix checkstyle
EugeneTeu Oct 22, 2019
49da318
Merge branch 'master' of https://github.com/EugeneTeu/main into GUI-t…
EugeneTeu Oct 23, 2019
caddc34
remove help window test to fix travis
EugeneTeu Oct 23, 2019
d93e843
modify build.gradle
EugeneTeu Oct 23, 2019
761922f
changed travis yml file
EugeneTeu Oct 23, 2019
dc7ced0
debug
EugeneTeu Oct 23, 2019
87b6f4d
troubleshooting
EugeneTeu Oct 23, 2019
3fb4b8d
add xvfb buffer
EugeneTeu Oct 23, 2019
fbf7062
fixing 127 error
EugeneTeu Oct 23, 2019
9795fd2
add back perfomance test
EugeneTeu Oct 23, 2019
ad88785
doubled the time for performance test
EugeneTeu Oct 23, 2019
aeda9d2
Merge branch 'master' of https://github.com/EugeneTeu/main into GUI-t…
EugeneTeu Oct 24, 2019
6b75a90
need to fix failing Order display test
EugeneTeu Oct 24, 2019
aa8e9a8
OrderCard test
EugeneTeu Oct 24, 2019
1701bc6
fix checkstyle
EugeneTeu Oct 24, 2019
b8a88c7
remove person test
EugeneTeu Oct 24, 2019
80d7c6c
add tests for various Statistics module
EugeneTeu Oct 24, 2019
2fadd37
fix checkstyle
EugeneTeu Oct 24, 2019
28ea296
fix mutability issue in DateUtil
EugeneTeu Oct 25, 2019
6a570b9
fix checkstyle
EugeneTeu Oct 25, 2019
cb3a833
added profit test
EugeneTeu Oct 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .travis.yml
Expand Up @@ -2,6 +2,11 @@ language: java
matrix:
include:
- jdk: openjdk11
services:
- xvfb

before_script:
- export DISPLAY=:99.0

script: >-
./config/travis/run-checks.sh &&
Expand Down
88 changes: 87 additions & 1 deletion build.gradle
Expand Up @@ -106,7 +106,36 @@ tasks.coveralls {
onlyIf { System.env.'CI' }
}


task(guiTests)
task(nonGuiTests)

// Run `test` task if `guiTests` or `nonGuiTests` is specified
guiTests.dependsOn test
nonGuiTests.dependsOn test

task(allTests)

// `allTests` implies both `guiTests` and `nonGuiTests`
allTests.dependsOn guiTests
allTests.dependsOn nonGuiTests


test {

testLogging {
events TestLogEvent.FAILED, TestLogEvent.SKIPPED

// Prints the currently running test's name in the CI's build log,
// so that we can check if tests are being silently skipped or
// stalling the build.
if (System.env.'CI') {
events << TestLogEvent.STARTED
}
}

systemProperty 'testfx.setup.timeout', '60000'

testLogging {
events TestLogEvent.FAILED, TestLogEvent.SKIPPED

Expand All @@ -121,8 +150,48 @@ test {
jacoco {
destinationFile = new File("${buildDir}/jacoco/test.exec")
}

doFirst {
boolean runGuiTests = gradle.taskGraph.hasTask(guiTests)
boolean runNonGuiTests = gradle.taskGraph.hasTask(nonGuiTests)

if (!runGuiTests && !runNonGuiTests) {
runGuiTests = true
runNonGuiTests = true
}

if (runNonGuiTests) {
test.include 'seedu/address/**'
}

if (runGuiTests) {
//test.include 'systemtests/**'
test.include 'seedu/address/ui/**'
}

if (!runGuiTests) {
test.exclude 'seedu/address/ui/**'
}
}
}

task headless {
doLast {
println 'Setting headless mode properties.'
test {
systemProperties = [
'testfx.robot': 'glass',
'testfx.headless': 'true',
'prism.order': 'sw',
'prism.text': 't2k',
]
}
}
}

// Makes sure that headless properties are set before running tests
test.mustRunAfter headless

asciidoctor {
backends 'html5'
sourceDir 'docs'
Expand Down Expand Up @@ -161,4 +230,21 @@ task copyStylesheets(type: Copy) {
}
asciidoctor.dependsOn copyStylesheets

defaultTasks 'clean', 'test', 'coverage', 'asciidoctor'
task deployOfflineDocs(type: Copy) {
into('src/main/resources/docs')

from ("${asciidoctor.outputDir}/html5") {
include 'stylesheets/*'
include 'images/*'
include 'HelpWindow.html'
}
}


deployOfflineDocs.dependsOn asciidoctor
processResources.dependsOn deployOfflineDocs

defaultTasks 'clean', 'test', 'coverage'



4 changes: 2 additions & 2 deletions docs/team/johndoe.adoc
Expand Up @@ -50,9 +50,9 @@ _{you can add/remove categories in the list above}_
|_Given below are sections I contributed to the User Guide. They showcase my ability to write documentation targeting end-users._
|===

include::../UserGuide.adoc[tag=delete]
//include::../UserGuide.adoc[tag=delete]

include::../UserGuide.adoc[tag=dataencryption]
//include::../UserGuide.adoc[tag=dataencryption]

== Contributions to the Developer Guide

Expand Down
31 changes: 24 additions & 7 deletions src/main/java/seedu/address/statistic/DateUtil.java
Expand Up @@ -20,16 +20,33 @@ public static int extractYear(Order order) {
}

public static List<Calendar> getListOfYearMonth(StatsPayload statsPayload) {

List<Calendar> listOfYearMonth = new ArrayList<>();
Calendar startDate = statsPayload.getStartingDate();
int startingMonth = startDate.get(Calendar.MONTH);
int startingYear = startDate.get(Calendar.YEAR);
int startingDay = startDate.get(Calendar.DAY_OF_MONTH);
Calendar endDate = statsPayload.getEndingDate();


while (startDate.before(endDate)) {
//System.out.println(convertCalendarDateToString(startDate));
Calendar temp = (Calendar) startDate.clone();
listOfYearMonth.add(temp);
startDate.add(Calendar.MONTH, 1);
int endingMonth = endDate.get(Calendar.MONTH);
int endingYear = endDate.get(Calendar.YEAR);
int endingDay = endDate.get(Calendar.DAY_OF_MONTH);

Calendar startDateCloned = new Calendar.Builder()
.setDate(startingYear, startingMonth, startingDay)
.build();
Calendar endDateCloned = new Calendar.Builder()
.setDate(endingYear, endingMonth, endingDay)
.build();
while (startDateCloned.before(endDateCloned)) {
if (startDateCloned.get(Calendar.MONTH) == endDateCloned.get(Calendar.MONTH)
&& startDateCloned.get(Calendar.YEAR) == endDateCloned.get(Calendar.YEAR)) {
//same month same year i dont add
break;
} else {
Calendar temp = (Calendar) startDateCloned.clone();
listOfYearMonth.add(temp);
startDateCloned.add(Calendar.MONTH, 1);
}
}
listOfYearMonth.add(endDate);
return listOfYearMonth;
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/seedu/address/statistic/StatisticManager.java
Expand Up @@ -2,6 +2,8 @@

import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -16,7 +18,6 @@
import seedu.address.model.ReadOnlyDataBook;
import seedu.address.model.order.Order;
import seedu.address.model.order.Status;
import seedu.address.model.util.SampleDataUtil;


/**
Expand Down Expand Up @@ -63,6 +64,7 @@ public XYChart.Series<String, Number> calculateTotalRevenueOnCompletedGraph(Read

// returns a list of Months between starting and ending date.
List<Calendar> listOfMonth = DateUtil.getListOfYearMonth(statsPayload);

XYChart.Series<String, Number> series = new XYChart.Series<>();

// loops through the list of months, for each month, calculate the revenue for all orders in that month
Expand All @@ -81,12 +83,13 @@ public XYChart.Series<String, Number> calculateTotalCostOnCompletedGraph(ReadOnl
StatsPayload statsPayload) {
//filter the list of orders to be only the orders within the starting and ending date.
//dummy data here to test, should be passing orderBook straight in
List<Order> listOfFilteredOrders = getFilteredOrderListByDate(SampleDataUtil.getSampleOrderBook(),
List<Order> listOfFilteredOrders = getFilteredOrderListByDate(orderBook,
statsPayload)
.collect(Collectors.toList());

// returns a list of Months between starting and ending date.
List<Calendar> listOfMonth = DateUtil.getListOfYearMonth(statsPayload);
//listOfMonth.forEach(x -> System.out.println(x));
XYChart.Series<String, Number> series = new XYChart.Series<>();

// loops through the list of months, for each month, calculate the cost for all orders in that month
Expand Down Expand Up @@ -152,18 +155,21 @@ private XYChart.Data<String, Number> processCostByMonth(List<Order> listOfOrders
* Takes in an orderlist, calculates the profit of all orders in this month
*/
private static double calculateProfitByMonth(List<Order> orderList, Calendar month) {
DecimalFormat profitFormatter = new DecimalFormat("#.####");
profitFormatter.setRoundingMode(RoundingMode.CEILING);

double[] doubleProfitList =
StatisticManager.checkIfOrderIsPresent(orderList.stream())
.filter(currentOrder ->
DateUtil.extractMonth(currentOrder) == month.get(2)
DateUtil.extractMonth(currentOrder) == month.get(2)
&& DateUtil.extractYear(currentOrder) == month.get(1))
.map(currentOrder ->
MoneyUtil.convertToDouble(currentOrder.getPrice())
profitFormatter.format(MoneyUtil.convertToDouble(currentOrder.getPrice())
-
MoneyUtil.convertToDouble(currentOrder.getPhone().getCost()))
MoneyUtil.convertToDouble(currentOrder.getPhone().getCost())))
.collect(Collectors.toList())
.stream()
.mapToDouble(d -> d).toArray();
.mapToDouble(d -> Double.parseDouble(d)).toArray();
return StatUtils.sum(doubleProfitList);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/view/OrderListCard.fxml
Expand Up @@ -29,7 +29,7 @@
</HBox>
<FlowPane fx:id="tags" />
<Label fx:id="orderId" styleClass="cell_small_label" text="\$orderId" />
<Label fx:id="contactNumber" styleClass="cell_small_label" text="\$customerName" />
<Label fx:id="contactNumber" styleClass="cell_small_label" />
<Label fx:id="phoneId" styleClass="cell_small_label" text="\$phoneId" />
<Label fx:id="phoneName" styleClass="cell_small_label" text="\$phoneName" />
<Label fx:id="phoneColour" styleClass="cell_small_label" text="\$phoneColour" />
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/guitests/GuiRobot.java
Expand Up @@ -14,7 +14,7 @@
*/
public class GuiRobot extends FxRobot {

private static final int PAUSE_FOR_HUMAN_DELAY_MILLISECONDS = 250;
private static final int PAUSE_FOR_HUMAN_DELAY_MILLISECONDS = 50;
private static final int DEFAULT_WAIT_FOR_EVENT_TIMEOUT_MILLISECONDS = 5000;

private static final String PROPERTY_TESTFX_HEADLESS = "testfx.headless";
Expand Down
30 changes: 29 additions & 1 deletion src/test/java/guitests/guihandles/MainWindowHandle.java
@@ -1,24 +1,36 @@
package guitests.guihandles;

import guitests.guihandles.panels.CustomerListPanelHandle;
import guitests.guihandles.panels.OrderListPanelHandle;
import guitests.guihandles.panels.PhoneListPanelHandle;
import javafx.stage.Stage;

/**
* Provides a handle for {@code MainWindow}.
*/
public class MainWindowHandle extends StageHandle {

private final CustomerListPanelHandle customerListPanel;
private final PhoneListPanelHandle phoneListPanel;
private final OrderListPanelHandle orderListPanel;
private final ResultDisplayHandle resultDisplay;
private final CommandBoxHandle commandBox;
private final StatusBarFooterHandle statusBarFooter;
private final MainMenuHandle mainMenu;
private final TabPanelHandle tabPanel;

public MainWindowHandle(Stage stage) {
super(stage);

customerListPanel = new CustomerListPanelHandle(getChildNode(CustomerListPanelHandle.CUSTOMER_LIST_VIEW_ID));
phoneListPanel = new PhoneListPanelHandle(getChildNode(PhoneListPanelHandle.PHONE_LIST_VIEW));
orderListPanel = new OrderListPanelHandle(getChildNode(OrderListPanelHandle.ORDER_LIST_VIEW_ID));

resultDisplay = new ResultDisplayHandle(getChildNode(ResultDisplayHandle.RESULT_DISPLAY_ID));
commandBox = new CommandBoxHandle(getChildNode(CommandBoxHandle.COMMAND_INPUT_FIELD_ID));
statusBarFooter = new StatusBarFooterHandle(getChildNode(StatusBarFooterHandle.STATUS_BAR_PLACEHOLDER));
mainMenu = new MainMenuHandle(getChildNode(MainMenuHandle.MENU_BAR_ID));
tabPanel = new TabPanelHandle(getChildNode(TabPanelHandle.TAB_PANEL_FIELD_ID));

}

public ResultDisplayHandle getResultDisplay() {
Expand All @@ -33,8 +45,24 @@ public StatusBarFooterHandle getStatusBarFooter() {
return statusBarFooter;
}

public TabPanelHandle getTabPanel() {
return tabPanel;
}

public MainMenuHandle getMainMenu() {
return mainMenu;
}

public OrderListPanelHandle getOrderListPanel() {
return orderListPanel;
}
public CustomerListPanelHandle getCustomerListPanel() {
return customerListPanel;
}

public PhoneListPanelHandle getPhoneListPanel() {
return phoneListPanel;
}


}