-
Notifications
You must be signed in to change notification settings - Fork 1
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
25 changed files
with
264 additions
and
13 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
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
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,15 +1,15 @@ | ||
{% set _className = _spiritClassPrefix ~ 'Grid' %} | ||
{% set _class = (props.class is defined) ? ' ' ~ props.class : '' -%} | ||
{% set _elementType = (props.elementType is defined) ? props.elementType : 'div' -%} | ||
{% set _layoutClass = (props.layout is defined) ? ' Grid--' ~ props.layout : '' -%} | ||
{% set _colsClass = (props.cols is defined) ? ' Grid--cols-' ~ props.cols : '' -%} | ||
{% set _tabletClass = (props.tablet is defined) ? ' Grid--table--cols-' ~ props.tablet : '' -%} | ||
{% set _class = (props.class is defined) ? ' ' ~ props.class : '' %} | ||
{% set _elementType = (props.elementType is defined) ? props.elementType : 'div' %} | ||
{% set _layoutClass = (props.layout is defined) ? ' Grid--' ~ props.layout : '' %} | ||
{% set _colsClass = (props.cols is defined) ? ' Grid--cols-' ~ props.cols : '' %} | ||
{% set _tabletClass = (props.tablet is defined) ? ' Grid--table--cols-' ~ props.tablet : '' %} | ||
{% set _desktopClass = (props.desktop is defined) ? ' Grid--desktop--cols-' ~ props.desktop : '' -%} | ||
|
||
{% if props.cols is defined and props.tablet is defined and props.desktop %} | ||
{% set _layoutClass = '' -%} | ||
{% set _layoutClass = '' %} | ||
{% endif %} | ||
|
||
<{{ _elementType }} class="{{ _className }}{{ _layoutClass }}{{ _colsClass }}{{ _class }}"> | ||
{%- block content %}{% endblock %} | ||
{% block content %}{% endblock %} | ||
</{{ _elementType }}> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Lmc\SpiritWebTwigBundle; | ||
|
||
use Lmc\SpiritWebTwigBundle\Compiler\ComponentLexer; | ||
use Lmc\SpiritWebTwigBundle\DependencyInjection\CompilerPass\OverrideServiceCompilerPass; | ||
use Lmc\SpiritWebTwigBundle\DependencyInjection\SpiritWebTwigExtension; | ||
use PHPUnit\Framework\TestCase; | ||
use Spatie\Snapshots\MatchesSnapshots; | ||
use Twig\Environment; | ||
use Twig\Loader\FilesystemLoader; | ||
|
||
final class ComponentsSnapshotTest extends TestCase | ||
{ | ||
use MatchesSnapshots; | ||
|
||
protected Environment $twig; | ||
|
||
private const SNAPSHOT_SOURCES = __DIR__ . '/components-fixtures'; | ||
|
||
protected function setupTwig(?string $prefix = null): Environment | ||
{ | ||
$alias = 'spirit'; | ||
$loader = new FilesystemLoader(self::SNAPSHOT_SOURCES); | ||
$loader->addPath(SpiritWebTwigExtension::DEFAULT_COMPONENTS_PATH, SpiritWebTwigExtension::DEFAULT_PATH_ALIAS); | ||
|
||
$twig = new Environment($loader, [ | ||
'cache' => false, | ||
]); | ||
|
||
if ($prefix) { | ||
$twig->addGlobal(OverrideServiceCompilerPass::GLOBAL_PREFIX_TWIG_VARIABLE, $prefix); | ||
} | ||
|
||
$twig->setLoader($loader); | ||
$twig->setLexer(new ComponentLexer($twig, [], $alias)); | ||
|
||
return $twig; | ||
} | ||
|
||
public function setUp(): void | ||
{ | ||
$this->twig = $this->setupTwig(); | ||
} | ||
|
||
/** | ||
* @dataProvider snapshotComponentsDataProvider | ||
*/ | ||
public function testShouldSnapshotComponents(string $template): void | ||
{ | ||
$html = $this->twig->render($template); | ||
|
||
$this->assertMatchesHtmlSnapshot($html); | ||
} | ||
|
||
/** | ||
* @return array<string, array<string>> | ||
*/ | ||
public function snapshotComponentsDataProvider(): array | ||
{ | ||
$scanDirArray = scandir(self::SNAPSHOT_SOURCES); | ||
|
||
assert(is_array($scanDirArray)); | ||
|
||
$scannedDirectory = array_diff($scanDirArray, ['..', '.']); | ||
$dataToProvide = []; | ||
|
||
foreach ($scannedDirectory as $fileName) { | ||
$dataToProvide[(string) $fileName] = [(string) $fileName]; | ||
} | ||
|
||
return $dataToProvide; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...ntsSnapshotTest__testShouldSnapshotComponents with data set containerDefault.twig__1.html
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,4 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> | ||
<html><body> | ||
<div class="Container">Content</div> | ||
</body></html> |
5 changes: 5 additions & 0 deletions
5
...napshotTest__testShouldSnapshotComponents with data set containerDefaultPure.twig__1.html
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,5 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> | ||
<html><body> | ||
<div class="Container"> Content | ||
</div> | ||
</body></html> |
11 changes: 11 additions & 0 deletions
11
...mponentsSnapshotTest__testShouldSnapshotComponents with data set gridDefault.twig__1.html
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,11 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> | ||
<html><body> | ||
<div class="Grid Grid--cols-2"> | ||
<span>col 1</span> | ||
<span>col 2</span> | ||
<span>col 3</span> | ||
<span>col 4</span> | ||
<span>col 5</span> | ||
<span>col 6</span> | ||
</div> | ||
</body></html> |
11 changes: 11 additions & 0 deletions
11
...entsSnapshotTest__testShouldSnapshotComponents with data set gridDefaultPure.twig__1.html
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,11 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> | ||
<html><body> | ||
<div class="Grid Grid--cols-2"> | ||
<span>col 1</span> | ||
<span>col 2</span> | ||
<span>col 3</span> | ||
<span>col 4</span> | ||
<span>col 5</span> | ||
<span>col 6</span> | ||
</div> | ||
</body></html> |
19 changes: 19 additions & 0 deletions
19
...ponentsSnapshotTest__testShouldSnapshotComponents with data set stackDefault.twig__1.html
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,19 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> | ||
<html><body> | ||
<div class="Stack"> | ||
<div>Block 1</div> | ||
<div>Block 2</div> | ||
<div>Block 3</div> | ||
</div> | ||
<ul class="Stack"> | ||
<li> | ||
<div>List item 1</div> | ||
</li> | ||
<li> | ||
<div>List item 1</div> | ||
</li> | ||
<li> | ||
<div>List item 1</div> | ||
</li> | ||
</ul> | ||
</body></html> |
20 changes: 20 additions & 0 deletions
20
...ntsSnapshotTest__testShouldSnapshotComponents with data set stackDefaultPure.twig__1.html
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,20 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> | ||
<html><body> | ||
<div class="Stack"> | ||
<div>Block 1</div> | ||
<div>Block 2</div> | ||
<div>Block 3</div> | ||
</div> | ||
|
||
<ul class="Stack"> | ||
<li> | ||
<div>List item 1</div> | ||
</li> | ||
<li> | ||
<div>List item 1</div> | ||
</li> | ||
<li> | ||
<div>List item 1</div> | ||
</li> | ||
</ul> | ||
</body></html> |
13 changes: 13 additions & 0 deletions
13
...ntsSnapshotTest__testShouldSnapshotComponents with data set textFieldDefault.twig__1.html
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,13 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> | ||
<html><body> | ||
<div class="TextField TextField--error"> | ||
<label for="example" class="TextField__label TextField__label--required">Text field</label> | ||
<input type="text" id="example" name="example" class="TextField__input" required="true" value=""> | ||
</div> | ||
|
||
|
||
<div class="TextField TextField--error"> | ||
<label for="example2" class="TextField__label TextField__label--required">Password field</label> | ||
<input type="password" id="example2" name="example2" class="TextField__input" required="true" value=""> | ||
</div> | ||
</body></html> |
6 changes: 6 additions & 0 deletions
6
...napshotTest__testShouldSnapshotComponents with data set textFieldDefaultPure.twig__1.html
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,6 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> | ||
<html><body><div class="TextField TextField--error"> | ||
<label for="example" class="TextField__label"></label> | ||
<input type="text" id="example" name="example" class="TextField__input" required="true" value=""> | ||
<div class="TextField__message">validation failed</div> | ||
</div></body></html> |
5 changes: 5 additions & 0 deletions
5
...Test__testShouldSnapshotComponents with data set textFieldWithInvisibleLabel.twig__1.html
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,5 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> | ||
<html><body><div class="TextField"> | ||
<label for="example" class="TextField__label TextField__label--hidden"></label> | ||
<input type="text" id="example" name="example" class="TextField__input" required="true" value=""> | ||
</div></body></html> |
1 change: 1 addition & 0 deletions
1
packages/web-twig/tests/components-fixtures/containerDefault.twig
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 @@ | ||
<Container>Content</Container> |
5 changes: 5 additions & 0 deletions
5
packages/web-twig/tests/components-fixtures/containerDefaultPure.twig
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,5 @@ | ||
{% embed "@spirit/container.twig" %} | ||
{% block content %} | ||
Content | ||
{% endblock %} | ||
{% endembed %} |
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,8 @@ | ||
<Grid cols="2" tablet="3" desktop="4"> | ||
<span>col 1</span> | ||
<span>col 2</span> | ||
<span>col 3</span> | ||
<span>col 4</span> | ||
<span>col 5</span> | ||
<span>col 6</span> | ||
</Grid> |
14 changes: 14 additions & 0 deletions
14
packages/web-twig/tests/components-fixtures/gridDefaultPure.twig
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,14 @@ | ||
{% embed "@spirit/grid.twig" with { props: { | ||
cols: 2, | ||
tablet: 3, | ||
desktop: 4, | ||
}} %} | ||
{% block content %} | ||
<span>col 1</span> | ||
<span>col 2</span> | ||
<span>col 3</span> | ||
<span>col 4</span> | ||
<span>col 5</span> | ||
<span>col 6</span> | ||
{% endblock %} | ||
{% endembed %} |
16 changes: 16 additions & 0 deletions
16
packages/web-twig/tests/components-fixtures/stackDefault.twig
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,16 @@ | ||
<Stack> | ||
<div>Block 1</div> | ||
<div>Block 2</div> | ||
<div>Block 3</div> | ||
</Stack> | ||
<Stack elementType="ul"> | ||
<li> | ||
<div>List item 1</div> | ||
</li> | ||
<li> | ||
<div>List item 1</div> | ||
</li> | ||
<li> | ||
<div>List item 1</div> | ||
</li> | ||
</Stack> |
23 changes: 23 additions & 0 deletions
23
packages/web-twig/tests/components-fixtures/stackDefaultPure.twig
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,23 @@ | ||
{% embed "@spirit/stack.twig" %} | ||
{% block content %} | ||
<div>Block 1</div> | ||
<div>Block 2</div> | ||
<div>Block 3</div> | ||
{% endblock %} | ||
{% endembed %} | ||
|
||
{% embed "@spirit/stack.twig" with { props: { | ||
elementType: 'ul' | ||
}} %} | ||
{% block content %} | ||
<li> | ||
<div>List item 1</div> | ||
</li> | ||
<li> | ||
<div>List item 1</div> | ||
</li> | ||
<li> | ||
<div>List item 1</div> | ||
</li> | ||
{% endblock %} | ||
{% endembed %} |
2 changes: 2 additions & 0 deletions
2
packages/web-twig/tests/components-fixtures/textFieldDefault.twig
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,2 @@ | ||
<TextField id="example" label="Text field" type="text" name="example" required validationState="error" messsage="validation failed" /> | ||
<TextField id="example2" label="Password field" type="password" name="example2" required validationState="error" messsage="validation failed" /> |
8 changes: 8 additions & 0 deletions
8
packages/web-twig/tests/components-fixtures/textFieldDefaultPure.twig
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,8 @@ | ||
{% include "@spirit/textField.twig" with { props: { | ||
id: "example", | ||
type: "text", | ||
name: "example", | ||
required: "true", | ||
validationState: "error", | ||
message: "validation failed", | ||
}} %} |
1 change: 1 addition & 0 deletions
1
packages/web-twig/tests/components-fixtures/textFieldWithInvisibleLabel.twig
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 @@ | ||
<TextField id="example" type="text" name="example" isLabelHidden required /> |