Skip to content

Commit

Permalink
Replace test with lower level
Browse files Browse the repository at this point in the history
  • Loading branch information
seadowg committed Apr 7, 2023
1 parent 99b3961 commit c037f7d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,4 @@ class AuditTest {
assertThat(auditLog[11].get("event"), equalTo("form exit"))
assertThat(auditLog[12].get("event"), equalTo("form finalize"))
}

@Test
fun fillingFormWithTrackChanges_withConstraint_andViolatingConstraint_andCorrectingAnswer_tracksCorrectedAnswer() {
rule.startAtMainMenu()
.copyForm("one-question-audit-constraint.xml")
.startBlankForm("One Question Audit Constraint")
.answerQuestion("What is your age?", "120")
.swipeToNextQuestionWithConstraintViolation("Too old!")
.answerQuestion("What is your age?", "119")
.swipeToEndScreen()
.clickSaveAndExit()

val auditLog = StorageUtils.getAuditLogForFirstInstance()
assertThat(auditLog.size, equalTo(6))

assertThat(auditLog[0].get("event"), equalTo("form start"))

val questionEvent = auditLog[1]
assertThat(questionEvent.get("event"), equalTo("question"))
assertThat(questionEvent.get("old-value"), equalTo(""))
assertThat(questionEvent.get("new-value"), equalTo("119"))

assertThat(auditLog[2].get("event"), equalTo("end screen"))
assertThat(auditLog[3].get("event"), equalTo("form save"))
assertThat(auditLog[4].get("event"), equalTo("form exit"))
assertThat(auditLog[5].get("event"), equalTo("form finalize"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,20 @@ public void moveForward_whenThereIsAFailedConstraint_setsFailedConstraint() thro
assertThat(getOrAwaitValue(viewModel.getFailedConstraint()), equalTo(failedConstraint));
}

/**
* We don't want to flush the log before answers are actually committed.
*/
@Test
public void moveForward_whenThereIsAFailedConstraint_doesNotFlushAuditLog() throws Exception {
FailedConstraint failedConstraint = new FailedConstraint(startingIndex, 0);
when(formController.saveAllScreenAnswers(any(), anyBoolean())).thenReturn(failedConstraint);

viewModel.moveForward(new HashMap<>());
scheduler.runBackground();

verify(auditEventLogger, never()).flush();
}

@Test
public void moveForward_whenThereIsAFailedConstraint_doesNotStepToNextEvent() throws Exception {
FailedConstraint failedConstraint = new FailedConstraint(startingIndex, 0);
Expand Down

0 comments on commit c037f7d

Please sign in to comment.