From 025246bf14ec50c57130dabb760ddebd3314dc9e Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 11 Jan 2019 14:40:30 +0000 Subject: [PATCH] JAL-3184 unit test for Cancel in FeatureSettings --- test/jalview/gui/FeatureSettingsTest.java | 190 ++++++++++++++++++++++++++++- 1 file changed, 189 insertions(+), 1 deletion(-) diff --git a/test/jalview/gui/FeatureSettingsTest.java b/test/jalview/gui/FeatureSettingsTest.java index 6ddebf8..228d924 100644 --- a/test/jalview/gui/FeatureSettingsTest.java +++ b/test/jalview/gui/FeatureSettingsTest.java @@ -1,6 +1,11 @@ package jalview.gui; +import static jalview.gui.FeatureSettings.COLOUR_COLUMN; +import static jalview.gui.FeatureSettings.FILTER_COLUMN; +import static jalview.gui.FeatureSettings.SHOW_COLUMN; +import static jalview.gui.FeatureSettings.TYPE_COLUMN; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; @@ -11,6 +16,7 @@ import jalview.datamodel.features.FeatureMatcher; import jalview.datamodel.features.FeatureMatcherSet; import jalview.datamodel.features.FeatureMatcherSetI; import jalview.io.DataSourceType; +import jalview.io.FileFormat; import jalview.io.FileLoader; import jalview.schemes.FeatureColour; import jalview.util.matcher.Condition; @@ -33,7 +39,7 @@ public class FeatureSettingsTest public void testSaveLoad() throws IOException { AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( - ">Seq1\nACDEFGHIKLM", DataSourceType.PASTE); + ">Seq1\nACDEFGHIKLM", DataSourceType.PASTE, FileFormat.Fasta); SequenceI seq1 = af.getViewport().getAlignment().getSequenceAt(0); /* @@ -188,4 +194,186 @@ public class FeatureSettingsTest }); seq.addSequenceFeature(sf); } + + /** + * Test of the behaviour of the Show / Hide checkbox + */ + @Test(groups = "Functional") + public void testHideShow() + { + AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( + ">Seq1\nACDEFGHIKLM", DataSourceType.PASTE, FileFormat.Fasta); + SequenceI seq1 = af.getViewport().getAlignment().getSequenceAt(0); + seq1.addSequenceFeature( + new SequenceFeature("type1", "", 1, 4, "group1")); + + FeatureRenderer fr = af.getFeatureRenderer(); + fr.setColour("type1", new FeatureColour(Color.red)); + + af.showSeqFeatures_actionPerformed(null); + FeatureSettings dialog = new FeatureSettings(af); + + assertTrue(fr.getDisplayedFeatureTypes().contains("type1")); + + /* + * check the table has one row, for type1, visible, no filter, red + */ + assertEquals(dialog.table.getRowCount(), 1); + assertEquals(dialog.table.getColumnCount(), 4); + assertEquals(dialog.table.getModel().getValueAt(0, TYPE_COLUMN), + "type1"); + FeatureColourI colour = (FeatureColourI) dialog.table.getModel() + .getValueAt(0, COLOUR_COLUMN); + assertTrue(colour.isSimpleColour()); + assertEquals(colour.getColour(), Color.red); + FeatureMatcherSetI filter = (FeatureMatcherSetI) dialog.table.getModel() + .getValueAt(0, FILTER_COLUMN); + assertTrue(filter.isEmpty()); + assertEquals(dialog.table.getModel().getValueAt(0, SHOW_COLUMN), + Boolean.TRUE); + + /* + * set feature type to hidden by clicking the checkbox in column 4, + * and verify that now no feature types are displayed + */ + dialog.table.setValueAt(Boolean.FALSE, 0, SHOW_COLUMN); + assertTrue(fr.getDisplayedFeatureTypes().isEmpty()); + + /* + * set feature type back to visible by clicking the checkbox in column 4, + * and verify that now the feature type is displayed + */ + dialog.table.setValueAt(Boolean.TRUE, 0, SHOW_COLUMN); + assertTrue(fr.getDisplayedFeatureTypes().contains("type1")); + } + + /** + * Test Cancel resets any changes made + */ + @Test(groups = "Functional") + public void testCancel() + { + AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( + ">Seq1\nACDEFGHIKLM", DataSourceType.PASTE, FileFormat.Fasta); + SequenceI seq1 = af.getViewport().getAlignment().getSequenceAt(0); + seq1.addSequenceFeature( + new SequenceFeature("type1", "", 1, 4, "group1")); + seq1.addSequenceFeature( + new SequenceFeature("type2", "", 1, 4, "group2")); + + /* + * set type1: red, filter 'Label Contains metal' + * type2: variable colour red:blue, no filter + */ + FeatureRenderer fr = af.getFeatureRenderer(); + fr.setColour("type1", new FeatureColour(Color.red)); + fr.setColour("type2", new FeatureColour(Color.red, Color.blue, 0f, 1f)); + FeatureMatcherSetI f = new FeatureMatcherSet(); + f.and(FeatureMatcher.byLabel(Condition.Contains, "metal")); + fr.setFeatureFilter("type1", f); + + af.showSeqFeatures_actionPerformed(null); + FeatureSettings dialog = new FeatureSettings(af); + + assertTrue(fr.getDisplayedFeatureTypes().contains("type1")); + assertTrue(fr.getDisplayedFeatureTypes().contains("type2")); + + /* + * check the table has two rows, for type1 and type2 + * note type2 is shown first; the initial ordering is 'random' as driven by + * the Set of feature groups for the sequence + */ + assertEquals(dialog.table.getRowCount(), 2); + assertEquals(dialog.table.getColumnCount(), 4); + + assertEquals(dialog.table.getModel().getValueAt(0, TYPE_COLUMN), + "type2"); + FeatureColourI colour = (FeatureColourI) dialog.table.getModel() + .getValueAt(0, COLOUR_COLUMN); + assertFalse(colour.isSimpleColour()); + assertEquals(colour.getMinColour(), Color.red); + assertEquals(colour.getMaxColour(), Color.blue); + FeatureMatcherSetI filter = (FeatureMatcherSetI) dialog.table.getModel() + .getValueAt(0, FILTER_COLUMN); + assertTrue(filter.isEmpty()); + assertEquals(dialog.table.getModel().getValueAt(0, SHOW_COLUMN), + Boolean.TRUE); + + assertEquals(dialog.table.getModel().getValueAt(1, TYPE_COLUMN), + "type1"); + colour = (FeatureColourI) dialog.table.getModel().getValueAt(1, + COLOUR_COLUMN); + assertTrue(colour.isSimpleColour()); + assertEquals(colour.getColour(), Color.red); + filter = (FeatureMatcherSetI) dialog.table.getModel().getValueAt(1, + FILTER_COLUMN); + assertFalse(filter.isEmpty()); + assertEquals(dialog.table.getModel().getValueAt(1, SHOW_COLUMN), + Boolean.TRUE); + + /* + * Make some changes: + * - set type1 to hidden by clicking the checkbox in column 4 + * - change type2 to plain colour green + * We can do these by setting values in the table model - + * updateFeatureRenderer then updates visibility and colour + */ + dialog.table.setValueAt(Boolean.FALSE, 1, SHOW_COLUMN); + dialog.table.setValueAt(new FeatureColour(Color.green), 0, + COLOUR_COLUMN); + + /* + * - remove the filter on type1 + * - set a filter on type2 + * We have to do this directly on FeatureRendererModel (as done in the + * application from FeatureTypeSettings) + */ + fr.setFeatureFilter("type1", null); + fr.setFeatureFilter("type2", + FeatureMatcherSet.fromString("Label matches Metal")); + + /* + * verify the changes reached the FeatureRender + */ + assertFalse(fr.getDisplayedFeatureTypes().contains("type1")); + assertNull(fr.getFeatureFilter("type1")); + colour = fr.getFeatureColours().get("type2"); + assertTrue(colour.isSimpleColour()); + assertEquals(colour.getColour(), Color.green); + filter = fr.getFeatureFilter("type2"); + assertFalse(filter.isEmpty()); + assertEquals(filter.toStableString(), "Label Matches Metal"); + + /* + * add a new feature type and 'notify' FeatureRenderer + * it should appear in the first row of FeatureSettings table + */ + seq1.addSequenceFeature( + new SequenceFeature("type3", "desc", 4, 5, null)); + fr.featuresAdded(); + assertEquals(dialog.table.getRowCount(), 3); + assertEquals(dialog.table.getModel().getValueAt(0, TYPE_COLUMN), + "type3"); + assertEquals(dialog.table.getModel().getValueAt(0, SHOW_COLUMN), + Boolean.TRUE); + assertTrue(fr.getDisplayedFeatureTypes().contains("type3")); + + /* + * cancel the dialog, and verify FeatureRenderer data has been reset + */ + dialog.cancel(); + // type1 has been reset to visible: + assertTrue(fr.getDisplayedFeatureTypes().contains("type1")); + // type3 has been reset to not visible: + assertTrue(fr.getDisplayedFeatureTypes().contains("type3")); + // type2 colour has been reset to graduated: + colour = fr.getFeatureColours().get("type2"); + assertFalse(colour.isSimpleColour()); + assertEquals(colour.getMaxColour(), Color.blue); + // type2 filter has been reset to none (held as null): + assertNull(fr.getFeatureFilter("type2")); + // type1 filter has been reset: + filter = fr.getFeatureFilter("type1"); + assertEquals(filter.toStableString(), "Label Contains metal"); + } } -- 1.7.10.2