JAL-3493 fix patch for 2.11.1_js (nb - these changes should not be merged to 2.11.2!)
[jalview.git] / test / jalview / gui / SeqCanvasTest.java
index 78f6cd3..34e88ad 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.datamodel.SearchResults;
+import jalview.datamodel.SearchResultsI;
 import jalview.io.FileLoader;
 import jalview.util.Platform;
+import jalview.viewmodel.ViewportRanges;
 
 import java.awt.Font;
 import java.awt.FontMetrics;
 
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
+import static org.testng.Assert.assertEquals;
+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 junit.extensions.PA;
 
@@ -41,7 +48,9 @@ public class SeqCanvasTest
   @BeforeClass(alwaysRun = true)
   public void setUp()
   {
+    Cache.loadProperties(null);
     Cache.initLogger();
+    Desktop.getInstance().setVisible(false);
   }
 
   /**
@@ -53,6 +62,7 @@ public class SeqCanvasTest
   {
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
             "examples/uniref50.fa", DataSourceType.FILE);
+    
     AlignViewport av = af.getViewport();
     AlignmentI al = av.getAlignment();
     assertEquals(al.getWidth(), 157);
@@ -65,8 +75,8 @@ public class SeqCanvasTest
     av.setFont(new Font("SansSerif", Font.PLAIN, 14), true);
     int charHeight = av.getCharHeight();
     int charWidth = av.getCharWidth();
-    assertEquals(charHeight, Platform.isMac() ? 17 : 19);
-    assertEquals(charWidth, Platform.isMac() ? 12 : 11);
+    assertEquals(charHeight, !Platform.isWin() ? 17 : 19);
+    assertEquals(charWidth, !Platform.isWin() ? 12 : 11);
 
     /*
      * first with scales above, left, right
@@ -78,7 +88,7 @@ public class SeqCanvasTest
     FontMetrics fm = testee.getFontMetrics(av.getFont());
     int labelWidth = fm.stringWidth("000") + charWidth;
     assertEquals(labelWidth,
-            Platform.isMac() ? 3 * 9 + charWidth : 3 * 8 + charWidth);
+            !Platform.isWin() ? 3 * 9 + charWidth : 3 * 8 + charWidth);
 
     /*
      * width 400 pixels leaves (400 - 2*labelWidth) for residue columns
@@ -200,7 +210,7 @@ public class SeqCanvasTest
     canvasWidth += 2;
     wrappedWidth = testee.calculateWrappedGeometry(canvasWidth,
             canvasHeight);
-    assertEquals(wrappedWidth, Platform.isMac() ? 24 : 25); // 2px not enough
+    assertEquals(wrappedWidth, !Platform.isWin() ? 24 : 25); // 2px not enough
     canvasWidth += 1;
     wrappedWidth = testee.calculateWrappedGeometry(canvasWidth,
             canvasHeight);
@@ -235,8 +245,8 @@ public class SeqCanvasTest
     int charHeight = av.getCharHeight();
     int charWidth = av.getCharWidth();
 
-    assertEquals(charHeight, Platform.isMac() ? 17 : 19);
-    assertEquals(charWidth, Platform.isMac() ? 12 : 11);
+    assertEquals(charHeight, !Platform.isWin() ? 17 : 19);
+    assertEquals(charWidth, !Platform.isWin() ? 12 : 11);
 
     SeqCanvas testee = af.alignPanel.getSeqPanel().seqCanvas;
   
@@ -251,7 +261,7 @@ public class SeqCanvasTest
     FontMetrics fm = testee.getFontMetrics(av.getFont());
     int labelWidth = fm.stringWidth("000") + charWidth;
     assertEquals(labelWidth,
-            Platform.isMac() ? 3 * 9 + charWidth : 3 * 8 + charWidth);
+            !Platform.isWin() ? 3 * 9 + charWidth : 3 * 8 + charWidth);
 
     int annotationHeight = testee.getAnnotationHeight();
 
@@ -326,11 +336,22 @@ public class SeqCanvasTest
   {
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
             "examples/uniref50.fa", DataSourceType.FILE);
+    // 
+    System.out.println("ap dim = " + af.alignPanel.getSize());
+    System.out.println("seqpan dim = " + af.alignPanel.getSeqPanel().getSize());
+    System.out.println("seqcan dim = " + af.alignPanel.getSeqPanel().seqCanvas.getSize());
+
+
     AlignViewport av = af.getViewport();
     AlignmentI al = av.getAlignment();
     assertEquals(al.getWidth(), 157);
     assertEquals(al.getHeight(), 15);
-    av.getRanges().setStartEndSeq(0, 3);
+
+    ViewportRanges ranges = av.getRanges();
+    System.out.println(ranges + " before setting to 3");
+    ranges.setStartEndSeq(0, 3);
+    int endSeq = ranges.getEndSeq();
+    System.out.println(ranges + " after setting to 3");
     av.setShowAnnotation(false);
     av.setScaleAboveWrapped(true);
 
@@ -340,17 +361,39 @@ public class SeqCanvasTest
     int charHeight = av.getCharHeight();
     int charWidth = av.getCharWidth();
     // Windows h=19, w=11.
-    assertEquals(charHeight, Platform.isMac() ? 17 : 19);
-    assertEquals(charWidth, Platform.isMac() ? 12 : 11);
-
+    assertEquals(charHeight, !Platform.isWin() ? 17 : 19);
+    assertEquals(charWidth, !Platform.isWin() ? 12 : 11);
+    
     int canvasWidth = 400;
     int canvasHeight = 300;
     testee.calculateWrappedGeometry(canvasWidth, canvasHeight);
-
-    assertEquals(av.getRanges().getEndSeq(), 3); // unchanged
+    System.out.println(ranges);
+    assertEquals(ranges.getEndSeq(), endSeq); // unchanged
     int repeatingHeight = (int) PA.getValue(testee,
             "wrappedRepeatHeightPx");
     int h = charHeight * (2 + al.getHeight());
     assertEquals(repeatingHeight, h);
   }
+  @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.");
+  }
 }