Skip to content

Commit

Permalink
Update Docs for Release 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgaber committed Jun 22, 2020
1 parent d08755e commit 96da482
Show file tree
Hide file tree
Showing 9 changed files with 588 additions and 162 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![StyleCI](https://github.styleci.io/repos/261879333/shield)](https://github.styleci.io/repos/261879333)
[![Total Downloads](https://img.shields.io/packagist/dt/joshgaber/novaunit.svg?style=flat-square)](https://packagist.org/packages/joshgaber/novaunit)

NovaUnit is a unit-testing package for Laravel Nova, built using PHPUnit. NovaUnit provides you with assertions for Nova Actions, Lenses and Resources, so you can create great administration panels with confidence.
[NovaUnit](https://joshgaber.github.io/NovaUnit) is a unit-testing package for Laravel Nova, built using PHPUnit. NovaUnit provides you with assertions for Nova Actions, Lenses and Resources, so you can create great administration panels with confidence.

## Installation

Expand All @@ -34,16 +34,14 @@ class ClearLogsTest extends TestCase {
}
```

Currently, there are three traits: `NovaActionTest`, `NovaLensTest` and `NovaResourceTest`. To test these components, invoke the respective test class (ie. `novaAction` for Actions).

Once you've created the mock with the initial test class, you can begin testing different aspect of the component:

```php
$this->novaAction(ClearLogs::class)
->assertHasField('since_date');
```

For a list of available methods, see the [full docs site](https://joshgaber.github.io/NovaUnit/index.html).
For a list of available methods, see the [full docs site](https://joshgaber.github.io/NovaUnit).

### Changelog

Expand Down
204 changes: 204 additions & 0 deletions docs/actions.md
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.
133 changes: 133 additions & 0 deletions docs/fields.md
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.
Loading

0 comments on commit 96da482

Please sign in to comment.