-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f4e989
commit ff8e1b0
Showing
3 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
packages/app-project/src/shared/components/SubjectPicker/SubjectPicker.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { mount, shallow } from 'enzyme' | ||
import { Grommet } from 'grommet' | ||
import nock from 'nock' | ||
import zooTheme from '@zooniverse/grommet-theme' | ||
|
||
import SubjectPicker, { StyledBox, SubjectDataTable } from './SubjectPicker' | ||
|
||
describe('Components > Subject Picker', function () { | ||
let wrapper | ||
const workflow = { | ||
id: '123345' | ||
} | ||
const subjectSet = { | ||
id: '4567', | ||
display_name: 'Test subject set', | ||
metadata: { | ||
indexFields: 'Date,Page' | ||
} | ||
} | ||
|
||
before(function () { | ||
wrapper = shallow( | ||
<SubjectPicker | ||
baseUrl="/workflow/12345/subject-set/4567" | ||
subjectSet={subjectSet} | ||
workflow={workflow} | ||
/> | ||
) | ||
}) | ||
|
||
it('should render', function () { | ||
expect(wrapper).to.be.ok() | ||
}) | ||
|
||
it('should show the subject set name', function () { | ||
const displayName = wrapper.find(StyledBox) | ||
expect(displayName).to.be.ok() | ||
}) | ||
|
||
describe('subject data table', function () { | ||
let wrapper | ||
|
||
before(async function () { | ||
const columns = [ | ||
'subject_id', | ||
'Page', | ||
'Date' | ||
] | ||
const rows = [ | ||
['1', '43', '23 January 1916'], | ||
['2', '44', '24 January 1916'], | ||
['3', '45', '25 January 1916'] | ||
] | ||
nock('https://subject-set-search-api.zooniverse.org/subjects') | ||
.get('/4567.json') | ||
.query(true) | ||
.reply(200, { | ||
columns, | ||
rows | ||
}) | ||
nock('https://panoptes-staging.zooniverse.org/api') | ||
.get('/subject_workflow_statuses') | ||
.query(true) | ||
.reply(200, { | ||
subject_workflow_statuses: [ | ||
{ classifications_count: 0, retired_at: null, links: { subject: '1' }}, | ||
{ classifications_count: 3, retired_at: null, links: { subject: '2' }}, | ||
{ classifications_count: 5, retired_at: "2018-01-30T21:09:49.396Z", links: { subject: '3' }} | ||
] | ||
}) | ||
wrapper = mount( | ||
<SubjectPicker | ||
subjectSet={subjectSet} | ||
workflow={workflow} | ||
/>, | ||
{ wrappingComponent: Grommet, wrappingComponentProps: { theme: zooTheme } } | ||
) | ||
// workaround to wait for the mock API calls to resolve | ||
await new Promise((resolve) => setTimeout(resolve, 100)); | ||
}) | ||
|
||
it('should have column headings, including indexed subject fields', function () { | ||
const dataTable = wrapper.find(SubjectDataTable) | ||
const headers = dataTable.prop('columns').map(column => column.header) | ||
expect(headers).to.deep.equal(['subject_id', 'Date', 'Page', 'status']) | ||
}) | ||
|
||
it('should have a row for each subject', function () { | ||
wrapper.update() | ||
const dataTable = wrapper.find(SubjectDataTable) | ||
expect(dataTable.prop('data').length).to.equal(3) | ||
}) | ||
}) | ||
}) |
36 changes: 36 additions & 0 deletions
36
packages/app-project/src/shared/components/SubjectPicker/helpers/checkRetiredStatus.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import nock from 'nock' | ||
import checkRetiredStatus from './checkRetiredStatus' | ||
|
||
describe('Components > Subject Picker > helpers > checkRetiredStatus', function () { | ||
let retirementStatuses | ||
|
||
before(async function () { | ||
const subject_ids = ['1', '2', '3'] | ||
const workflow = { | ||
id: '1' | ||
} | ||
const panoptes = nock('https://panoptes-staging.zooniverse.org/api') | ||
.get('/subject_workflow_statuses') | ||
.query(true) | ||
.reply(200, { | ||
subject_workflow_statuses: [ | ||
{ classifications_count: 0, retired_at: null, links: { subject: '1' }}, | ||
{ classifications_count: 3, retired_at: null, links: { subject: '2' }}, | ||
{ classifications_count: 5, retired_at: "2018-01-30T21:09:49.396Z", links: { subject: '3' }} | ||
] | ||
}) | ||
retirementStatuses = await checkRetiredStatus(subject_ids, workflow) | ||
}) | ||
|
||
it('should set the status of unclassified subjects', function () { | ||
expect(retirementStatuses['1']).to.equal('Unclassified') | ||
}) | ||
|
||
it('should set the status of classified subjects', function () { | ||
expect(retirementStatuses['2']).to.equal('In progress') | ||
}) | ||
|
||
it('should set the status of retired subjects', function () { | ||
expect(retirementStatuses['3']).to.equal('Retired') | ||
}) | ||
}) |
42 changes: 42 additions & 0 deletions
42
packages/app-project/src/shared/components/SubjectPicker/helpers/fetchRows.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import nock from 'nock' | ||
import fetchRows from './fetchRows' | ||
|
||
describe('Components > Subject Picker > helpers > fetchRows', function () { | ||
let data | ||
const expectedData = [ | ||
{ subject_id: '1', Page: '43', Date: '23 January 1916', status: 'Unclassified' }, | ||
{ subject_id: '2', Page: '44', Date: '24 January 1916', status: 'In progress' }, | ||
{ subject_id: '3', Page: '45', Date: '25 January 1916', status: 'Retired' }, | ||
] | ||
|
||
before(async function () { | ||
const columns = [ | ||
'subject_id', | ||
'Page', | ||
'Date' | ||
] | ||
const rows = [ | ||
['1', '43', '23 January 1916'], | ||
['2', '44', '24 January 1916'], | ||
['3', '45', '25 January 1916'] | ||
] | ||
const workflow = { | ||
id: '1' | ||
} | ||
const panoptes = nock('https://panoptes-staging.zooniverse.org/api') | ||
.get('/subject_workflow_statuses') | ||
.query(true) | ||
.reply(200, { | ||
subject_workflow_statuses: [ | ||
{ classifications_count: 0, retired_at: null, links: { subject: '1' }}, | ||
{ classifications_count: 3, retired_at: null, links: { subject: '2' }}, | ||
{ classifications_count: 5, retired_at: "2018-01-30T21:09:49.396Z", links: { subject: '3' }} | ||
] | ||
}) | ||
data = await fetchRows({ columns, rows }, workflow) | ||
}) | ||
|
||
it('should generate subject data table rows with classification statuses', function () { | ||
expect(data).to.deep.equal(expectedData) | ||
}) | ||
}) |