DocumentLayersTests.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. using PixiEditor.Models.DataHolders;
  2. using System;
  3. using Xunit;
  4. namespace PixiEditorTests.ModelsTests.DataHoldersTests
  5. {
  6. [Collection("Application collection")]
  7. public class DocumentLayersTests
  8. {
  9. [Fact]
  10. public void TestThatToggleLayerDoesNotToggleLastLayer()
  11. {
  12. using Document doc = new(5, 5);
  13. doc.AddNewLayer("layer");
  14. bool isActive = doc.Layers[^1].IsActive;
  15. doc.ToggleLayer(0);
  16. Assert.False(doc.Layers[^1].IsActive != isActive);
  17. }
  18. [Fact]
  19. public void TestThatToggleLayerTogglesLayer()
  20. {
  21. using Document doc = new(5, 5);
  22. doc.AddNewLayer("layer");
  23. doc.AddNewLayer("layer 1");
  24. doc.Layers[0].IsActive = true;
  25. doc.Layers[^1].IsActive = true;
  26. doc.ToggleLayer(0);
  27. Assert.False(doc.Layers[0].IsActive);
  28. Assert.True(doc.Layers[1].IsActive);
  29. }
  30. [Fact]
  31. public void TestThatToggleLayerDoesNothingOnNonExistingIndex()
  32. {
  33. using Document document = new Document(5, 5);
  34. document.AddNewLayer("test");
  35. document.ToggleLayer(1);
  36. document.ToggleLayer(-1);
  37. Assert.True(true);
  38. }
  39. [Theory]
  40. [InlineData(0, 2)]
  41. [InlineData(2, 0)]
  42. [InlineData(1, 1)]
  43. public void TestThatSelectLayersRangeSelectsRange(int startIndex, int endIndex)
  44. {
  45. using Document document = new Document(5, 5);
  46. document.AddNewLayer("1");
  47. document.AddNewLayer("2");
  48. document.AddNewLayer("3");
  49. document.SetMainActiveLayer(startIndex);
  50. document.SelectLayersRange(endIndex);
  51. for (int i = 0; i < document.Layers.Count; i++)
  52. {
  53. Assert.Equal(
  54. i >= Math.Min(startIndex, endIndex)
  55. && i <= Math.Max(startIndex, endIndex),
  56. document.Layers[i].IsActive);
  57. }
  58. }
  59. [Theory]
  60. [InlineData(0)]
  61. [InlineData(1)]
  62. [InlineData(2)]
  63. public void TestThatDeselectAllExceptDeselectsAllExceptLayer(int index)
  64. {
  65. using Document document = new Document(5, 5);
  66. document.AddNewLayer("1");
  67. document.AddNewLayer("2");
  68. document.AddNewLayer("3");
  69. document.SetMainActiveLayer(0);
  70. document.Layers[1].IsActive = true;
  71. document.Layers[2].IsActive = true;
  72. document.DeselectAllExcept(document.Layers[index]);
  73. foreach (var layer in document.Layers)
  74. {
  75. Assert.Equal(layer == document.Layers[index], layer.IsActive);
  76. }
  77. }
  78. [Fact]
  79. public void TestThatUpdateLayersColorMakesOnlyOneLayerMainColorAndOtherSecondary()
  80. {
  81. using Document document = new Document(1, 1);
  82. document.AddNewLayer("1");
  83. document.AddNewLayer("2");
  84. document.AddNewLayer("3");
  85. document.SetMainActiveLayer(0);
  86. document.Layers[1].IsActive = true; // This makes layer selected, but not main
  87. document.Layers[2].IsActive = true;
  88. document.UpdateLayersColor();
  89. Assert.Equal(Document.MainSelectedLayerColor, document.Layers[0].LayerHighlightColor);
  90. Assert.Equal(Document.SecondarySelectedLayerColor, document.Layers[1].LayerHighlightColor);
  91. Assert.Equal(Document.SecondarySelectedLayerColor, document.Layers[2].LayerHighlightColor);
  92. }
  93. [Fact]
  94. public void TestThatUpdateLayersColorMakesLayerMainColorAndRestNonActiveReturnsTransparent()
  95. {
  96. using Document document = new Document(1, 1);
  97. document.AddNewLayer("1");
  98. document.AddNewLayer("2");
  99. document.AddNewLayer("3");
  100. document.SetMainActiveLayer(1);
  101. document.UpdateLayersColor();
  102. string transparentHex = "#00000000";
  103. Assert.Equal(transparentHex, document.Layers[0].LayerHighlightColor);
  104. Assert.Equal(Document.MainSelectedLayerColor, document.Layers[1].LayerHighlightColor);
  105. Assert.Equal(transparentHex, document.Layers[2].LayerHighlightColor);
  106. }
  107. [Fact]
  108. public void TestThatSetNextSelectedLayerAsActiveSelectsFirstAvailableLayer()
  109. {
  110. using Document document = new Document(1, 1);
  111. document.AddNewLayer("1");
  112. document.AddNewLayer("2");
  113. document.AddNewLayer("3");
  114. document.AddNewLayer("4");
  115. foreach (var layer in document.Layers)
  116. {
  117. layer.IsActive = true;
  118. }
  119. document.SetNextSelectedLayerAsActive(document.Layers[1].GuidValue);
  120. Assert.Equal(document.Layers[0].GuidValue, document.ActiveLayerGuid);
  121. }
  122. }
  123. }