ファイル

87 行
3.2 KiB
C#

using System.Windows.Input;
using YukkuriMovieMaker.Plugin;
using YukkuriMovieMaker.Project;
using YukkuriMovieMaker.UndoRedo;
namespace UndoTree.Tests;
public sealed class UndoTreeCommandPluginTests
{
static (UndoTreeViewModel Model, UndoRedoManager Manager, Document Document) Open()
{
var (manager, document) = Histories.NewDocument("p1");
var model = new UndoTreeViewModel();
model.SetTimelineToolInfo(new TimelineToolInfo(null!, new Scenes(true), manager, new AsyncAwaitStatus()));
return (model, manager, document);
}
static PluginCommand[] CommandsOf(UndoTreeCommandPlugin plugin) => [.. plugin.Commands.Cast<PluginCommand>()];
[Fact]
public void TheHostCanCreateThePluginAndFindItsDetails()
{
var plugin = Assert.IsType<UndoTreeCommandPlugin>(Activator.CreateInstance(typeof(UndoTreeCommandPlugin)));
Assert.Equal(Texts.UndoTree, plugin.Name);
Assert.Equal("routersys", plugin.Details.AuthorName);
Assert.Equal(4, plugin.Commands.Count());
}
[Fact]
public void EveryMoveHasItsOwnKeyAndAnAltArrowAsTheDefault()
{
var commands = CommandsOf(new UndoTreeCommandPlugin(() => null));
Assert.Equal(4, commands.Select(command => command.CommandKey).Distinct().Count());
Assert.All(commands, command => Assert.StartsWith(UndoTreeToolPlugin.Id + ".", command.CommandKey));
Assert.All(commands, command => Assert.True(command.SupportsShortcutKey));
Assert.All(commands, command => Assert.Equal(ModifierKeys.Alt, command.DefaultModifierKeys));
Assert.Equal([Key.Left, Key.Right, Key.Up, Key.Down], commands.Select(command => command.DefaultKey));
}
[Fact]
public void TheNamesTellTheToolAndTheMove()
{
var commands = CommandsOf(new UndoTreeCommandPlugin(() => null));
Assert.Equal(
[Texts.MoveToPreviousCreated, Texts.MoveToNextCreated, Texts.MoveToPreviousBranch, Texts.MoveToNextBranch],
commands.Select(command => command.Name[(Texts.UndoTree.Length + 2)..]));
Assert.All(commands, command => Assert.StartsWith(Texts.UndoTree + ": ", command.Name));
}
[Fact]
public void WithoutAToolViewNothingCanRunAndRunningDoesNothing()
{
var commands = CommandsOf(new UndoTreeCommandPlugin(() => null));
Assert.All(commands, command => Assert.False(command.CanExecute()));
Assert.All(commands, command => command.Execute());
}
[Fact]
public void TheKeysMoveThroughTheHistoryOfTheToolView()
{
var (model, manager, document) = Open();
var commands = CommandsOf(new UndoTreeCommandPlugin(() => model));
Histories.Edit(manager, () => document.X = 1);
var first = model.Items[1];
Histories.Edit(manager, () => document.X = 2);
var second = model.Items[2];
Assert.True(commands[0].CanExecute());
Assert.False(commands[1].CanExecute());
commands[0].Execute();
Assert.True(first.IsCurrent);
Assert.True(commands[1].CanExecute());
commands[1].Execute();
Assert.True(second.IsCurrent);
Assert.False(commands[2].CanExecute());
Assert.False(commands[3].CanExecute());
}
}