test unitaires qui se basent sur la fenêtre de résultats

This commit is contained in:
Thomas Rubini 2022-06-07 17:11:54 +02:00
parent 9e57c45497
commit 8c7cda026e
No known key found for this signature in database
GPG Key ID: C7D287C8C1CAC373
4 changed files with 106 additions and 3 deletions

View File

@ -8,12 +8,15 @@ public class TableEntry {
private String nom;
private String discipline;
private String thematique;
private String description;
private String niveau;
public TableEntry(Usage usage) {
nom = usage.getNom();
thematique = usage.getThematique().getNom();
discipline = usage.getDiscipline().getNom();
System.out.println("DESC="+usage.getDescription());
description = usage.getDescription();
niveau = usage.getNiveau().getNom();
}
@ -34,6 +37,15 @@ public class TableEntry {
this.discipline = discipline;
}
public String getThematique() {
return thematique;
}
public void setThematique(String thematique) {
this.thematique = thematique;
}
public String getDescription() {
return description;
}
@ -51,4 +63,36 @@ public class TableEntry {
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TableEntry that = (TableEntry) o;
if (nom != null ? !nom.equals(that.nom) : that.nom != null) return false;
if (discipline != null ? !discipline.equals(that.discipline) : that.discipline != null) return false;
if (description != null ? !description.equals(that.description) : that.description != null) return false;
return niveau != null ? niveau.equals(that.niveau) : that.niveau == null;
}
@Override
public int hashCode() {
int result = nom != null ? nom.hashCode() : 0;
result = 31 * result + (discipline != null ? discipline.hashCode() : 0);
result = 31 * result + (description != null ? description.hashCode() : 0);
result = 31 * result + (niveau != null ? niveau.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "TableEntry{" +
"nom='" + nom + '\'' +
", discipline='" + discipline + '\'' +
", description='" + description + '\'' +
", niveau='" + niveau + '\'' +
'}';
}
}

View File

@ -43,6 +43,8 @@ public class Controller implements Initializable {
DAOThematique daoThematique;
DAOUsage daoUsage;
Stage lastResultSceneOpened;
@FXML
private Pane stackPaneFrance;
@ -205,6 +207,7 @@ public class Controller implements Initializable {
try {
resultats.setScene(new Scene(FXMLLoader.load(getClass().getResource("/fr/univ_amu/iut/fResultat/FResultat.fxml"))));
resultats.show();
lastResultSceneOpened = resultats;
} catch (IOException e) {
e.printStackTrace();
}

View File

@ -23,13 +23,22 @@ public class DAOUsageTest implements DAOUsage{
List<Usage> usages = new ArrayList<>();
for( int i = 0; i < 42 ; i++){
Usage tmp = new Usage();
tmp.setNom(String.valueOf(i));
tmp.setNom("Usage n°"+ i);
tmp.setDiscipline(Discipline.Technologie);
tmp.setThematique(Thematique.CreationNumerique);
tmp.setNiveau(Niveau.Tous);
tmp.setDescription("je suis un commentaire tres long mais surtout tres utile, je sert a tester l'interface graphique et la mettre au bout de ses limtes");
tmp.setDescription("je suis un commentaire tres long mais surtout tres utile, je sert a tester l'interface graphique et la mettre au bout de ses limites");
usages.add(tmp);
}
Usage tmp = new Usage();
tmp.setNom("Usage spécial 1");
tmp.setDiscipline(Discipline.PhysiqueChimie);
tmp.setThematique(Thematique.ClasseInversee);
tmp.setNiveau(Niveau.PremierDegre);
tmp.setDescription("Un usage très simple, pour un test de recherche");
usages.add(tmp);
return usages;
}

View File

@ -1,11 +1,16 @@
package fr.univ_amu.iut;
import fr.univ_amu.iut.fResultat.TableEntry;
import fr.univ_amu.iut.model.Discipline;
import fr.univ_amu.iut.model.Niveau;
import fr.univ_amu.iut.model.Thematique;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TableView;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.stage.Window;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@ -69,7 +74,39 @@ public class AppTest {
}
@Test
void test_recherche(FxRobot robot) {
void search_should_open_window(FxRobot robot) {
Pane disciplinesPane = (Pane) stage.getScene().lookup("#discipline");
Pane thematiquesPane = (Pane) stage.getScene().lookup("#thematique");
Node recherche = stage.getScene().lookup("#recherche");
robot.clickOn(disciplinesPane.getChildren().get(1));
robot.clickOn(thematiquesPane.getChildren().get(0));
int windowsCount = Stage.getWindows().size();
robot.clickOn(recherche);
assertThat(Stage.getWindows().size()).isEqualTo(windowsCount+1);
}
@Test
void search_window_should_have_1_result(FxRobot robot) {
Pane disciplinesPane = (Pane) stage.getScene().lookup("#discipline");
Pane thematiquesPane = (Pane) stage.getScene().lookup("#thematique");
Node recherche = stage.getScene().lookup("#recherche");
robot.clickOn(disciplinesPane.getChildren().get(1));
robot.clickOn(thematiquesPane.getChildren().get(0));
int windowsCount = Stage.getWindows().size();
robot.clickOn(recherche);
Scene resultScene = Stage.getWindows().get(windowsCount).getScene();
TableView<?> table = (TableView<?>) resultScene.lookup("#table");
assertThat(table.getItems().size()).isEqualTo(1);
}
@Test
void search_window_result_should_be_shown(FxRobot robot) {
Pane disciplinesPane = (Pane) stage.getScene().lookup("#discipline");
Pane thematiquesPane = (Pane) stage.getScene().lookup("#thematique");
Node recherche = stage.getScene().lookup("#recherche");
@ -78,6 +115,16 @@ public class AppTest {
robot.clickOn(thematiquesPane.getChildren().get(0));
robot.clickOn(recherche);
Scene resultScene = Stage.getWindows().get(1).getScene();
TableView<TableEntry> table = (TableView<TableEntry>) resultScene.lookup("#table");
TableEntry entry = table.getItems().get(0);
assertThat(entry.getNom()).isEqualTo("Usage spécial 1");
assertThat(entry.getDescription()).isEqualTo("Un usage très simple, pour un test de recherche");
assertThat(entry.getDiscipline()).isEqualTo(Discipline.PhysiqueChimie.getNom());
assertThat(entry.getThematique()).isEqualTo(Thematique.ClasseInversee.getNom());
assertThat(entry.getNiveau()).isEqualTo(Niveau.PremierDegre.getNom());
}
}