From 493f401b4e369d84512ee7a6bea56c2859b29795 Mon Sep 17 00:00:00 2001 From: Abby George Date: Tue, 19 May 2020 13:10:30 -0500 Subject: [PATCH] :white_check_mark: Adding tests for the attribute details page --- .../attributeDetails/allPatients.json | 44 ++++++++++++ .../attributeDetails/patientSnapshot.json | 69 +++++++++++++++++++ cypress/integration/attributeDetails.js | 55 +++++++++++++++ src/components/AttributeDetails.js | 7 +- 4 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 cypress/fixtures/attributeDetails/allPatients.json create mode 100644 cypress/fixtures/attributeDetails/patientSnapshot.json create mode 100644 cypress/integration/attributeDetails.js diff --git a/cypress/fixtures/attributeDetails/allPatients.json b/cypress/fixtures/attributeDetails/allPatients.json new file mode 100644 index 0000000..e2a366c --- /dev/null +++ b/cypress/fixtures/attributeDetails/allPatients.json @@ -0,0 +1,44 @@ +{ + "resourceType": "Bundle", + "id": "1", + "link": [ + { + "relation": "self", + "url": "http://localhost:8000/Condition?_profile%3Abelow=http%3A%2F%2Ffhir.kids-first.io%2FStructureDefinition%2FPatient" + } + ], + "entry": [ + { + "fullUrl": "http://localhost:8000/Patient/123", + "resource": { + "resourceType": "Patient", + "id": "123", + "meta": { + "profile": ["http://fhir.kids-first.io/StructureDefinition/Patient"] + } + } + }, + { + "fullUrl": "http://localhost:8000/Patient/456", + "resource": { + "resourceType": "Patient", + "id": "456", + "meta": { + "lastUpdated": "2020-03-04T20:33:42.445+00:00", + "profile": ["http://fhir.kids-first.io/StructureDefinition/Patient"] + } + } + }, + { + "fullUrl": "http://localhost:8000/Patient/789", + "resource": { + "resourceType": "Patient", + "id": "789", + "meta": { + "lastUpdated": "2020-03-04T20:33:42.445+00:00", + "profile": ["http://fhir.kids-first.io/StructureDefinition/Patient"] + } + } + } + ] +} diff --git a/cypress/fixtures/attributeDetails/patientSnapshot.json b/cypress/fixtures/attributeDetails/patientSnapshot.json new file mode 100644 index 0000000..a3264a2 --- /dev/null +++ b/cypress/fixtures/attributeDetails/patientSnapshot.json @@ -0,0 +1,69 @@ +{ + "resourceType": "StructureDefinition", + "id": "TestPatient", + "url": "http://fhir.kidsfirst.org/StructureDefinition/Patient", + "name": "TestPatient", + "title": "TestPatient", + "type": "Patient", + "baseDefinition": "http://hl7.org/fhir/StructureDefinition/Patient", + "snapshot": { + "element": [ + { + "id": "Patient", + "path": "Patient" + }, + { + "id": "Patient.address", + "path": "Patient.address", + "type": [ + { + "code": "Address" + } + ] + }, + { + "id": "Patient.name", + "path": "Patient.name", + "type": [ + { + "code": "HumanName" + } + ] + }, + { + "id": "Patient.email", + "path": "Patient.email", + "type": [ + { + "code": "ContactPoint" + } + ] + }, + { + "id": "Patient.deceased", + "path": "Patient.deceased", + "type": [ + { + "code": "boolean" + } + ] + }, + { + "id": "Patient.extension:karyotypic-sex", + "path": "Patient.extension", + "sliceName": "karyotypic-sex", + "label": "karyotypicSex", + "min": 0, + "max": "1", + "type": [ + { + "code": "Extension", + "profile": [ + "http://fhir.kids-first.io/StructureDefinition/karyotypic-sex" + ] + } + ] + } + ] + } +} diff --git a/cypress/integration/attributeDetails.js b/cypress/integration/attributeDetails.js new file mode 100644 index 0000000..b7fad1b --- /dev/null +++ b/cypress/integration/attributeDetails.js @@ -0,0 +1,55 @@ +describe('Attribute Details', () => { + before(() => { + cy.server(); + cy.route({ + method: 'GET', + url: + 'https://damp-castle-44220.herokuapp.com/http://hapi.fhir.org/baseR4/StructureDefinition/Patient/$snapshot', + response: 'fixture:attributeDetails/patientSnapshot.json', + }).as('getSnapshot'); + cy.route({ + method: 'GET', + url: + 'https://damp-castle-44220.herokuapp.com/http://hapi.fhir.org/baseR4/Patient?_profile:below=http://fhir.kidsfirst.org/StructureDefinition/Patient', + response: 'fixture:attributeDetails/allPatients.json', + }).as('getAll'); + cy.visit('/resources/Patient/all'); + cy.wait(['@getSnapshot', '@getAll']); + }); + + it('loads the attribute details into a table', () => { + cy.url().should('include', '/resources/Patient/all'); + cy.get('.sortable-table') + .children('table') + .children('tbody') + .children('tr') + .should($x => { + expect($x).to.have.length(3); + }); + }); + + it('formats dates properly', () => { + cy.get('.sortable-table') + .children('table') + .children('tbody') + .children('tr') + .each(($el, index, $list) => { + if (index === 0) { + cy.contains('Unknown'); + } else { + cy.contains('March 3, 2020'); + } + }); + }); + + it('goes to an ID detail page on row click', () => { + cy.get('.sortable-table') + .children('table') + .children('tbody') + .children('tr') + .eq(0) + .click(); + + cy.url().should('include', '/resources/Patient/id=123'); + }); +}); diff --git a/src/components/AttributeDetails.js b/src/components/AttributeDetails.js index d2ae4ea..cb8a074 100644 --- a/src/components/AttributeDetails.js +++ b/src/components/AttributeDetails.js @@ -60,7 +60,10 @@ class AttributeDetails extends React.Component { .map(x => x.resource) .map(x => ({ id: x.id, - lastUpdated: x.meta ? x.meta.lastUpdated : 'Unknown', + lastUpdated: + !!x.meta && !!x.meta.lastUpdated + ? x.meta.lastUpdated + : 'Unknown', })); this.setState({ data: mappedData, @@ -103,7 +106,7 @@ class AttributeDetails extends React.Component { display: 'Last Updated', sortId: 'lastUpdated', sort: true, - func: str => this.formatDate(str), + func: str => (str !== 'Unknown' ? this.formatDate(str) : str), }, ]; return (