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

Add assertion to check if a button is disabled #661

Merged
merged 5 commits into from
Jul 29, 2019
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
36 changes: 36 additions & 0 deletions src/Concerns/MakesAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,42 @@ public function assertDisabled($field)
return $this;
}

/**
* Assert that the given button is enabled.
*
* @param string $button
* @return $this
*/
public function assertButtonEnabled($button)
{
$element = $this->resolver->resolveForButtonPress($button);

PHPUnit::assertTrue(
$element->isEnabled(),
"Expected button [{$button}] to be enabled, but it wasn't."
);

return $this;
}

/**
* Assert that the given button is disabled.
*
* @param string $button
* @return $this
*/
public function assertButtonDisabled($button)
{
$element = $this->resolver->resolveForButtonPress($button);

PHPUnit::assertFalse(
$element->isEnabled(),
"Expected button [{$button}] to be disabled, but it wasn't."
);

return $this;
}

/**
* Assert that the given field is focused.
*
Expand Down
36 changes: 36 additions & 0 deletions tests/MakesAssertionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,42 @@ public function test_assert_disabled()
}
}

public function test_assert_button_enabled()
{
$this->expectException(ExpectationFailedException::class);
$this->expectExceptionMessage("Expected button [Cant press me] to be enabled, but it wasn't.");

$driver = m::mock(stdClass::class);
$resolver = m::mock(stdClass::class);
$resolver->shouldReceive('resolveForButtonPress->isEnabled')->andReturn(
true,
false
);
$browser = new Browser($driver, $resolver);

$browser->assertButtonEnabled('Press me');

$browser->assertButtonEnabled('Cant press me');
}

public function test_assert_button_disabled()
{
$this->expectException(ExpectationFailedException::class);
$this->expectExceptionMessage("Expected button [Press me] to be disabled, but it wasn't.");

$driver = m::mock(stdClass::class);
$resolver = m::mock(stdClass::class);
$resolver->shouldReceive('resolveForButtonPress->isEnabled')->twice()->andReturn(
false,
true
);
$browser = new Browser($driver, $resolver);

$browser->assertButtonDisabled('Cant press me');

$browser->assertButtonDisabled('Press me');
}

public function test_assert_focused()
{
$driver = m::mock(stdClass::class);
Expand Down