1. Project Clover database mar. avr. 16 2024 08:19:06 CEST
  2. Package org.devacfr.maven.skins.reflow.snippet

File ComponentResolverTest.java

 

Code metrics

0
22
15
1
117
81
15
0,68
1,47
15
1

Classes

Class Line # Actions
ComponentResolverTest 30 22 0% 15 0
1.0100%
 

Contributing tests

This file is covered by 14 tests. .

Source view

1    /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10    * http://www.apache.org/licenses/LICENSE-2.0
11    *
12    * Unless required by applicable law or agreed to in writing,
13    * software distributed under the License is distributed on an
14    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15    * KIND, either express or implied. See the License for the
16    * specific language governing permissions and limitations
17    * under the License.
18    */
19    package org.devacfr.maven.skins.reflow.snippet;
20   
21    import org.devacfr.maven.skins.reflow.snippet.ComponentToken.Tag;
22    import org.devacfr.maven.skins.reflow.snippet.ComponentToken.Type;
23    import org.jsoup.nodes.Element;
24    import org.junit.jupiter.api.Assertions;
25    import org.junit.jupiter.api.Test;
26   
27    import static org.junit.jupiter.api.Assertions.assertEquals;
28    import static org.junit.jupiter.api.Assertions.assertNull;
29   
 
30    public class ComponentResolverTest {
31   
 
32  1 toggle @Test
33    public void shouldBeStartWebComponent() {
34  1 check("{{% component %}}", "component", Type.webComponent, Tag.start);
35    }
36   
 
37  1 toggle @Test
38    public void shouldBeStartWebComponentWithAttributes() {
39  1 check("{{% component style=\"width: 18rem;\" attr2=\"val\" %}}", "component", Type.webComponent, Tag.start);
40    }
41   
 
42  1 toggle @Test
43    public void shouldBeStartWebComponentWithAttributesLeftAndRightDoubleQuote() {
44  1 check("{{% component style=“width: 18rem;” attr2=“val” %}}", "component", Type.webComponent, Tag.start);
45    }
46   
 
47  1 toggle @Test
48    public void shouldBeStartWebComponentWithAttributeWithoutValue() {
49  1 check("{{% component pill %}}", "component", Type.webComponent, Tag.start);
50    }
51   
 
52  1 toggle @Test
53    public void shouldBeStartWebComponentWithNumberAttributes() {
54  1 check("{{% component length=\"120\" %}}", "component", Type.webComponent, Tag.start);
55    }
56   
 
57  1 toggle @Test
58    public void shouldBeEndWebComponent() {
59  1 check("{{% /component %}}", "component", Type.webComponent, Tag.end);
60    }
61   
 
62  1 toggle @Test
63    public void shouldBeEmptyWebComponent() {
64  1 check("{{% component /%}}", "component", Type.webComponent, Tag.empty);
65    }
66   
 
67  1 toggle @Test
68    public void shouldBeStartShortcode() {
69  1 check("{{< component >}}", "component", Type.shortcode, Tag.start);
70    }
71   
 
72  1 toggle @Test
73    public void shouldBeEndShortcode() {
74  1 check("{{< /component >}}", "component", Type.shortcode, Tag.end);
75    }
76   
 
77  1 toggle @Test
78    public void shouldBeEmptyShortcode() {
79  1 check("{{< component />}}", "component", Type.shortcode, Tag.empty);
80    }
81   
 
82  1 toggle @Test
83    public void shouldFailedOnMalformed() {
84  1 Assertions.assertThrows(RuntimeException.class, () -> {
85  1 new ComponentResolver().create(new Element("p").text("{{% /component /%}}"));
86    });
87    }
88   
 
89  1 toggle @Test
90    public void shouldFailedUnknownComponent() {
91  1 assertNull(new ComponentResolver().create(new Element("p").text("{{- /component -}}")));
92    }
93   
 
94  1 toggle @Test
95    public void shouldElementStartWebComponentContainingAttributes() {
96  1 check("{{% component attr=\"value\" attr1=\"value1\" %}}", "component", Type.webComponent, Tag.start);
97    }
98   
 
99  1 toggle @Test
100    public void shouldContainSnippetComponent() {
101  1 assertEquals(true,
102    ComponentResolver.hasIncludedSnippetComponent(
103    new Element("body").append("<test webcomponent class=\"cl\"></test>")));
104  1 assertEquals(true,
105    ComponentResolver
106    .hasIncludedSnippetComponent(new Element("body").append("<test shortcode class=\"cl\"></test>")));
107  1 assertEquals(false, ComponentResolver.hasIncludedSnippetComponent(new Element("body").append("<test></test>")));
108    }
109   
 
110  11 toggle private ComponentToken check(final String text, final String name, final Type type, final Tag state) {
111  11 final ComponentToken element = new ComponentResolver().create(new Element("p").text(text));
112  11 assertEquals(name, element.name());
113  11 assertEquals(type, element.type());
114  11 assertEquals(state, element.tag());
115  11 return element;
116    }
117    }