Skip to content

Commit

Permalink
complete
Browse files Browse the repository at this point in the history
  • Loading branch information
capdiem committed May 18, 2024
1 parent 232b2b5 commit 8e529e3
Show file tree
Hide file tree
Showing 17 changed files with 790 additions and 104 deletions.
70 changes: 70 additions & 0 deletions BemIt.Tests/BlockOrElementExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
namespace BemIt.Tests;

using Xunit;
using BemIt;

public class BlockOrElementExtensionsTests
{
[Fact]
public void Modifier_WithTrueCondition_ReturnsCorrectModifier()
{
var block = new Block("block");
var result = block.Modifier(true, "modifier");

Assert.Equal("block--modifier", result);
}

[Fact]
public void Modifier_WithFalseCondition_ReturnsEmptyString()
{
var block = new Block("block");
var result = block.Modifier(false, "modifier");

Assert.Equal(string.Empty, result);
}

[Fact]
public void Modifier_WithConditionAndModifier_ReturnsCorrectModifier()
{
var block = new Block("block");
var result = block.Modifier("modifier", true);

Assert.Equal("block--modifier", result);
}

[Fact]
public void Modifier_WithConditionAndModifier_ReturnsEmptyString()
{
var block = new Block("block");
var result = block.Modifier("modifier", false);

Assert.Equal(string.Empty, result);
}

[Fact]
public void Modifier_WithEnum_ReturnsCorrectModifier()
{
var block = new Block("block");
var result = block.Modifier(Density.Default);

Assert.Equal("block--density-default", result);
}

[Fact]
public void Modifier_WithEnumAndExclude_ReturnsCorrectModifier()
{
var block = new Block("block");
var result = block.Modifier(Density.Comfortable, Density.Default);

Assert.Equal("block--density-comfortable", result);
}

[Fact]
public void Modifier_WithEnumAndExclude_ReturnsEmptyString()
{
var block = new Block("block");
var result = block.Modifier(Density.Default, Density.Default);

Assert.Equal(string.Empty, result);
}
}
92 changes: 91 additions & 1 deletion BemIt.Tests/BlockTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,96 @@
namespace BemIt.Tests;

using BemIt;

public class BlockTests
{
private readonly Block _block = new("m-list-item");
[Fact]
public void Test()
{
var outlined = true;
var isDisabled = true;
var density = Density.Dense;

var cardModifierBuilder = new Block("card")
.CreateModifierBuilder()
.Add(outlined)
.Add("disabled", isDisabled)
.Add(density)
.AddClass("theme--light");

Assert.Equal("card card--outlined card--disabled card--density-dense theme--light", cardModifierBuilder.ToString());
}

enum Density
{
Dense,
Comfortable,
Compact,
}

[Fact]
public void Constructor_WithValidName_InitializesNameProperty()
{
var block = new Block("validName");

Assert.Equal("validname", block.Name);
}

[Fact]
public void Constructor_WithNullName_ThrowsArgumentException()
{
Assert.Throws<ArgumentNullException>(() => new Block(null));
}

[Theory]
[InlineData("")]
[InlineData(" ")]
public void Constructor_WithWhiteSpaceName_ThrowsArgumentException(string invalidName)
{
Assert.Throws<ArgumentException>(() => new Block(invalidName));
}

[Fact]
public void Element_WithValidName_ReturnsElementWithCorrectName()
{
var block = new Block("block");
var element = block.Element("element");

Assert.Equal("block__element", element.Name);
}

[Fact]
public void CreateModifierBuilder_ReturnsModifierBuilderWithCorrectName()
{
var block = new Block("block");
var modifierBuilder = block.CreateModifierBuilder();

Assert.Equal("block", modifierBuilder.ToString());
}

[Fact]
public void CreateModifierBuilder_AddModifier_AppendsModifier()
{
var block = new Block("block");
var modifierBuilder = block.CreateModifierBuilder().Add("modifier");

Assert.Equal("block block--modifier", modifierBuilder.ToString());
}

[Fact]
public void CreateModifierBuilder_AddClass_AppendsClasses()
{
var block = new Block("block");
var modifierBuilder = block.CreateModifierBuilder().AddClass("class");

Assert.Equal("block class", modifierBuilder.ToString());
}

[Fact]
public void ToString_ReturnsNameInLowerCase()
{
var block = new Block("BLOCK");

Assert.Equal("block", block.ToString());
}
}
48 changes: 46 additions & 2 deletions BemIt.Tests/ElementTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,50 @@
namespace BemIt.Tests;

using Xunit;
using BemIt;

public class ElementTests
{
private readonly Block _block = new("m-list-item");
}
[Fact]
public void Constructor_WithValidNames_InitializesNameProperty()
{
var element = new Element("validBlock", "validElement");

Assert.Equal("validblock__validelement", element.Name);
}

[Theory]
[InlineData(null, "validElement")]
[InlineData("validBlock", null)]
public void Constructor_WithNullNames_ThrowsArgumentException(string block, string element)
{
Assert.Throws<ArgumentNullException>(() => new Element(block, element));
}

[Theory]
[InlineData("", "validElement")]
[InlineData(" ", "validElement")]
[InlineData("validBlock", "")]
[InlineData("validBlock", " ")]
public void Constructor_WithWhiteSpaceNames_ThrowsArgumentException(string block, string element)
{
Assert.Throws<ArgumentException>(() => new Element(block, element));
}

[Fact]
public void CreateModifierBuilder_ReturnsModifierBuilderWithCorrectName()
{
var element = new Element("block", "element");
var modifierBuilder = element.CreateModifierBuilder();

Assert.Equal("block__element", modifierBuilder.ToString());
}

[Fact]
public void ToString_ReturnsNameInLowerCase()
{
var element = new Element("BLOCK", "ELEMENT");

Assert.Equal("block__element", element.ToString());
}
}
Loading

0 comments on commit 8e529e3

Please sign in to comment.