JAL-3253-applet JAL-3423 TestNG/Win
[jalview.git] / test / jalview / gui / AlignmentPanelTest.java
index f3b6876..fd67ac4 100644 (file)
@@ -21,6 +21,7 @@
 package jalview.gui;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotEquals;
 
 import jalview.bin.Cache;
 import jalview.bin.Jalview;
@@ -28,6 +29,9 @@ import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
 import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
+import jalview.viewmodel.ViewportRanges;
+
+import java.lang.reflect.InvocationTargetException;
 
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
@@ -129,15 +133,17 @@ public class AlignmentPanelTest
   AlignFrame af;
 
   @BeforeMethod(alwaysRun = true)
-  public void setUp()
+  public void setUp() throws InvocationTargetException, InterruptedException
   {
     Jalview.main(new String[] { "-nonews", "-props",
         "test/jalview/testProps.jvprops" });
 
-    Cache.applicationProperties.setProperty("SHOW_IDENTITY",
+    Cache.setPropertyNoSave("SHOW_IDENTITY",
             Boolean.TRUE.toString());
     af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
             DataSourceType.FILE);
+    
+    af.paintImmediately(af.getBounds());
 
     /*
      * wait for Consensus thread to complete
@@ -148,7 +154,7 @@ public class AlignmentPanelTest
       {
         try
         {
-          wait(50);
+          wait(250); // BH was 50
         } catch (InterruptedException e)
         {
         }
@@ -164,27 +170,32 @@ public class AlignmentPanelTest
   @Test(groups = "Functional")
   public void TestSetScrollValues()
   {
-    int oldres = af.getViewport().getEndRes();
+    ViewportRanges ranges = af.getViewport().getRanges();
+    af.alignPanel.setScrollValues(0, 0);
+
+    int oldres = ranges.getEndRes();
     af.alignPanel.setScrollValues(-1, 5);
 
     // setting -ve x value does not change residue
-    assertEquals(af.getViewport().getEndRes(), oldres);
+    assertEquals(ranges.getEndRes(), oldres);
 
     af.alignPanel.setScrollValues(0, 5);
 
     // setting 0 as x value does not change residue
-    assertEquals(af.getViewport().getEndRes(), oldres);
+    assertEquals(ranges.getEndRes(), oldres);
 
     af.alignPanel.setScrollValues(5, 5);
     // setting x value to 5 extends endRes by 5 residues
-    assertEquals(af.getViewport().getEndRes(), oldres + 5);
+    assertEquals(ranges.getEndRes(), oldres + 5);
 
     // scroll to position after hidden columns sets endres to oldres (width) +
     // position
     int scrollpos = 60;
     af.getViewport().hideColumns(30, 50);
     af.alignPanel.setScrollValues(scrollpos, 5);
-    assertEquals(af.getViewport().getEndRes(), oldres + scrollpos);
+
+    af.paintImmediately(af.getBounds());
+    assertEquals(ranges.getEndRes(), oldres + scrollpos);
 
     // scroll to position within hidden columns, still sets endres to oldres +
     // position
@@ -194,14 +205,15 @@ public class AlignmentPanelTest
     af.getViewport().showAllHiddenColumns();
     af.getViewport().hideColumns(30, 50);
     af.alignPanel.setScrollValues(scrollpos, 5);
-    assertEquals(af.getViewport().getEndRes(), oldres + scrollpos);
+    assertEquals(ranges.getEndRes(), oldres + scrollpos);
 
     // scroll to position within <width> distance of the end of the alignment
     // endRes should be set to width of alignment - 1
     scrollpos = 130;
     af.getViewport().showAllHiddenColumns();
     af.alignPanel.setScrollValues(scrollpos, 5);
-    assertEquals(af.getViewport().getEndRes(), af.getViewport()
+    af.paintImmediately(af.getBounds());
+    assertEquals(ranges.getEndRes(), af.getViewport()
             .getAlignment().getWidth() - 1);
 
     // now hide some columns, and scroll to position within <width>
@@ -209,9 +221,38 @@ public class AlignmentPanelTest
     // endRes should be set to width of alignment - 1 - the number of hidden
     // columns
     af.getViewport().hideColumns(30, 50);
+    af.paintImmediately(af.getBounds());
     af.alignPanel.setScrollValues(scrollpos, 5);
-    assertEquals(af.getViewport().getEndRes(), af.getViewport()
+    assertEquals(ranges.getEndRes(), af.getViewport()
             .getAlignment().getWidth() - 1 - 21); // 21 is the number of hidden
                                                   // columns
   }
+
+  /**
+   * Test that update layout reverts to original (unwrapped) values for endRes
+   * when switching from wrapped back to unwrapped mode (JAL-2739)
+   */
+  @Test(groups = "Functional")
+  public void TestUpdateLayout_endRes()
+  {
+    // get details of original alignment dimensions
+    ViewportRanges ranges = af.getViewport().getRanges();
+    int endres = ranges.getEndRes();
+
+    // wrap
+    af.alignPanel.getAlignViewport().setWrapAlignment(true);
+    af.alignPanel.updateLayout();
+    af.paintImmediately(af.getBounds());
+
+    // endRes has changed
+    assertNotEquals(ranges.getEndRes(), endres);
+
+    // unwrap
+    af.alignPanel.getAlignViewport().setWrapAlignment(false);
+    af.alignPanel.updateLayout();
+    af.paintImmediately(af.getBounds());
+    // endRes back to original value
+    assertEquals(ranges.getEndRes(), endres);
+
+  }
 }