Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 17:27:16 GMT
  2. Package jalview.gui

File ScalePanelTest.java

 

Code metrics

0
114
5
1
264
165
5
0.04
22.8
5
1

Classes

Class Line # Actions
ScalePanelTest 46 114 5
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.gui;
22   
23    import static org.testng.Assert.assertEquals;
24    import static org.testng.Assert.assertTrue;
25   
26    import jalview.bin.Cache;
27    import jalview.bin.Jalview;
28    import jalview.datamodel.Alignment;
29    import jalview.datamodel.AlignmentI;
30    import jalview.datamodel.Sequence;
31    import jalview.datamodel.SequenceGroup;
32    import jalview.datamodel.SequenceI;
33    import jalview.io.DataSourceType;
34    import jalview.io.FileLoader;
35    import jalview.util.MessageManager;
36    import jalview.viewmodel.ViewportRanges;
37   
38    import java.awt.event.MouseEvent;
39   
40    import javax.swing.JMenuItem;
41    import javax.swing.JPopupMenu;
42   
43    import org.testng.annotations.BeforeClass;
44    import org.testng.annotations.Test;
45   
 
46    public class ScalePanelTest
47    {
 
48  1 toggle @BeforeClass(alwaysRun = true)
49    public void setUpJvOptionPane()
50    {
51  1 JvOptionPane.setInteractiveMode(false);
52  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
53    }
54   
 
55  1 toggle @Test(groups = "Functional")
56    public void testPreventNegativeStartColumn()
57    {
58  1 SequenceI seq1 = new Sequence("Seq1", "MATRESS");
59  1 SequenceI seq2 = new Sequence("Seq2", "MADNESS");
60  1 AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
61   
62  1 AlignFrame alignFrame = new AlignFrame(al, al.getWidth(),
63    al.getHeight());
64  1 ScalePanel scalePanel = alignFrame.alignPanel.getScalePanel();
65   
66  1 MouseEvent mouse = new MouseEvent(scalePanel, 0, 1, 0, 4, 0, 1, false);
67   
68    // check the bounded lookup is not returning negatives
69  1 assertEquals(
70    alignFrame.alignPanel.getSeqPanel().findAlignmentColumn(mouse),
71    0);
72   
73  1 scalePanel.mousePressed(mouse);
74  1 scalePanel.mouseDragged(mouse);
75   
76    // simulate dragging selection leftwards beyond the sequences giving
77    // negative X
78  1 mouse = new MouseEvent(scalePanel, 0, 1, 0, -30, 0, 1, false);
79   
80  1 scalePanel.mouseReleased(mouse);
81   
82  1 SequenceGroup sg = scalePanel.av.getSelectionGroup();
83  1 int startCol = sg.getStartRes();
84   
85  1 assertTrue(startCol >= 0);
86    }
87   
88    /**
89    * Test for JAL-3212
90    */
 
91  1 toggle @Test(groups = "Functional")
92    public void testSelectColumns_withHidden()
93    {
94  1 String seq1 = ">Seq1\nANTOFAGASTAVALPARAISOMONTEVIDEOANTANANARIVO";
95  1 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(seq1,
96    DataSourceType.PASTE);
97  1 ScalePanel scalePanel = alignFrame.alignPanel.getScalePanel();
98   
99    /*
100    * hide columns 1-20 (of 43); then 'drag' to select columns 30-31;
101    * 31 is 51 in absolute columns but bug JAL-3212 reduces it to
102    * endRes which is 22
103    */
104  1 AlignViewport viewport = alignFrame.getViewport();
105  1 ViewportRanges ranges = viewport.getRanges();
106  1 assertEquals(ranges.getStartRes(), 0);
107  1 assertEquals(ranges.getEndRes(), 42);
108  1 viewport.hideColumns(0, 19);
109  1 alignFrame.alignPanel.updateLayout();
110  1 assertEquals(ranges.getStartRes(), 0);
111  1 assertEquals(ranges.getEndRes(), 22);
112   
113  1 int cw = viewport.getCharWidth();
114  1 int xPos = 9 * cw + 2;
115  1 MouseEvent mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1,
116    false);
117  1 scalePanel.mousePressed(mouse);
118  1 scalePanel.mouseDragged(mouse);
119  1 xPos += cw;
120  1 mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false);
121  1 scalePanel.mouseReleased(mouse);
122   
123  1 SequenceGroup sg = scalePanel.av.getSelectionGroup();
124  1 assertEquals(sg.getStartRes(), 29);
125  1 assertEquals(sg.getEndRes(), 30);
126    }
127   
 
