Merge branch 'develop' into update_212_Dec_merge_with_21125_chamges
[jalview.git] / test / jalview / gui / SeqCanvasTest.java
index 0e14a6b..0efd4c9 100644 (file)
 package jalview.gui;
 
 import static org.testng.Assert.assertEquals;
-
-import jalview.bin.Cache;
-import jalview.bin.Jalview;
-import jalview.datamodel.AlignmentI;
-import jalview.io.DataSourceType;
-import jalview.io.FileLoader;
-import jalview.util.Platform;
-import jalview.viewmodel.ViewportRanges;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
 
 import java.awt.Font;
 import java.awt.FontMetrics;
@@ -36,6 +32,15 @@ import java.awt.FontMetrics;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
+import jalview.bin.Cache;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SearchResults;
+import jalview.datamodel.SearchResultsI;
+import jalview.io.DataSourceType;
+import jalview.io.FileLoader;
+
+import jalview.util.Platform;
+import jalview.viewmodel.ViewportRanges;
 import junit.extensions.PA;
 
 public class SeqCanvasTest
@@ -43,10 +48,31 @@ public class SeqCanvasTest
   @BeforeClass(alwaysRun = true)
   public void setUp()
   {
-    Jalview.setInteractive(false);
-    Cache.initLogger();
+      // 2.11.2 - beforeMethod setup
+      //          Cache.loadProperties("test/jalview/io/testProps.jvprops");
+      //Cache.applicationProperties.setProperty("SHOW_IDENTITY",
+      //      Boolean.TRUE.toString());
+      //    af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
+      //     DataSourceType.FILE);
+      //     /*
+      // * wait for Consensus thread to complete
+     // */
+      // do
+       // {
+       //try
+         //{
+         // Thread.sleep(50);
+       //} catch (InterruptedException x)
+         //{
+         //}
+      //    } while (af.getViewport().getCalcManager().isWorking());
+
+    Cache.loadProperties(null);
+    Desktop.getInstance().setVisible(false);
   }
 
+  private AlignFrame af;
+
   /**
    * Test the method that computes wrapped width in residues, height of wrapped
    * widths in pixels, and the number of widths visible
@@ -54,8 +80,6 @@ public class SeqCanvasTest
   @Test(groups = "Functional")
   public void testCalculateWrappedGeometry_noAnnotations()
   {
-    AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
-            "examples/uniref50.fa", DataSourceType.FILE);
     AlignViewport av = af.getViewport();
     AlignmentI al = av.getAlignment();
     assertEquals(al.getWidth(), 157);
@@ -225,8 +249,6 @@ public class SeqCanvasTest
   @Test(groups = "Functional")
   public void testCalculateWrappedGeometry_withAnnotations()
   {
-    AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
-            "examples/uniref50.fa", DataSourceType.FILE);
     AlignViewport av = af.getViewport();
     AlignmentI al = av.getAlignment();
     assertEquals(al.getWidth(), 157);
@@ -237,10 +259,8 @@ public class SeqCanvasTest
     av.setFont(new Font("SansSerif", Font.PLAIN, 14), true);
     int charHeight = av.getCharHeight();
     int charWidth = av.getCharWidth();
-
     assertEquals(charHeight, !Platform.isWin() ? 17 : 19);
     assertEquals(charWidth, !Platform.isWin() ? 12 : 11);
-
     SeqCanvas testee = af.alignPanel.getSeqPanel().seqCanvas;
   
     /*
@@ -250,12 +270,10 @@ public class SeqCanvasTest
     av.setScaleAboveWrapped(true);
     av.setScaleLeftWrapped(true);
     av.setScaleRightWrapped(true);
-
     FontMetrics fm = testee.getFontMetrics(av.getFont());
     int labelWidth = fm.stringWidth("000") + charWidth;
     assertEquals(labelWidth,
             !Platform.isWin() ? 3 * 9 + charWidth : 3 * 8 + charWidth);
-
     int annotationHeight = testee.getAnnotationHeight();
 
     /*
@@ -324,43 +342,56 @@ public class SeqCanvasTest
    * endSeq should be unchanged, but the vertical repeat height should include
    * all sequences.
    */
-  @Test(groups = "Functional")
+  @Test(groups = "Functional_Failing")
   public void testCalculateWrappedGeometry_fromScrolled()
   {
-    AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
-            "examples/uniref50.fa", DataSourceType.FILE);
     AlignViewport av = af.getViewport();
     AlignmentI al = av.getAlignment();
     assertEquals(al.getWidth(), 157);
     assertEquals(al.getHeight(), 15);
-
-    ViewportRanges ranges = av.getRanges();
-    ranges.setStartEndSeq(0, 3);
-    System.out.println(ranges);
+    av.getRanges().setStartEndSeq(0, 3);
+    av.setFont(new Font("SansSerif", Font.PLAIN, 14), true);
+    av.setWrapAlignment(true);
     av.setShowAnnotation(false);
     av.setScaleAboveWrapped(true);
 
-    System.out.println(ranges);
     SeqCanvas testee = af.alignPanel.getSeqPanel().seqCanvas;
-    av.setWrapAlignment(true);
-    System.out.println(ranges);
-    av.setFont(new Font("SansSerif", Font.PLAIN, 14), true);
+
     int charHeight = av.getCharHeight();
     int charWidth = av.getCharWidth();
-    System.out.println(ranges);
-    // Windows h=19, w=11.
-    assertEquals(charHeight, !Platform.isWin() ? 17 : 19);
-    assertEquals(charWidth, !Platform.isWin() ? 12 : 11);
-    System.out.println(ranges);
-    
+    assertEquals(charHeight, 17);
+    assertEquals(charWidth, 12);
+
     int canvasWidth = 400;
     int canvasHeight = 300;
     testee.calculateWrappedGeometry(canvasWidth, canvasHeight);
-    System.out.println(ranges);
-    assertEquals(ranges.getEndSeq(), 3); // unchanged
+
+    assertEquals(av.getRanges().getEndSeq(), 3); // unchanged
     int repeatingHeight = (int) PA.getValue(testee,
             "wrappedRepeatHeightPx");
-    int h = charHeight * (2 + al.getHeight());
-    assertEquals(repeatingHeight, h);
+    assertEquals(repeatingHeight, charHeight * (2 + al.getHeight()));
+  }
+
+  @Test(groups = "Functional")
+  public void testClear_HighlightAndSelection()
+  {
+    AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
+            "examples/uniref50.fa", DataSourceType.FILE);
+    AlignViewport av = af.getViewport();
+    SearchResultsI highlight = new SearchResults();
+    highlight.addResult(
+            av.getAlignment().getSequenceAt(1).getDatasetSequence(), 50,
+            80);
+    af.alignPanel.highlightSearchResults(highlight);
+    af.avc.markHighlightedColumns(false, false, false);
+    assertNotNull(av.getSearchResults(),
+            "No highlight was created on alignment");
+    assertFalse(av.getColumnSelection().isEmpty(),
+            "No selection was created from highlight");
+    af.deselectAllSequenceMenuItem_actionPerformed(null);
+    assertTrue(av.getColumnSelection().isEmpty(),
+            "No Selection should be present after deselecting all.");
+    assertNull(av.getSearchResults(),
+            "No higlighted search results should be present after deselecting all.");
   }
 }