source: josm/trunk/test/unit/org/openstreetmap/josm/gui/dialogs/layer/LayerVisibilityActionTest.java@ 15650

Last change on this file since 15650 was 15650, checked in by Don-vip, 4 years ago

fix #18514 - display changeset toggle dialog entry in the window menu only in expert mode

  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.layer;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertFalse;
6import static org.junit.Assert.assertTrue;
7
8import org.junit.Rule;
9import org.junit.Test;
10import org.openstreetmap.josm.gui.MainApplication;
11import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
12import org.openstreetmap.josm.gui.dialogs.LayerListDialog.LayerListModel;
13import org.openstreetmap.josm.gui.layer.TMSLayer;
14import org.openstreetmap.josm.gui.layer.TMSLayerTest;
15import org.openstreetmap.josm.testutils.JOSMTestRules;
16
17import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
18
19/**
20 * Unit tests of {@link LayerVisibilityAction} class.
21 */
22public class LayerVisibilityActionTest {
23 /**
24 * TMS layer needs prefs. Platform for LayerListDialog shortcuts.
25 */
26 @Rule
27 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
28 public JOSMTestRules test = new JOSMTestRules().preferences().projection().main();
29
30 /**
31 * Unit test of {@link LayerVisibilityAction} class.
32 */
33 @Test
34 public void testLayerVisibilityAction() {
35 TMSLayer layer = TMSLayerTest.createTmsLayer();
36 LayerListModel model = new LayerListDialog(MainApplication.getLayerManager()) {
37 @Override
38 protected void registerInWindowMenu(boolean isExpert) {
39 // ignore
40 }
41 }.getModel();
42 LayerVisibilityAction action = new LayerVisibilityAction(model);
43 action.updateEnabledState();
44 assertFalse(action.isEnabled());
45
46 MainApplication.getLayerManager().addLayer(layer);
47 model.setSelectedLayer(layer);
48 action.updateEnabledState();
49 assertTrue(action.isEnabled());
50 assertTrue(action.supportLayers(model.getSelectedLayers()));
51
52 // now check values
53 action.updateValues();
54 assertEquals(1.0, action.opacitySlider.getRealValue(), 1e-15);
55 assertEquals("OpacitySlider [getRealValue()=1.0]", action.opacitySlider.toString());
56
57 action.opacitySlider.setRealValue(.5);
58 action.updateValues();
59
60 assertEquals(0.5, action.opacitySlider.getRealValue(), 1e-15);
61 assertEquals("OpacitySlider [getRealValue()=0.5]", action.opacitySlider.toString());
62
63 action.setVisibleFlag(false);
64 action.updateValues();
65 assertFalse(layer.isVisible());
66
67 action.setVisibleFlag(true);
68 action.updateValues();
69 assertTrue(layer.isVisible());
70
71 // layer stays visible during adjust
72 action.opacitySlider.slider.setValueIsAdjusting(true);
73 action.opacitySlider.setRealValue(0);
74 assertEquals(0, layer.getOpacity(), 1e-15);
75 layer.setOpacity(.1); // to make layer.isVisible work
76 assertTrue(layer.isVisible());
77 layer.setOpacity(0);
78
79 action.opacitySlider.slider.setValueIsAdjusting(false);
80 action.opacitySlider.setRealValue(0);
81 assertEquals(0, layer.getOpacity(), 1e-15);
82 layer.setOpacity(.1); // to make layer.isVisible work
83 assertFalse(layer.isVisible());
84 layer.setOpacity(0);
85 action.updateValues();
86
87 // Opacity reset when it was 0 and user set layer to visible.
88 action.setVisibleFlag(true);
89 action.updateValues();
90 assertEquals(1.0, action.opacitySlider.getRealValue(), 1e-15);
91 assertEquals(1.0, layer.getOpacity(), 1e-15);
92 }
93}
Note: See TracBrowser for help on using the repository browser.