|
| 1 | +/* |
| 2 | + * Copyright 2026 znai maintainers |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of 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, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.testingisdocumenting.znai.extensions.attention |
| 18 | + |
| 19 | +import org.junit.Test |
| 20 | +import org.testingisdocumenting.znai.extensions.PluginParamsFactory |
| 21 | +import org.testingisdocumenting.znai.extensions.include.PluginsTestUtils |
| 22 | + |
| 23 | +import static org.testingisdocumenting.webtau.Matchers.code |
| 24 | +import static org.testingisdocumenting.webtau.Matchers.throwException |
| 25 | +import static org.testingisdocumenting.znai.parser.TestComponentsRegistry.TEST_COMPONENTS_REGISTRY |
| 26 | + |
| 27 | +class AttentionSignCustomFencePluginTest { |
| 28 | + static PluginParamsFactory pluginParamsFactory = TEST_COMPONENTS_REGISTRY.pluginParamsFactory() |
| 29 | + |
| 30 | + @Test |
| 31 | + void "uses free form parameter as the attention type"() { |
| 32 | + def props = process("my-type", [:], "hello world") |
| 33 | + props.attentionType.should == "my-type" |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + void "trims the free form type"() { |
| 38 | + def props = process(" my-type ", [:], "hello world") |
| 39 | + props.attentionType.should == "my-type" |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + void "supports optional label"() { |
| 44 | + def props = process("my-type", [label: "Consider"], "hello world") |
| 45 | + props.attentionType.should == "my-type" |
| 46 | + props.label.should == "Consider" |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + void "supports optional icon"() { |
| 51 | + def props = process("my-type", [icon: "zap"], "hello world") |
| 52 | + props.attentionType.should == "my-type" |
| 53 | + props.icon.should == "zap" |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + void "has no icon by default"() { |
| 58 | + def props = process("my-type", [:], "hello world") |
| 59 | + props.containsKey("icon").should == false |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + void "fails when type is not provided"() { |
| 64 | + code { |
| 65 | + process("", [:], "hello world") |
| 66 | + } should throwException(~/attention-custom requires a type/) |
| 67 | + } |
| 68 | + |
| 69 | + private static def process(String type, Map<String, ?> params, String content) { |
| 70 | + return PluginsTestUtils.processFenceAndGetProps( |
| 71 | + pluginParamsFactory.create("attention-custom", type, params), content) |
| 72 | + } |
| 73 | +} |
0 commit comments