diff options
author | Adrien Hopkins <ahopk127@my.yorku.ca> | 2022-07-17 14:39:16 -0500 |
---|---|---|
committer | Adrien Hopkins <ahopk127@my.yorku.ca> | 2022-07-17 14:39:16 -0500 |
commit | 051f6779be836cd9a5205f0c6527fd3a6f734ed1 (patch) | |
tree | 9ce9527d68d47f43d9502927d9b12cc3259b0c03 /src | |
parent | 6274c1cda8248f93075d99bd5ea46922fbec7207 (diff) |
Added a GUI test simulating unit conversion
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/sevenUnitsGUI/TabbedView.java | 21 | ||||
-rw-r--r-- | src/test/java/sevenUnitsGUI/TabbedViewTest.java | 60 |
2 files changed, 72 insertions, 9 deletions
diff --git a/src/main/java/sevenUnitsGUI/TabbedView.java b/src/main/java/sevenUnitsGUI/TabbedView.java index e3b5610..ca20216 100644 --- a/src/main/java/sevenUnitsGUI/TabbedView.java +++ b/src/main/java/sevenUnitsGUI/TabbedView.java @@ -159,15 +159,17 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView { // DIMENSION-BASED CONVERTER /** The combo box that selects dimensions */ - private final JComboBox<String> dimensionSelector; + final JComboBox<String> dimensionSelector; /** The panel for inputting values in the dimension-based converter */ - private final JTextField valueInput; + final JTextField valueInput; /** The panel for "From" in the dimension-based converter */ - private final SearchBoxList<String> fromSearch; + final SearchBoxList<String> fromSearch; /** The panel for "To" in the dimension-based converter */ - private final SearchBoxList<String> toSearch; + final SearchBoxList<String> toSearch; /** The output area in the dimension-based converter */ - private final JTextArea unitOutput; + final JTextArea unitOutput; + /** The button used for conversion */ + final JButton convertUnitButton; // EXPRESSION-BASED CONVERTER /** The "From" entry in the conversion panel */ @@ -261,10 +263,11 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView { outputPanel.add(this.valueInput, BorderLayout.CENTER); // conversion button - final JButton convertButton = new JButton("Convert"); - outputPanel.add(convertButton, BorderLayout.LINE_END); - convertButton.addActionListener(e -> this.presenter.convertUnits()); - convertButton.setMnemonic(KeyEvent.VK_ENTER); + this.convertUnitButton = new JButton("Convert"); + outputPanel.add(this.convertUnitButton, BorderLayout.LINE_END); + this.convertUnitButton + .addActionListener(e -> this.presenter.convertUnits()); + this.convertUnitButton.setMnemonic(KeyEvent.VK_ENTER); // conversion output this.unitOutput = new JTextArea(2, 32); diff --git a/src/test/java/sevenUnitsGUI/TabbedViewTest.java b/src/test/java/sevenUnitsGUI/TabbedViewTest.java new file mode 100644 index 0000000..a669773 --- /dev/null +++ b/src/test/java/sevenUnitsGUI/TabbedViewTest.java @@ -0,0 +1,60 @@ +/** + * Copyright (C) 2022 Adrien Hopkins + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ +package sevenUnitsGUI; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +/** + * Test for the TabbedView + * + * @since v0.4.0 + * @since 2022-07-17 + */ +class TabbedViewTest { + /** + * Simulates a unit conversion operation, and ensures it works properly. + * + * @since 2022-07-17 + */ + @Test + void testUnitConversion() { + // setup view + final var view = new TabbedView(); + final var presenter = view.getPresenter(); + presenter.setNumberDisplayRule(StandardDisplayRules.uncertaintyBased()); + presenter.setPrefixRepetitionRule( + DefaultPrefixRepetitionRule.NO_RESTRICTION); + presenter.setSearchRule(PrefixSearchRule.COMMON_PREFIXES); + presenter.setOneWayConversionEnabled(false); + presenter.setShowDuplicates(true); + + // prepare for unit conversion + view.masterPane.setSelectedIndex(0); + view.dimensionSelector.setSelectedItem("LENGTH"); + view.fromSearch.getSearchList().setSelectedValue("inch", true); + view.toSearch.getSearchList().setSelectedValue("metre", true); + view.valueInput.setText("250.0"); + + view.convertUnitButton.doClick(); + + // check result of conversion + assertEquals("250.0 inch = 6.350 metre", view.unitOutput.getText()); + } + +} |