Merge branch 'develop' into features/JAL-518_justify_seqs_in_region
[jalview.git] / test / jalview / gui / AlignmentPanelTest.java
index a137ff6..a221bd1 100644 (file)
@@ -22,7 +22,10 @@ package jalview.gui;
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
 
+import java.awt.Container;
 import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.FontMetrics;
@@ -51,7 +54,7 @@ public class AlignmentPanelTest
   {
     Jalview.main(
             new String[]
-            { "-nonews", "-props", "test/jalview/testProps.jvprops" });
+            { "--nonews", "--props", "test/jalview/testProps.jvprops" });
 
     Cache.applicationProperties.setProperty("SHOW_IDENTITY",
             Boolean.TRUE.toString());
@@ -206,9 +209,10 @@ public class AlignmentPanelTest
 
   /**
    * Test the variant of calculateIdWidth that computes the longest of any
-   * sequence name or annotation label width
+   * sequence name or annotation label width FIXME: JAL-4291: test needs
+   * updating for JAL-244 and JAL-4091
    */
-  @Test(groups = "Functional")
+  @Test(groups = "Functional", enabled = false)
   public void testCalculateIdWidth_withMaxWidth()
   {
     AlignViewportI av = af.alignPanel.getAlignViewport();
@@ -217,13 +221,20 @@ public class AlignmentPanelTest
     av.setShowAnnotation(false);
     av.setIdWidth(18);
 
+    FontMetrics fmfor = new Container()
+            .getFontMetrics(new Font(af.viewport.font.getName(),
+                    Font.ITALIC, af.viewport.font.getSize()));
+
     /*
      * note 4 pixels 'padding' are added to the longest seq name/annotation label
      */
     Dimension d = af.alignPanel.calculateIdWidth(2000);
+    // Assumption ID_WIDTH_PADDING == 4
+    int expwidth = 3 + fmfor.stringWidth("Conservation");
+
     assertEquals(d.width, 166); // 4 + pixel width of "Q93Z60_ARATH/1-118"
     assertEquals(d.height, 12); // fixed value (not used?)
-    assertEquals(av.getIdWidth(), 18); // not changed by this method
+    assertEquals(av.getIdWidth(), expwidth); // not changed by this method
 
     /*
      * make the longest sequence name longer
@@ -242,11 +253,10 @@ public class AlignmentPanelTest
      */
     AlignmentAnnotation aa = av.getAlignment().getAlignmentAnnotation()[0];
     aa.label = "THIS IS A VERY LONG LABEL INDEED";
-    FontMetrics fmfor = af.alignPanel
-            .getFontMetrics(af.alignPanel.getAlabels().getFont());
-    // Assumption ID_WIDTH_PADDING == 4
-    int expwidth = 4 + fmfor.stringWidth(aa.label);
     d = af.alignPanel.calculateIdWidth(2000);
+    // Assumption ID_WIDTH_PADDING == 3
+    expwidth = 3 + fmfor.stringWidth(aa.label);
+
     assertEquals(d.width, expwidth); // 228 == ID_WIDTH_PADDING + pixel width of
                                      // "THIS IS A VERY LONG LABEL INDEED"
     assertEquals(d.height, 12);
@@ -290,4 +300,71 @@ public class AlignmentPanelTest
     Cache.setProperty("FIGURE_AUTOIDWIDTH", Boolean.TRUE.toString());
     assertEquals(115, af.alignPanel.getVisibleIdWidth(false));
   }
-}
+
+  @Test(groups = { "Functional", "Not-bamboo" })
+  public void testresetIdWidth()
+  {
+    /*
+     * width for onscreen rendering is IDPanel width
+     */
+    int w = af.alignPanel.getVisibleIdWidth(true);
+    assertEquals(w, af.alignPanel.getIdPanel().getWidth());
+    assertEquals(w, 115);
+
+    // manually adjust
+    af.viewport.setIdWidth(200);
+    w = af.alignPanel.calculateIdWidth().width;
+    assertTrue(
+            af.alignPanel.getIdPanel().getIdCanvas().isManuallyAdjusted());
+    assertEquals(w, af.alignPanel.getIdPanel().getWidth());
+
+    af.viewport.setIdWidth(-1);
+    af.alignPanel.getIdPanel().getIdCanvas().setManuallyAdjusted(false);
+    w = af.alignPanel.calculateIdWidth().width;
+
+    assertEquals(w, af.alignPanel.getIdPanel().getWidth());
+
+    assertNotEquals(w, 115);
+  }
+
+  @Test(groups = "Functional")
+  public void testSetOverviewTitle()
+  {
+    OverviewPanel ov1 = this.af.openOverviewPanel(true);
+    String alignFrameTitle = af.getTitle();
+    assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle);
+
+    /*
+     * on New View, existing overview should get " Original" added to title
+     * and new view's overview should get " View 1" added
+     */
+    af.newView_actionPerformed(null);
+    assertEquals(ov1.getTitle(),
+            "Overview " + alignFrameTitle + " Original");
+    OverviewPanel ov2 = this.af.openOverviewPanel(true);
+    assertEquals(ov2.getTitle(), "Overview " + alignFrameTitle + " View 1");
+  }
+
+  @Test(groups = "Functional")
+  public void testSetOverviewTitle_automaticOverview()
+  {
+    Cache.setProperty("SHOW_OVERVIEW", "true");
+    AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
+            "examples/uniref50.fa", DataSourceType.FILE);
+    OverviewPanel ov1 = alignFrame.alignPanel.getOverviewPanel();
+    assertNotNull(ov1);
+    String alignFrameTitle = alignFrame.getTitle();
+    assertEquals(ov1.getTitle(), "Overview " + alignFrameTitle);
+
+    /*
+     * on New View, existing overview should get " Original" added to title
+     * and new view's automatic overview should have " View 1" added
+     */
+    alignFrame.newView_actionPerformed(null);
+    assertEquals(ov1.getTitle(),
+            "Overview " + alignFrameTitle + " Original");
+    OverviewPanel ov2 = alignFrame.alignPanel.getOverviewPanel();
+    assertNotNull(ov2);
+    assertEquals(ov2.getTitle(), "Overview " + alignFrameTitle + " View 1");
+  }
+}
\ No newline at end of file