-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
9 changed files
with
588 additions
and
162 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
# Actions | ||
|
||
* [Testing Actions](#testing-actions) | ||
* [Testing Action Handle](#testing-action-handle) | ||
* [Testing Actions on Components](#testing-actions-on-components) | ||
* [Testing Actions Individually](#testing-actions-individually) | ||
|
||
## Testing Actions | ||
|
||
To create the testing object for a Nova Action, add the `NovaActionTest` trait to your class, and invoke the test method. | ||
|
||
```php | ||
class TestClass extends TestCase | ||
{ | ||
use NovaActionTest; | ||
|
||
public function testNovaAction() | ||
{ | ||
$action = $this->novaAction(MyAction::class); | ||
} | ||
} | ||
``` | ||
|
||
The following assertions can be run on the Nova Action: | ||
|
||
* [Fields](fields.md#testing-fields-on-components) | ||
|
||
## Testing Action Handle | ||
|
||
```php | ||
$response = $action->handle($fields, $models); | ||
``` | ||
|
||
Invokes the `handle` method on the action with the given parameters. | ||
|
||
* `$fields` - A key-value array with the input values of the action fields, indexed by attribute. Eg., `['name' => 'John Smith']` | ||
* `$models` - A list of the models to apply the action to. Value can be either an array, an Eloquent collection, or a single Model. | ||
|
||
### `assertMessage()` | ||
|
||
```php | ||
$response->assertMessage(); | ||
``` | ||
|
||
Assert that this action will return an `Action::message()` response with the given input | ||
|
||
### `assertDanger()` | ||
|
||
```php | ||
$response->assertDanger(); | ||
``` | ||
|
||
Assert that this action will return an `Action::danger()` response with the given input | ||
|
||
### `assertDeleted()` | ||
|
||
```php | ||
$response->assertDeleted(); | ||
``` | ||
|
||
Assert that this action will return an `Action::deleted()` response with the given input | ||
|
||
### `assertRedirect()` | ||
|
||
```php | ||
$response->assertRedirect(); | ||
``` | ||
|
||
Assert that this action will return an `Action::redirect()` response with the given input | ||
|
||
### `assertPush()` | ||
|
||
```php | ||
$response->assertPush(); | ||
``` | ||
|
||
Assert that this action will return an `Action::push()` response with the given input | ||
|
||
### `assertOpenInNewTab()` | ||
|
||
```php | ||
$response->assertOpenInNewTab(); | ||
``` | ||
|
||
Assert that this action will return an `Action::openInNewTab()` response with the given input | ||
|
||
### `assertDownload()` | ||
|
||
```php | ||
$response->assertDownload(); | ||
``` | ||
|
||
Assert that this action will return an `Action::download()` response with the given input | ||
|
||
### `assertMessageContains($contents)` | ||
|
||
```php | ||
$response->assertMessageContains('Success'); | ||
``` | ||
|
||
Assert that the `Action::message()` response contains `$contents` | ||
|
||
### `assertDangerContains($contents)` | ||
|
||
```php | ||
$response->assertDangerContains('Failure'); | ||
``` | ||
|
||
Assert that the `Action::danger()` response contains `$contents` | ||
|
||
## Testing Actions on Components | ||
|
||
Action assertions can be run on the following Nova classes: | ||
|
||
* [Lenses](lenses.md#testing-lenses) | ||
* [Resources](resources.md#testing-resources) | ||
|
||
### `assertHasAction($action)` | ||
|
||
```php | ||
$component->assertHasAction(MyAction::class); | ||
``` | ||
|
||
Asserts that the provided class path `$action` matches one of the actions returned by the `actions()` method | ||
|
||
### `assertActionMissing($action)` | ||
|
||
```php | ||
$component->assertActionMissing(MyAction::class); | ||
``` | ||
|
||
Asserts that the provided class path `$action` does not match any actions returned by the `actions()` method | ||
|
||
### `assertHasNoAction()` | ||
|
||
```php | ||
$component->assertHasNoActions(); | ||
``` | ||
|
||
Asserts that the `actions()` method returns an empty array. | ||
|
||
### `assertHasValidActions()` | ||
|
||
```php | ||
$component->assertHasValidActions(); | ||
``` | ||
|
||
Asserts that all actions returned by the `actions()` method are valid Nova Actions. | ||
|
||
## Testing Actions Individually | ||
|
||
```php | ||
$action = $component->action(MyAction::class); | ||
``` | ||
|
||
Searches the `actions()` method on the component for the first occurance of an action matching the provided class name, and returns a testing object. | ||
|
||
### `assertShownOnIndex()` | ||
|
||
```php | ||
$action->assertShownOnIndex(); | ||
``` | ||
|
||
Asserts that the action will be shown on this component's index view. | ||
|
||
### `assertHiddenFromIndex()` | ||
|
||
```php | ||
$action->assertHiddenFromIndex(); | ||
``` | ||
|
||
Asserts that the action will be hidden from this component's index view. | ||
|
||
### `assertShownOnDetail()` | ||
|
||
```php | ||
$action->assertShownOnDetail(); | ||
``` | ||
|
||
Asserts that the action will be shown on this component's detail view. | ||
|
||
### `assertHiddenFromDetail()` | ||
|
||
```php | ||
$action->assertHiddenFromDetail(); | ||
``` | ||
|
||
Asserts that the action will be hidden from this component's detail view. | ||
|
||
### `assertShownOnTableRow()` | ||
|
||
```php | ||
$action->assertShownOnTableRow(); | ||
``` | ||
|
||
Asserts that the action will be shown on this component's table row view. | ||
|
||
### `assertHiddenFromTableRow()` | ||
|
||
```php | ||
$action->assertHiddenFromTableRow(); | ||
``` | ||
|
||
Asserts that the action will be hidden from this component's table row view. |
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,133 @@ | ||
# Fields | ||
|
||
* [Testing Fields on Components](#testing-fields-on-components) | ||
* [Testing Fields Individually](#testing-fields-individually) | ||
|
||
## Testing Fields on Components | ||
|
||
Field assertions can be run on the following Nova classes: | ||
|
||
* [Actions](actions.md#testing-actions) | ||
* [Lenses](lenses.md#testing-lenses) | ||
* [Resources](resources.md#testing-resources) | ||
|
||
### `assertHasField($field)` | ||
|
||
```php | ||
$component->assertHasField('field_name'); | ||
``` | ||
|
||
Asserts that the provided string matches the name or attribute of one of the fields returned by the `fields()` method | ||
|
||
### `assertFieldMissing($field)` | ||
|
||
```php | ||
$component->assertFieldMissing('field_name'); | ||
``` | ||
|
||
Asserts that the provided string does not match the name or attribute of one of the fields returned by the `fields()` method | ||
|
||
### `assertHasNoFields()` | ||
|
||
```php | ||
$component->assertHasNoFields(); | ||
``` | ||
|
||
Asserts that the `fields()` method returns an empty array. | ||
|
||
### `assertHasValidFields()` | ||
|
||
```php | ||
$component->assertHasValidFields(); | ||
``` | ||
|
||
Asserts that all fields returned by the `fields()` method are valid Nova Fields. | ||
|
||
## Testing Fields Individually | ||
|
||
To test configuration of a component's individual fields, you may use the `field($fieldName)` method: | ||
|
||
```php | ||
$field = $component->field('field_name'); | ||
``` | ||
|
||
Searches the components `fields()` array for a field with a name or attribute matching `$fieldname`, and returns first occurrence in a testing class. | ||
|
||
### `assertHasRule($rule)` | ||
|
||
```php | ||
$field->assertHasRule('required'); | ||
``` | ||
|
||
Asserts that the following rule is being applied to the value of this field. This assertion only works on string-type rules, not closures. | ||
|
||
### `assertRuleMissing($rule)` | ||
|
||
```php | ||
$field->assertRuleMissing('required'); | ||
``` | ||
Asserts that the following rule is not being applied to the value of this field. This assertion only works on string-type rules, not closures. | ||
|
||
### `assertShownOnIndex()` | ||
|
||
```php | ||
$field->assertShownOnIndex(); | ||
``` | ||
|
||
Asserts that the field will be shown on the component's index view. | ||
|
||
### `assertHiddenFromIndex()` | ||
|
||
```php | ||
$field->assertHiddenFromIndex(); | ||
``` | ||
|
||
Asserts that the field will be hidden from the component's index view. | ||
|
||
### `assertShownOnDetail()` | ||
|
||
```php | ||
$field->assertShownOnDetail(); | ||
``` | ||
|
||
Asserts that the field will be shown on the component's detail view. | ||
|
||
### `assertHiddenFromDetail()` | ||
|
||
```php | ||
$field->assertHiddenFromDetail(); | ||
``` | ||
|
||
Asserts that the field will be hidden from the component's detail view. | ||
|
||
### `assertNullable()` | ||
|
||
```php | ||
$field->assertNullable(); | ||
``` | ||
|
||
Asserts that the value of this field will be set to null if left empty. | ||
|
||
### `assertNotNullable()` | ||
|
||
```php | ||
$field->assertNotNullable(); | ||
``` | ||
|
||
Asserts that the value of this field will not be set to null if left empty. | ||
|
||
### `assertSortable()` | ||
|
||
```php | ||
$field->assertSortable(); | ||
``` | ||
|
||
Asserts that the component's records can be sorted by this field. | ||
|
||
### `assertNotSortable()` | ||
|
||
```php | ||
$field->assertNotSortable(); | ||
``` | ||
|
||
Asserts that the component's records cannot be sorted by this field. |
Oops, something went wrong.