package com.astoev.cave.survey.test.service.export;

import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;

import com.astoev.cave.survey.activity.home.SplashActivity;

import org.junit.Rule;
import org.junit.Test;

import static com.astoev.cave.survey.test.helper.Data.dataScreen;
import static com.astoev.cave.survey.test.helper.Data.xlsExport;
import static com.astoev.cave.survey.test.helper.Home.goHome;
import static com.astoev.cave.survey.test.helper.Survey.addLeg;
import static com.astoev.cave.survey.test.helper.Survey.createSurvey;
import static com.astoev.cave.survey.test.helper.Survey.openSurvey;

public class XlsExportTest {

    @Rule
    public ActivityTestRule<SplashActivity> activityRule = new ActivityTestRule<>(SplashActivity.class);


    @Test
    @LargeTest
    public void testCreateSurvey() {

//        clearDatabase();

        String surveyName = "xls" + System.currentTimeMillis();
        goHome();

        createSurvey(surveyName);
        openSurvey(surveyName);

        addLeg(1, 2);
        addLeg(1.2f, 2.2f);

        dataScreen();
        xlsExport();
    }
}

@@ -195,51 +195,425 @@
 ty;%0A
-%0Aimport org.junit.Rule;%0Aimport org.junit.Te
+import com.astoev.cave.survey.service.export.excel.ExcelExport;%0Aimport com.astoev.cave.survey.service.imp.ExcelImport;%0Aimport com.astoev.cave.survey.service.imp.LegData;%0Aimport com.astoev.cave.survey.service.imp.ProjectData;%0Aimport com.astoev.cave.survey.util.FileStorageUtil;%0A%0Aimport org.junit.After;%0Aimport org.junit.Rule;%0Aimport org.junit.Test;%0A%0Aimport java.io.File;%0Aimport java.io.IOException;%0Aimport java.util.Li
 st;%0A
@@ -1007,16 +1007,61 @@
 nSurvey;
+%0Aimport static org.junit.Assert.assertEquals;
 %0A%0Apublic
@@ -1201,16 +1201,89 @@
 ass);%0A%0A%0A
+    @After%0A    public void cleanUp() %7B%0A//        clearDatabase();%0A    %7D%0A%0A
     @Tes
@@ -1337,22 +1337,39 @@
 ey()
+ throws IOException
  %7B%0A%0A
-//
         
 clea
@@ -1368,33 +1368,38 @@
     
-clearDatabase();%0A%0A
+// create survey%0A 
        
+final
  Str
@@ -1469,17 +1469,16 @@
 Home();%0A
-%0A
         
@@ -1532,24 +1532,44 @@
 rveyName);%0A%0A
+        // add data%0A
         addL
@@ -1603,24 +1603,42 @@
 2f, 2.2f);%0A%0A
+        // export%0A
         data
@@ -1667,16 +1667,719 @@
 xport();
+%0A%0A        // verify%0A        List%3CFile%3E excelExportFiles = FileStorageUtil.listProjectFiles(null, ExcelExport.EXCEL_FILE_EXTENSION);%0A        File exportFile = excelExportFiles.stream().filter(file -%3E file.getName().startsWith(surveyName)).findFirst().get();%0A%0A        ProjectData data = ExcelImport.loadProjectData(exportFile);%0A%0A        // TODO options%0A        List%3CLegData%3E legs = data.getLegs();%0A        assertEquals(2, legs.size());%0A        assertLeg(legs.get(0), 1, 2);%0A        assertLeg(legs.get(1), 1.2f, 2.2f);%0A    %7D%0A%0A    private void assertLeg(LegData leg, float length, float azimuth) %7B%0A        assertEquals(length, leg.getLength(), 0.001);%0A        assertEquals(azimuth, leg.getAzimuth(), 0.001);
 %0A    %7D%0A%7D

prepare to check exported data