1 /*
2  * ElementIdsTests.java
3  *
4  * Copyright (C) 2021 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant
7  * to the terms of a commercial license agreement with RStudio, then
8  * this program is licensed to you under the terms of version 3 of the
9  * GNU Affero General Public License. This program is distributed WITHOUT
10  * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
11  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
12  * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
13  *
14  */
15 package org.rstudio.core.client;
16 
17 import com.google.gwt.dom.client.Element;
18 import com.google.gwt.junit.client.GWTTestCase;
19 import com.google.gwt.user.client.DOM;
20 
21 public class ElementIdsTests extends GWTTestCase
22 {
23    @Override
getModuleName()24    public String getModuleName()
25    {
26       return "org.rstudio.studio.RStudioTests";
27    }
28 
testExactMatchElementId()29    public void testExactMatchElementId()
30    {
31       Element ele = DOM.createDiv();
32       ElementIds.assignElementId(ele, ElementIds.CONSOLE_INPUT);
33       assertTrue(ElementIds.isInstanceOf(ele, ElementIds.CONSOLE_INPUT));
34    }
35 
testMismatchedElementId()36    public void testMismatchedElementId()
37    {
38       Element ele = DOM.createDiv();
39       ElementIds.assignElementId(ele, ElementIds.CONSOLE_INPUT);
40       assertFalse(ElementIds.isInstanceOf(ele, ElementIds.CONSOLE_OUTPUT));
41    }
42 
testMatchingUndupedElementId()43    public void testMatchingUndupedElementId()
44    {
45       Element ele = DOM.createDiv();
46       ElementIds.assignElementId(ele, ElementIds.CONSOLE_INPUT + "_123");
47       assertTrue(ElementIds.isInstanceOf(ele, ElementIds.CONSOLE_INPUT));
48    }
49 
testMisMatchedUndupedElementId()50    public void testMisMatchedUndupedElementId()
51    {
52       Element ele = DOM.createDiv();
53       assertFalse(ElementIds.isInstanceOf(ele, ElementIds.CONSOLE_OUTPUT));
54    }
55 
testElementIdWithoutStandardPrefix()56    public void testElementIdWithoutStandardPrefix()
57    {
58       Element ele = DOM.createDiv();
59       ele.setId("some-randomID");
60       assertFalse(ElementIds.isInstanceOf(ele, ElementIds.CONSOLE_OUTPUT));
61    }
62 
testElementIdWithoutStandardSuffix()63    public void testElementIdWithoutStandardSuffix()
64    {
65       Element ele = DOM.createDiv();
66       ElementIds.assignElementId(ele, ElementIds.CONSOLE_INPUT + "_123_");
67       assertFalse(ElementIds.isInstanceOf(ele, ElementIds.CONSOLE_OUTPUT));
68    }
69 }
70