Skip to content

Commit

Permalink
test(lib-classifier): test classification timestamps
Browse files Browse the repository at this point in the history
- [x] Add tests for classification `started_at` and `finished_at` timestamps.
- [ ] fix the failing test for classification start times.
  • Loading branch information
eatyourgreens committed Nov 7, 2024
1 parent 860f09f commit f5d0e07
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ const ClassificationMetadata = types.model('ClassificationMetadata', {
.actions(self => ({
afterAttach() {
function _onLocaleChange() {
self.update({
userLanguage: getRoot(self)?.locale
})
const userLanguage = getRoot(self)?.locale
if (userLanguage) {
self.update({ userLanguage })
}
}
addDisposer(self, autorun(_onLocaleChange))
},
Expand Down
48 changes: 48 additions & 0 deletions packages/lib-classifier/src/store/ClassificationStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('Model > ClassificationStore', function () {
describe('when a subject advances', function () {
let classifications
let rootStore

beforeEach(function () {
rootStore = setupStores({
dataVisAnnotating: {},
Expand Down Expand Up @@ -106,6 +107,53 @@ describe('Model > ClassificationStore', function () {
})

describe('on complete classification', function () {
describe('submitted classifications', function () {
let classifications
let rootStore
let clock
let submittedClassification

before(function () {
clock = sinon.useFakeTimers(new Date('2024-11-06T13:00:00Z'))
rootStore = setupStores({
dataVisAnnotating: {},
drawing: {},
feedback: {},
fieldGuide: {},
subjectViewer: {},
tutorials: {},
workflowSteps: {},
userProjectPreferences: {}
})

classifications = rootStore.classifications
classifications.setOnComplete(snapshot => {
console.log(snapshot)
submittedClassification = snapshot
})
const taskSnapshot = Object.assign({}, singleChoiceTaskSnapshot, { taskKey: singleChoiceAnnotationSnapshot.task })
taskSnapshot.createAnnotation = () => SingleChoiceAnnotation.create(singleChoiceAnnotationSnapshot)
clock.tick(1 * 60 * 60 * 1000) // wait for one hour before starting the classification.
classifications.addAnnotation(taskSnapshot, singleChoiceAnnotationSnapshot.value)
clock.tick(30 * 1000) // wait for 30 seconds before finishing the classification.
classifications.completeClassification()
})

after(function () {
clock.restore()
})

it('should record the started at time', function () {
const startedAt = submittedClassification.metadata.started_at
expect(startedAt).to.equal('2024-11-06T14:00:00.000Z')
})

it('should record the finished at time', function () {
const finishedAt = submittedClassification.metadata.finished_at
expect(finishedAt).to.equal('2024-11-06T14:00:30.000Z')
})
})

describe('with invalid feedback', function () {
let classifications
let rootStore
Expand Down

0 comments on commit f5d0e07

Please sign in to comment.