Better Form Stats (#567)

* Better Form Stats

* fix lint

* submission timer store in localstorage

* Update test case for stats

* remove extra code

* fix form stats

* on restart remove timer

* fix resetTimer function name

* Improve form timer

* Fix timer after form validation error + polish UI

---------

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
Chirag Chhatrala
2024-09-18 22:50:52 +05:30
committed by GitHub
parent a057045ef6
commit ceb0648262
14 changed files with 381 additions and 62 deletions

View File

@@ -39,7 +39,7 @@ it('check formstat chart data', function () {
}
// Now check chart data
$this->getJson(route('open.workspaces.form.stats', [$workspace->id, $form->id]))
$this->getJson(route('open.workspaces.form.stats', [$workspace->id, $form->id]) . '?date_from=' . now()->subDays(29)->format('Y-m-d') . '&date_to=' . now()->format('Y-m-d'))
->assertSuccessful()
->assertJson(function (\Illuminate\Testing\Fluent\AssertableJson $json) use ($views, $submissions) {
return $json->whereType('views', 'array')
@@ -65,3 +65,37 @@ it('check formstat chart data', function () {
->etc();
});
});
it('checks form stats details', function () {
$user = $this->actingAsProUser();
$workspace = $this->createUserWorkspace($user);
$form = $this->createForm($user, $workspace, []);
// Create form submissions with varying completion times
$form->submissions()->createMany([
['completion_time' => 60], // 1 minute
['completion_time' => 60], // 1 minute
['completion_time' => 60], // 1 minute
['completion_time' => 120], // 2 minutes
['completion_time' => 120], // 2 minutes
[] // Incomplete submission
]);
// Create form views
$form->views()->createMany(array_fill(0, 10, []));
$this->getJson(route('open.workspaces.form.stats-details', [$workspace->id, $form->id]))
->assertSuccessful()
->assertJson(function (\Illuminate\Testing\Fluent\AssertableJson $json) {
return $json->has('views')
->has('submissions')
->has('completion_rate')
->has('average_duration')
->where('views', 10)
->where('submissions', 6)
->where('completion_rate', 60)
->where('average_duration', '1 minute 24 seconds')
->etc();
});
});