Skip to content

Commit

Permalink
Clean more code in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Nov 20, 2023
1 parent 631b72d commit 2bdfae2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
39 changes: 13 additions & 26 deletions tests/SelectizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public function setup(): void
parent::setUp();
$this->mockApplication();

Selectize::$counter = 0;

$this->view = Yii::$app->getView();
}

Expand Down Expand Up @@ -138,28 +140,23 @@ public function testItemsWithTypeTextInput(): void

public function testLoadUrl(): void
{
$selectizeDropdownList = Selectize::widget(
$selectize = Selectize::widget(
[
'attribute' => 'tags',
'loadUrl' => '/tags',
'model' => new SelectizeModel(),
],
);

$render = $this->view->renderFile(
__DIR__ . '/Support/main.php',
[
'widget' => $selectizeDropdownList,
],
);
$render = $this->view->renderFile(__DIR__ . '/Support/main.php', ['widget' => $selectize]);

Assert::equalsWithoutLE(
<<<HTML
<select id="selectizemodel-tags" name="SelectizeModel[tags]">
</select>
HTML,
$selectizeDropdownList,
$selectize,
);

$this->assertStringContainsString(
Expand Down Expand Up @@ -202,27 +199,22 @@ public function testLoadUrlWithTypeTextInput(): void

public function testRender(): void
{
$selectizeDropdownList = Selectize::widget(
$selectize = Selectize::widget(
[
'attribute' => 'tags',
'model' => new SelectizeModel(),
],
);

$render = $this->view->renderFile(
__DIR__ . '/Support/main.php',
[
'widget' => $selectizeDropdownList,
],
);
$render = $this->view->renderFile(__DIR__ . '/Support/main.php', ['widget' => $selectize]);

Assert::equalsWithoutLE(
<<<HTML
<select id="selectizemodel-tags" name="SelectizeModel[tags]">
</select>
HTML,
$selectizeDropdownList,
$selectize,
);

$this->assertStringContainsString(
Expand Down Expand Up @@ -264,22 +256,17 @@ public function testRenderWithTypeTextInput(): void

public function testWithoutModel(): void
{
$selectizeDropdownList = Selectize::widget(['name' => 'tags']);
$selectize = Selectize::widget(['name' => 'tags']);

$render = $this->view->renderFile(
__DIR__ . '/Support/main.php',
[
'widget' => $selectizeDropdownList,
],
);
$render = $this->view->renderFile(__DIR__ . '/Support/main.php', ['widget' => $selectize]);

Assert::equalsWithoutLE(
<<<HTML
<select id="w0" name="tags">
</select>
HTML,
$selectizeDropdownList,
$selectize,
);

$this->assertStringContainsString(
Expand All @@ -300,7 +287,7 @@ public function testWithoutModelWithTypeTextInput(): void

Assert::equalsWithoutLE(
<<<HTML
<select id="w1" name="tags">
<select id="w0" name="tags">
</select>
HTML,
Expand All @@ -310,7 +297,7 @@ public function testWithoutModelWithTypeTextInput(): void
$this->assertStringContainsString(
<<<JS
<script>jQuery(function ($) {
jQuery('#w1').selectize([]);
jQuery('#w0').selectize([]);
});</script>
JS,
$render,
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function mockApplication(): void
'@bower' => '@root/node_modules',
'@npm' => '@root/node_modules',
],
'basePath' => __DIR__,
'basePath' => dirname(__DIR__),
'components' => [
'assetManager' => [
'basePath' => __DIR__ . '/Support/runtime',
Expand Down

0 comments on commit 2bdfae2

Please sign in to comment.