Skip to content

Commit

Permalink
✅ Adding tests for the attribute details page
Browse files Browse the repository at this point in the history
  • Loading branch information
abgeorge7 committed May 21, 2020
1 parent b100edb commit 493f401
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 2 deletions.
44 changes: 44 additions & 0 deletions cypress/fixtures/attributeDetails/allPatients.json
Original file line number Diff line number Diff line change
@@ -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"]
}
}
}
]
}
69 changes: 69 additions & 0 deletions cypress/fixtures/attributeDetails/patientSnapshot.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
]
}
]
}
}
55 changes: 55 additions & 0 deletions cypress/integration/attributeDetails.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
7 changes: 5 additions & 2 deletions src/components/AttributeDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit 493f401

Please sign in to comment.