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:
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace App\Tests\Timesheet;
|
||||
|
||||
use App\Configuration\TimesheetConfiguration;
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Event\TimesheetCreatePostEvent;
|
||||
@@ -42,8 +42,8 @@ class TimesheetServiceTest extends TestCase
|
||||
?ValidatorInterface $validator = null,
|
||||
?TimesheetRepository $repository = null
|
||||
): TimesheetService {
|
||||
$configuration = $this->createMock(TimesheetConfiguration::class);
|
||||
$configuration->method('getActiveEntriesHardLimit')->willReturn(1);
|
||||
$configuration = $this->createMock(SystemConfiguration::class);
|
||||
$configuration->method('getTimesheetActiveEntriesHardLimit')->willReturn(1);
|
||||
|
||||
if ($repository === null) {
|
||||
$repository = $this->createMock(TimesheetRepository::class);
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -9,13 +9,15 @@
|
||||
|
||||
namespace App\Tests\Timesheet;
|
||||
|
||||
use App\Tests\Mocks\Security\UserDateTimeFactoryFactory;
|
||||
use App\Entity\User;
|
||||
use App\Tests\Mocks\Security\CurrentUserFactory;
|
||||
use App\Timesheet\UserDateTimeFactory;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Timesheet\DateTimeFactory
|
||||
* @covers \App\Timesheet\UserDateTimeFactory
|
||||
* @group legacy
|
||||
*/
|
||||
class UserDateTimeFactoryTest extends TestCase
|
||||
{
|
||||
@@ -23,7 +25,10 @@ class UserDateTimeFactoryTest extends TestCase
|
||||
|
||||
protected function createUserDateTimeFactory(?string $timezone = null): UserDateTimeFactory
|
||||
{
|
||||
return (new UserDateTimeFactoryFactory($this))->create($timezone);
|
||||
$userFactory = new CurrentUserFactory($this);
|
||||
$currentUser = $userFactory->create(new User(), $timezone);
|
||||
|
||||
return new UserDateTimeFactory($currentUser);
|
||||
}
|
||||
|
||||
public function testGetTimezone()
|
||||
|
||||
Reference in New Issue
Block a user