bradenkeith / testing-nova

A test suite demonstrating TDD with Nova
MIT License
104 stars 10 forks source link

A question about this project #2

Closed sunscreem closed 5 years ago

sunscreem commented 5 years ago

Honestly can't thank you enough for taking the time to clean up and share this repo. Its really been handy for me learning how to TDD a side project I'm working on that's using Nova.

I've a question though - how did you decide on the your approach to testing you nova app? I've hunted around but not found any blog posts or resources to guide me? I'm concerned that I'll start testing things I don't need to, since they will be being testing by the nova maintainers.

bradenkeith commented 5 years ago

No problem! Glad it's been helpful.

It's easy to think through this process if you go about it from the perspective of just testing what code you are adding to your app. IE: I am adding a field to a nova resource... I don't need to test that it shows the field, or does a particular function. I simply need to make sure it is present at the end point that the resource is looking for.

I add on to my resource fields:

            Text::make('Name'),

Therefore, I want to assert that I have a text field and that it's named Name. That is the code I inserted into the platform.

So I end up with this:

        $response = $this->get('/nova-api/branches/'.$resource->id);

        $response->assertJson([
            'resource' => [
                'id' => [
                    'value' => $resource->id,
                ],
                'fields' => [
                    [
                        'component' => 'text-field',
                        'attribute' => 'id',
                        'value'     => $resource->id,
                    ],
                    [
                        'component' => 'text-field',
                        'attribute' => 'name',
                        'value'     => $resource->name,
                    ],
                ],
            ],
        ]);

Hope that helps with the thought process!