Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean more code in tests. #3

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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