128  1 toggle @Test(groups = "Functional")
129    public void testBuildPopupMenu()
130    {
131  1 final String hide = MessageManager.getString("label.hide_columns");
132  1 final String reveal = MessageManager.getString("label.reveal");
133  1 final String revealAll = MessageManager.getString("action.reveal_all");
134   
135  1 String seq1 = ">Seq1\nANTOFAGASTA";
136  1 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(seq1,
137    DataSourceType.PASTE);
138  1 ScalePanel scalePanel = alignFrame.alignPanel.getScalePanel();
139  1 AlignViewport viewport = alignFrame.getViewport();
140  1 int cw = viewport.getCharWidth();
141   
142    /*
143    * hide columns 3-4 (counting from 0)
144    */
145  1 viewport.hideColumns(3, 4);
146  1 alignFrame.alignPanel.updateLayout();
147   
148    /*
149    * verify popup menu left/right of hidden column marker
150    * NB need to call mouseMoved first as this sets field 'reveal'
151    */
152  1 int xPos = 1 * cw + 2; // 2 columns left of hidden marker
153  1 MouseEvent mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1,
154    false);
155  1 scalePanel.mouseMoved(mouse);
156  1 JPopupMenu popup = scalePanel.buildPopupMenu(1);
157  1 assertEquals(popup.getSubElements().length, 0);
158   
159    /*
160    * popup just left of hidden marker has 'Reveal'
161    */
162  1 xPos = 2 * cw + 2;
163  1 mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false);
164  1 scalePanel.mouseMoved(mouse);
165  1 popup = scalePanel.buildPopupMenu(2);
166  1 assertEquals(popup.getSubElements().length, 1);
167  1 assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), reveal);
168   
169    /*
170    * popup just right of hidden marker has 'Reveal'
171    */
172  1 xPos = 3 * cw + 2;
173  1 mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false);
174  1 scalePanel.mouseMoved(mouse);
175  1 popup = scalePanel.buildPopupMenu(5); // allowing for 2 hidden columns
176  1 assertEquals(popup.getSubElements().length, 1);
177  1 assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), reveal);
178   
179    /*
180    * popup further right is empty
181    */
182  1 xPos = 4 * cw + 2;
183  1 mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false);
184  1 scalePanel.mouseMoved(mouse);
185  1 popup = scalePanel.buildPopupMenu(6); // allowing for 2 hidden columns
186  1 assertEquals(popup.getSubElements().length, 0);
187   
188    /*
189    * 'drag' to select columns around the hidden column marker
190    */
191  1 xPos = 1 * cw + 2;
192  1 mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false);
193  1 scalePanel.mousePressed(mouse);
194  1 scalePanel.mouseDragged(mouse);
195  1 xPos = 5 * cw + 2;
196  1 mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false);
197  1 scalePanel.mouseReleased(mouse);
198   
199    /*
200    * popup 2 columns left of marker: 'Hide' only
201    */
202  1 xPos = 1 * cw + 2;
203  1 mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false);
204  1 scalePanel.mouseMoved(mouse);
205  1 popup = scalePanel.buildPopupMenu(1);
206  1 assertEquals(popup.getSubElements().length, 1);
207  1 assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), hide);
208   
209    /*
210    * popup just left of marker: 'Reveal' and 'Hide'
211    */
212  1 xPos = 2 * cw + 2;
213  1 mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false);
214  1 scalePanel.mouseMoved(mouse);
215  1 popup = scalePanel.buildPopupMenu(1);
216  1 assertEquals(popup.getSubElements().length, 2);
217  1 assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), reveal);
218  1 assertEquals(((JMenuItem) popup.getSubElements()[1]).getText(), hide);
219   
220    /*
221    * popup just right of marker: 'Reveal' and 'Hide'
222    */
223  1 xPos = 3 * cw + 2;
224  1 mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false);
225  1 scalePanel.mouseMoved(mouse);
226  1 popup = scalePanel.buildPopupMenu(5);
227  1 assertEquals(popup.getSubElements().length, 2);
228  1 assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), reveal);
229  1 assertEquals(((JMenuItem) popup.getSubElements()[1]).getText(), hide);
230   
231    /*
232    * hiding a second region adds option 'Reveal all' to 'Reveal'
233    */
234  1 viewport.hideColumns(6, 7);
235  1 alignFrame.alignPanel.updateLayout();
236  1 xPos = 3 * cw + 2;
237  1 mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false);
238  1 scalePanel.mouseMoved(mouse);
239  1 popup = scalePanel.buildPopupMenu(5);
240  1 assertEquals(popup.getSubElements().length, 3);
241  1 assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), reveal);
242  1 assertEquals(((JMenuItem) popup.getSubElements()[1]).getText(),
243    revealAll);
244  1 assertEquals(((JMenuItem) popup.getSubElements()[2]).getText(), hide);
245   
246  1 alignFrame.deselectAllSequenceMenuItem_actionPerformed(null);
247  1 popup = scalePanel.buildPopupMenu(5);
248  1 assertEquals(popup.getSubElements().length, 2);
249  1 assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), reveal);
250  1 assertEquals(((JMenuItem) popup.getSubElements()[1]).getText(),
251    revealAll);
252    }
253   
 
254  1 toggle @BeforeClass(alwaysRun = true)
255    public static void setUpBeforeClass() throws Exception
256    {
257    /*
258    * use read-only test properties file
259    */
260  1 Cache.loadProperties("test/jalview/io/testProps.jvprops");
261  1 Jalview.main(new String[] { "--nonews" });
262    }
263   
264    }