-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
790 additions
and
104 deletions.
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
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); | ||
} | ||
} |
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 |
---|---|---|
@@ -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()); | ||
} | ||
} |
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 |
---|---|---|
@@ -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()); | ||
} | ||
} |
Oops, something went wrong.