-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LayoutPreviewPlugin YAML config (#1029)
Added a declarative config for the LayoutPreviewPlugin.
- Loading branch information
Showing
6 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/Whim.Yaml.Tests/YamlLoader_LoadLayoutPreviewTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
using NSubstitute; | ||
using Whim.LayoutPreview; | ||
using Whim.TestUtils; | ||
using Xunit; | ||
|
||
namespace Whim.Yaml.Tests; | ||
|
||
public class YamlLoader_LoadLayoutPreviewTests | ||
{ | ||
public static TheoryData<string, bool, bool> LayoutPreviewConfig => | ||
new() | ||
{ | ||
// YAML, enabled' | ||
{ | ||
""" | ||
plugins: | ||
layout_preview: | ||
is_enabled: true | ||
""", | ||
true, | ||
true | ||
}, | ||
// JSON, enabled | ||
{ | ||
""" | ||
{ | ||
"plugins": { | ||
"layout_preview": { | ||
"is_enabled": true | ||
} | ||
} | ||
} | ||
""", | ||
false, | ||
true | ||
}, | ||
// YAML, no values set | ||
{ | ||
""" | ||
plugins: | ||
layout_preview: {} | ||
""", | ||
true, | ||
false | ||
}, | ||
// JSON, no values set | ||
{ | ||
""" | ||
{ | ||
"plugins": { | ||
"layout_preview": {} | ||
} | ||
} | ||
""", | ||
false, | ||
false | ||
}, | ||
}; | ||
|
||
[Theory, MemberAutoSubstituteData<YamlLoaderCustomization>(nameof(LayoutPreviewConfig))] | ||
public void LoadLayoutPreviewPlugin(string yaml, bool isYaml, bool isEnabled, IContext ctx) | ||
{ | ||
// Given a a YAML config with the layout preview plugin | ||
YamlLoaderTestUtils.SetupFileConfig(ctx, yaml, isYaml); | ||
|
||
// When loading the config | ||
bool result = YamlLoader.Load(ctx); | ||
|
||
// Then the result is true, and the layout preview plugin is set | ||
Assert.True(result); | ||
ctx.PluginManager.Received().AddPlugin(Arg.Any<LayoutPreviewPlugin>()); | ||
} | ||
|
||
public static TheoryData<string, bool> DisabledLayoutPreviewConfig => | ||
new() | ||
{ | ||
// YAML | ||
{ | ||
""" | ||
plugins: | ||
layout_preview: | ||
is_enabled: false | ||
""", | ||
true | ||
}, | ||
// JSON | ||
{ | ||
""" | ||
{ | ||
"plugins": { | ||
"layout_preview": { | ||
"is_enabled": false | ||
} | ||
} | ||
} | ||
""", | ||
false | ||
}, | ||
}; | ||
|
||
[Theory, MemberAutoSubstituteData<YamlLoaderCustomization>(nameof(DisabledLayoutPreviewConfig))] | ||
public void LoadLayoutPreviewPlugin_ConfigIsNotEnabled_PluginIsNotLoaded(string schema, bool isYaml, IContext ctx) | ||
{ | ||
// Given a valid config with the layout preview plugin not enabled | ||
YamlLoaderTestUtils.SetupFileConfig(ctx, schema, isYaml); | ||
|
||
// When loading the config | ||
bool result = YamlLoader.Load(ctx); | ||
|
||
// Then the result is true, and the layout preview plugin is not set | ||
Assert.True(result); | ||
ctx.PluginManager.DidNotReceive().AddPlugin(Arg.Any<LayoutPreviewPlugin>()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters