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:
54
tests/Form/FormTraitTest.php
Normal file
54
tests/Form/FormTraitTest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Form;
|
||||
|
||||
use App\Form\FormTrait;
|
||||
use App\Tests\Form\Type\TypeTestModel;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Symfony\Component\Form\Test\TypeTestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Form\FormTrait
|
||||
*/
|
||||
class FormTraitTest extends TypeTestCase
|
||||
{
|
||||
use FormTrait;
|
||||
|
||||
/**
|
||||
* @expectedDeprecation FormTrait::addDescription() is deprecated and will be removed with 2.0, use DescriptionType instead
|
||||
* @group legacy
|
||||
*/
|
||||
public function testAddDescription()
|
||||
{
|
||||
$data = ['description' => 'foo'];
|
||||
$model = new TypeTestModel(['description' => 'bar']);
|
||||
|
||||
$form = $this->factory->createBuilder(FormType::class, $model);
|
||||
$this->addDescription($form);
|
||||
|
||||
$desc = $form->get('description');
|
||||
self::assertArrayHasKey('autofocus', $desc->getOption('attr'));
|
||||
self::assertEquals('autofocus', $desc->getOption('attr')['autofocus']);
|
||||
|
||||
$form = $form->getForm();
|
||||
|
||||
$desc = $form->get('description');
|
||||
self::assertFalse($desc->isRequired());
|
||||
|
||||
$expected = new TypeTestModel([
|
||||
'description' => 'foo'
|
||||
]);
|
||||
|
||||
$form->submit($data);
|
||||
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
$this->assertEquals($expected, $model);
|
||||
}
|
||||
}
|
||||
101
tests/Form/Type/DurationTypeTest.php
Normal file
101
tests/Form/Type/DurationTypeTest.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Form\Type;
|
||||
|
||||
use App\Form\Type\DurationType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Symfony\Component\Form\Test\TypeTestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Form\Type\DurationType
|
||||
*/
|
||||
class DurationTypeTest extends TypeTestCase
|
||||
{
|
||||
public function getTestData()
|
||||
{
|
||||
yield [4.5, 16200];
|
||||
yield ['4,5', 16200];
|
||||
yield ['4:30', 16200];
|
||||
yield ['4h30m', 16200];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTestData
|
||||
*/
|
||||
public function testSubmitValidData($value, $expected)
|
||||
{
|
||||
$data = ['duration' => $value];
|
||||
$model = new TypeTestModel(['duration' => 3600]);
|
||||
|
||||
$form = $this->factory->createBuilder(FormType::class, $model);
|
||||
$form->add('duration', DurationType::class);
|
||||
$form = $form->getForm();
|
||||
|
||||
$expected = new TypeTestModel([
|
||||
'duration' => $expected
|
||||
]);
|
||||
|
||||
$form->submit($data);
|
||||
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
$this->assertEquals($expected, $model);
|
||||
}
|
||||
|
||||
public function testPresetPopulatesView()
|
||||
{
|
||||
$view = $this->factory->create(DurationType::class, 3600, [
|
||||
'preset_minutes' => 15,
|
||||
'preset_hours' => 5,
|
||||
])->createView();
|
||||
|
||||
self::assertArrayHasKey('duration_presets', $view->vars);
|
||||
self::assertCount(20, $view->vars['duration_presets']);
|
||||
self::assertEquals('0:30', $view->vars['duration_presets'][1]);
|
||||
self::assertEquals('4:45', $view->vars['duration_presets'][18]);
|
||||
}
|
||||
|
||||
public function testPresetsAreNotGeneratedOnMissingHours()
|
||||
{
|
||||
$view = $this->factory->create(DurationType::class, 3600, [
|
||||
'preset_minutes' => 5,
|
||||
])->createView();
|
||||
|
||||
self::assertArrayNotHasKey('duration_presets', $view->vars);
|
||||
}
|
||||
|
||||
public function testPresetsAreNotGeneratedOnMissingMinutes()
|
||||
{
|
||||
$view = $this->factory->create(DurationType::class, 3600, [
|
||||
'preset_hours' => 5,
|
||||
])->createView();
|
||||
|
||||
self::assertArrayNotHasKey('duration_presets', $view->vars);
|
||||
}
|
||||
|
||||
public function testPresetsAreNotGeneratedOnNegativeMinutes()
|
||||
{
|
||||
$view = $this->factory->create(DurationType::class, 3600, [
|
||||
'preset_minutes' => -1,
|
||||
'preset_hours' => 5,
|
||||
])->createView();
|
||||
|
||||
self::assertArrayNotHasKey('duration_presets', $view->vars);
|
||||
}
|
||||
|
||||
public function testPresetsAreNotGeneratedOnNegativeHours()
|
||||
{
|
||||
$view = $this->factory->create(DurationType::class, 3600, [
|
||||
'preset_minutes' => 5,
|
||||
'preset_hours' => -1,
|
||||
])->createView();
|
||||
|
||||
self::assertArrayNotHasKey('duration_presets', $view->vars);
|
||||
}
|
||||
}
|
||||
78
tests/Form/Type/MinuteIncrementTypeTest.php
Normal file
78
tests/Form/Type/MinuteIncrementTypeTest.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Form\Type;
|
||||
|
||||
use App\Form\Type\MinuteIncrementType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Symfony\Component\Form\Test\TypeTestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Form\Type\MinuteIncrementType
|
||||
*/
|
||||
class MinuteIncrementTypeTest extends TypeTestCase
|
||||
{
|
||||
public function testSubmitValidData()
|
||||
{
|
||||
$data = ['increment' => 4];
|
||||
$model = new TypeTestModel(['increment' => 5]);
|
||||
|
||||
$form = $this->factory->createBuilder(FormType::class, $model);
|
||||
$form->add('increment', MinuteIncrementType::class);
|
||||
$form = $form->getForm();
|
||||
|
||||
$expected = new TypeTestModel([
|
||||
'increment' => '3'
|
||||
]);
|
||||
|
||||
$form->submit($data);
|
||||
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
$this->assertEquals($expected, $model);
|
||||
}
|
||||
|
||||
public function testSubmitValidDataWithoutDeactivate()
|
||||
{
|
||||
$data = ['increment' => 4];
|
||||
$model = new TypeTestModel(['increment' => 5]);
|
||||
|
||||
$form = $this->factory->createBuilder(FormType::class, $model);
|
||||
$form->add('increment', MinuteIncrementType::class, ['deactivate' => false]);
|
||||
$form = $form->getForm();
|
||||
|
||||
$expected = new TypeTestModel([
|
||||
'increment' => '4'
|
||||
]);
|
||||
|
||||
$form->submit($data);
|
||||
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
$this->assertEquals($expected, $model);
|
||||
}
|
||||
|
||||
public function testPresetPopulatesView()
|
||||
{
|
||||
$view = $this->factory->create(MinuteIncrementType::class, 3600, [])->createView();
|
||||
self::assertArrayHasKey('choices', $view->vars);
|
||||
self::assertCount(16, $view->vars['choices']);
|
||||
self::assertEquals(null, $view->vars['choices'][0]->data);
|
||||
self::assertEquals(0, $view->vars['choices'][1]->data);
|
||||
self::assertEquals(1, $view->vars['choices'][2]->data);
|
||||
}
|
||||
|
||||
public function testPresetPopulatesViewWithoutDeactivate()
|
||||
{
|
||||
$view = $this->factory->create(MinuteIncrementType::class, 3600, ['deactivate' => false])->createView();
|
||||
self::assertArrayHasKey('choices', $view->vars);
|
||||
self::assertCount(15, $view->vars['choices']);
|
||||
self::assertEquals(null, $view->vars['choices'][0]->data);
|
||||
self::assertEquals(1, $view->vars['choices'][1]->data);
|
||||
self::assertEquals(2, $view->vars['choices'][2]->data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user