dillingham / nova-assertions

Laravel Nova assertions for your tests
MIT License
79 stars 16 forks source link

assertFieldCount() on index returns 1 #12

Closed asivaneswaran closed 3 years ago

asivaneswaran commented 3 years ago

Trying to count the fields on the index page returns 1 everytime.

public function testIndexFields()
    {
        Association::factory()->create();

        $response = $this->novaIndex('associations');

        dd($response);
        $response->assertFieldCount(7);

    }

Response returns this:

 #data: "{"label":"Associations","resources":[{"id":{"attribute":"id","component":"id-field","helpText":null,"indexName":"ID","name":"ID","nullable":false,"panel":null,"prefixComponent":true,"readonly":false,"required":false,"sortable":true,"sortableUriKey":"id","stacked":false,"textAlign":"left","validationKey":"id","value":1},"fields":[{"attribute":"id","component":"id-field","helpText":null,"indexName":"ID","name":"ID","nullable":false,"panel":null,"prefixComponent":true,"readonly":false,"required":false,"sortable":true,"sortableUriKey":"id","stacked":false,"textAlign":"left","validationKey":"id","value":1},{"attribute":"name","component":"text-field","helpText":null,"indexName":"Nom","name":"Nom","nullable":false,"panel":null,"prefixComponent":true,"readonly":false,"required":true,"sortable":true,"sortableUriKey":"name","stacked":false,"textAlign":"left","validationKey":"name","value":"Ste-Caroline"},{"attribute":"logo","component":"file-field","helpText":null,"indexName":"Logo","name":"Logo","nullable":false,"panel":null,"prefixComponent":true,"readonly":false,"required":false,"sortable":false,"sortableUriKey":"logo","stacked":false,"textAlign":"center","validationKey":"logo","value":null,"thumbnailUrl":null,"previewUrl":null,"downloadable":false,"deletable":true,"acceptedTypes":"image\/*","maxWidth":250,"rounded":true},{"belongsToId":1,"belongsToRelationship":"responsible1","debounce":500,"displaysWithTrashed":false,"label":"Membres","resourceName":"members","reverse":false,"searchable":true,"withSubtitles":false,"showCreateRelationButton":false,"singularLabel":"Responsable 1","viewable":true,"attribute":"responsible1","component":"belongs-to-field","helpText":null,"indexName":"Responsable 1","name":"Responsable 1","nullable":false,"panel":null,"prefixComponent":true,"readonly":false,"required":true,"sortable":false,"sortableUriKey":"responsible_1_id","stacked":false,"textAlign":"left","validationKey":"responsible1","value":"Th\u00e9ophile Perron"},{"belongsToId":2,"belongsToRelationship":"responsible2","debounce":500,"displaysWithTrashed":false,"label":"Membres","resourceName":"members","reverse":false,"searchable":true,"withSubtitles":false,"showCreateRelationButton":false,"singularLabel":"Responsable 2","viewable":true,"attribute":"responsible2","component":"belongs-to-field","helpText":null,"indexName":"Responsable 2","name":"Responsable 2","nullable":false,"panel":null,"prefixComponent":true,"readonly":false,"required":true,"sortable":false,"sortableUriKey":"responsible_2_id","stacked":false,"textAlign":"left","validationKey":"responsible2","value":"Dominic Carrier"},{"attribute":"email","component":"text-field","helpText":null,"indexName":"Courriel","name":"Courriel","nullable":false,"panel":"Contact","prefixComponent":true,"readonly":false,"required":true,"sortable":false,"sortableUriKey":"email","stacked":false,"textAlign":"left","validationKey":"email","value":null}],"title":"Ste-Caroline","actions":[{"cancelButtonText":"Annuler","component":"confirm-action-modal","confirmButtonText":"Ex\u00e9cuter action","class":"btn-primary","confirmText":"\u00cates-vous s\u00fbr que vous voulez ex\u00e9cuter cette action\u2008?","destructive":false,"name":"Generate Export","uriKey":"generate-export","fields":[],"availableForEntireResource":false,"showOnDetail":true,"showOnIndex":true,"showOnTableRow":false,"standalone":false,"withoutConfirmation":false}],"authorizedToView":true,"authorizedToCreate":true,"authorizedToUpdate":true,"authorizedToDelete":true,"authorizedToRestore":true,"authorizedToForceDelete":true,"softDeletes":true,"softDeleted":false}],"prev_page_url":null,"next_page_url":null,"per_page":25,"per_page_options":[25,50,100],"softDeletes":true}"

But when I do this:

 $response->assertFieldsInclude(['name', 'logo', 'responsible1', 'responsible2', 'email']);

It passes...

dillingham commented 3 years ago
Screen Shot 2020-11-23 at 8 10 45 PM

Is there a field wrongly defined? Im working on something related that might also help (there is a bug)

dillingham commented 3 years ago

Published a fix, let me know if its still an issue for you