improved duration and minute selector (#2264)

* do not close modal if form is dirty
* deprecated TimesheetConfiguration
* inject timezone in form types
* cleanup usage of UserDateTimeFactory
* allow to configure increment steps for minutes
* use 15 minutes step for datetimepicker in project edit form
* use rounding rules for increments in minute select for begin and end
* allow duration in multi user and admin timesheet forms
* make dropdown values configurable
This commit is contained in:
Kevin Papst
2021-01-17 14:04:13 +01:00
committed by GitHub
parent e2324b7d51
commit 8d72d114c7
95 changed files with 1381 additions and 510 deletions

View File

@@ -10,6 +10,7 @@
namespace App\Tests\Timesheet\TrackingMode;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Timesheet\TrackingMode\AbstractTrackingMode;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
@@ -24,6 +25,14 @@ abstract class AbstractTrackingModeTest extends TestCase
*/
abstract protected function createSut();
protected function createTimesheet(): Timesheet
{
$timesheet = new Timesheet();
$timesheet->setUser(new User());
return $timesheet;
}
protected function assertDefaultBegin(Timesheet $timesheet)
{
self::assertNull($timesheet->getBegin());
@@ -33,7 +42,7 @@ abstract class AbstractTrackingModeTest extends TestCase
{
$sut = $this->createSut();
$timesheet = new Timesheet();
$timesheet = $this->createTimesheet();
self::assertNull($timesheet->getBegin());
self::assertNull($timesheet->getEnd());
@@ -48,7 +57,7 @@ abstract class AbstractTrackingModeTest extends TestCase
{
$sut = $this->createSut();
$timesheet = new Timesheet();
$timesheet = $this->createTimesheet();
$request = new Request([
'begin' => '2017-07-23',
]);
@@ -65,7 +74,7 @@ abstract class AbstractTrackingModeTest extends TestCase
{
$sut = $this->createSut();
$timesheet = new Timesheet();
$timesheet = $this->createTimesheet();
$request = new Request([
'begin' => '2017-07-23',
'end' => '2017-07-23',
@@ -85,7 +94,7 @@ abstract class AbstractTrackingModeTest extends TestCase
{
$sut = $this->createSut();
$timesheet = new Timesheet();
$timesheet = $this->createTimesheet();
$request = new Request([
'begin' => '10x0-99-99',
'end' => '2017-07-23',
@@ -102,7 +111,7 @@ abstract class AbstractTrackingModeTest extends TestCase
{
$sut = $this->createSut();
$timesheet = new Timesheet();
$timesheet = $this->createTimesheet();
$request = new Request([
'begin' => '2017-07-23',
'end' => '20xx-07-23',
@@ -120,7 +129,7 @@ abstract class AbstractTrackingModeTest extends TestCase
{
$sut = $this->createSut();
$timesheet = new Timesheet();
$timesheet = $this->createTimesheet();
$request = new Request([
'from' => '2018-05-23 21:47:55',
]);
@@ -136,7 +145,7 @@ abstract class AbstractTrackingModeTest extends TestCase
{
$sut = $this->createSut();
$timesheet = new Timesheet();
$timesheet = $this->createTimesheet();
$request = new Request([
'from' => '2018-05-23 21:47:55',
'to' => '2018-05-24 01:11:11',
@@ -156,7 +165,7 @@ abstract class AbstractTrackingModeTest extends TestCase
{
$sut = $this->createSut();
$timesheet = new Timesheet();
$timesheet = $this->createTimesheet();
$request = new Request([
'begin' => '2017-07-23',
'end' => '2017-07-23',
@@ -178,7 +187,7 @@ abstract class AbstractTrackingModeTest extends TestCase
{
$sut = $this->createSut();
$timesheet = new Timesheet();
$timesheet = $this->createTimesheet();
$request = new Request([
'from' => '2018-xx-23 21:47:55',
'to' => '2018-05-24 01:11:11',
@@ -195,7 +204,7 @@ abstract class AbstractTrackingModeTest extends TestCase
{
$sut = $this->createSut();
$timesheet = new Timesheet();
$timesheet = $this->createTimesheet();
$request = new Request([
'from' => '2018-05-23 21:47:55',
'to' => '2018-xx-24 01:11:11',

View File

@@ -9,11 +9,8 @@
namespace App\Tests\Timesheet\TrackingMode;
use App\Configuration\TimesheetConfiguration;
use App\Entity\Timesheet;
use App\Tests\Configuration\TestConfigLoader;
use App\Tests\Mocks\RoundingServiceFactory;
use App\Tests\Mocks\Security\UserDateTimeFactoryFactory;
use App\Timesheet\TrackingMode\DefaultMode;
/**
@@ -32,11 +29,7 @@ class DefaultModeTest extends AbstractTrackingModeTest
*/
protected function createSut()
{
$loader = new TestConfigLoader([]);
$dateTime = (new UserDateTimeFactoryFactory($this))->create();
$configuration = new TimesheetConfiguration($loader, ['default_begin' => '13:47']);
return new DefaultMode($dateTime, $configuration, (new RoundingServiceFactory($this))->create());
return new DefaultMode((new RoundingServiceFactory($this))->create());
}
public function testDefaultValues()
@@ -45,7 +38,7 @@ class DefaultModeTest extends AbstractTrackingModeTest
self::assertTrue($sut->canEditBegin());
self::assertTrue($sut->canEditEnd());
self::assertFalse($sut->canEditDuration());
self::assertTrue($sut->canEditDuration());
self::assertTrue($sut->canUpdateTimesWithAPI());
self::assertTrue($sut->canSeeBeginAndEndTimes());
self::assertEquals('default', $sut->getId());

View File

@@ -9,10 +9,10 @@
namespace App\Tests\Timesheet\TrackingMode;
use App\Configuration\TimesheetConfiguration;
use App\Configuration\SystemConfiguration;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Tests\Configuration\TestConfigLoader;
use App\Tests\Mocks\Security\UserDateTimeFactoryFactory;
use App\Timesheet\TrackingMode\DurationFixedBeginMode;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
@@ -25,10 +25,9 @@ class DurationFixedBeginModeTest extends TestCase
protected function createSut()
{
$loader = new TestConfigLoader([]);
$dateTime = (new UserDateTimeFactoryFactory($this))->create();
$configuration = new TimesheetConfiguration($loader, ['default_begin' => '13:47']);
$configuration = new SystemConfiguration($loader, ['timesheet' => ['default_begin' => '13:47']]);
return new DurationFixedBeginMode($dateTime, $configuration);
return new DurationFixedBeginMode($configuration);
}
public function testDefaultValues()
@@ -57,7 +56,7 @@ class DurationFixedBeginModeTest extends TestCase
public function testCreateWithoutBeginInjectsBegin()
{
$timesheet = new Timesheet();
$timesheet = (new Timesheet())->setUser(new User());
$request = new Request();
$sut = $this->createSut();

View File

@@ -9,10 +9,9 @@
namespace App\Tests\Timesheet\TrackingMode;
use App\Configuration\TimesheetConfiguration;
use App\Configuration\SystemConfiguration;
use App\Entity\Timesheet;
use App\Tests\Configuration\TestConfigLoader;
use App\Tests\Mocks\Security\UserDateTimeFactoryFactory;
use App\Timesheet\TrackingMode\DurationOnlyMode;
/**
@@ -29,10 +28,9 @@ class DurationOnlyModeTest extends AbstractTrackingModeTest
protected function createSut()
{
$loader = new TestConfigLoader([]);
$dateTime = (new UserDateTimeFactoryFactory($this))->create();
$configuration = new TimesheetConfiguration($loader, ['default_begin' => '13:45:37']);
$configuration = new SystemConfiguration($loader, ['timesheet' => ['default_begin' => '13:45:37']]);
return new DurationOnlyMode($dateTime, $configuration);
return new DurationOnlyMode($configuration);
}
public function testDefaultValues()

View File

@@ -10,7 +10,7 @@
namespace App\Tests\Timesheet\TrackingMode;
use App\Entity\Timesheet;
use App\Tests\Mocks\Security\UserDateTimeFactoryFactory;
use App\Entity\User;
use App\Timesheet\TrackingMode\PunchInOutMode;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
@@ -22,8 +22,7 @@ class PunchInOutModeTest extends TestCase
{
public function testDefaultValues()
{
$dateTime = (new UserDateTimeFactoryFactory($this))->create();
$sut = new PunchInOutMode($dateTime);
$sut = new PunchInOutMode();
self::assertFalse($sut->canEditBegin());
self::assertFalse($sut->canEditEnd());
@@ -40,19 +39,17 @@ class PunchInOutModeTest extends TestCase
$timesheet->setBegin($startingTime);
$request = new Request();
$dateTime = (new UserDateTimeFactoryFactory($this))->create();
$sut = new PunchInOutMode($dateTime);
$sut = new PunchInOutMode();
$sut->create($timesheet, $request);
self::assertEquals($timesheet->getBegin(), $startingTime);
}
public function testCreateWithoutBegin()
{
$timesheet = new Timesheet();
$timesheet = (new Timesheet())->setUser(new User());
$request = new Request();
$dateTime = (new UserDateTimeFactoryFactory($this))->create();
$sut = new PunchInOutMode($dateTime);
$sut = new PunchInOutMode();
$sut->create($timesheet, $request);
self::assertInstanceOf(\DateTime::class, $timesheet->getBegin());
}