|
| 1 | +/* |
| 2 | + * Copyright 2000-2023 Vaadin Ltd. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | + * use this file except in compliance with the License. You may obtain a copy of |
| 6 | + * the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | + * License for the specific language governing permissions and limitations under |
| 14 | + * the License. |
| 15 | + */ |
| 16 | +package com.vaadin.flow.component.notification; |
| 17 | + |
| 18 | +import org.junit.After; |
| 19 | +import org.junit.Assert; |
| 20 | +import org.junit.Before; |
| 21 | +import org.junit.Test; |
| 22 | +import org.mockito.Mockito; |
| 23 | + |
| 24 | +import com.vaadin.flow.component.UI; |
| 25 | +import com.vaadin.flow.component.shared.internal.OverlayClassListProxy; |
| 26 | +import com.vaadin.flow.server.VaadinSession; |
| 27 | + |
| 28 | +public class NotificationHasStyleTest { |
| 29 | + |
| 30 | + private UI ui = new UI(); |
| 31 | + private Notification notification; |
| 32 | + |
| 33 | + @Before |
| 34 | + public void setup() { |
| 35 | + UI.setCurrent(ui); |
| 36 | + |
| 37 | + VaadinSession session = Mockito.mock(VaadinSession.class); |
| 38 | + Mockito.when(session.hasLock()).thenReturn(true); |
| 39 | + ui.getInternals().setSession(session); |
| 40 | + |
| 41 | + notification = new Notification(); |
| 42 | + ui.add(notification); |
| 43 | + } |
| 44 | + |
| 45 | + @After |
| 46 | + public void tearDown() { |
| 47 | + UI.setCurrent(null); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void addClassName_notificationHasOverlayClass() { |
| 52 | + notification.addClassName("foo"); |
| 53 | + Assert.assertEquals( |
| 54 | + notification.getElement().getProperty("overlayClass"), "foo"); |
| 55 | + |
| 56 | + notification.addClassName("bar"); |
| 57 | + Assert.assertEquals( |
| 58 | + notification.getElement().getProperty("overlayClass"), |
| 59 | + "foo bar"); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + public void removeClassName_notificationHasOverlayClass() { |
| 64 | + notification.addClassName("foo"); |
| 65 | + |
| 66 | + notification.removeClassName("foo"); |
| 67 | + Assert.assertEquals( |
| 68 | + notification.getElement().getProperty("overlayClass"), null); |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + public void setClassNameString_notificationHasOverlayClass() { |
| 73 | + notification.setClassName("foo"); |
| 74 | + Assert.assertEquals( |
| 75 | + notification.getElement().getProperty("overlayClass"), "foo"); |
| 76 | + |
| 77 | + notification.setClassName("bar"); |
| 78 | + Assert.assertEquals( |
| 79 | + notification.getElement().getProperty("overlayClass"), "bar"); |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + public void setClassNameBoolean_notificationHasOverlayClass() { |
| 84 | + notification.setClassName("foo", true); |
| 85 | + |
| 86 | + notification.setClassName("foo", false); |
| 87 | + |
| 88 | + Assert.assertEquals( |
| 89 | + notification.getElement().getProperty("overlayClass"), null); |
| 90 | + } |
| 91 | + |
| 92 | + @Test |
| 93 | + public void setClassNameMultiple_notificationHasOverlayClass() { |
| 94 | + notification.setClassName("foo bar"); |
| 95 | + notification.getClassNames().set("foo", false); |
| 96 | + |
| 97 | + Assert.assertEquals( |
| 98 | + notification.getElement().getProperty("overlayClass"), "bar"); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + public void addClassNames_notificationHasOverlayClass() { |
| 103 | + notification.addClassNames("foo", "bar"); |
| 104 | + Assert.assertEquals( |
| 105 | + notification.getElement().getProperty("overlayClass"), |
| 106 | + "foo bar"); |
| 107 | + |
| 108 | + notification.addClassNames("baz", "qux"); |
| 109 | + Assert.assertEquals( |
| 110 | + notification.getElement().getProperty("overlayClass"), |
| 111 | + "foo bar baz qux"); |
| 112 | + } |
| 113 | + |
| 114 | + @Test |
| 115 | + public void removeClassNames_notificationHasOverlayClass() { |
| 116 | + notification.addClassNames("foo", "bar", "baz", "qux"); |
| 117 | + |
| 118 | + notification.removeClassNames("foo", "bar"); |
| 119 | + Assert.assertEquals( |
| 120 | + notification.getElement().getProperty("overlayClass"), |
| 121 | + "baz qux"); |
| 122 | + } |
| 123 | + |
| 124 | + @Test(expected = UnsupportedOperationException.class) |
| 125 | + public void getStyle_unsupported() { |
| 126 | + notification.getStyle(); |
| 127 | + } |
| 128 | + |
| 129 | + @Test |
| 130 | + public void getClassNames_usesProxy() { |
| 131 | + Assert.assertTrue( |
| 132 | + notification.getClassNames() instanceof OverlayClassListProxy); |
| 133 | + } |
| 134 | +} |
0 commit comments