vibe
This commit is contained in:
parent
16533b1495
commit
ab0677c463
14 changed files with 705 additions and 38 deletions
|
@ -33,20 +33,20 @@ test('Bulk Edit Form displays correctly with drink types', function (): void {
|
|||
$this->assertResponseIsSuccessful();
|
||||
|
||||
// Check page title
|
||||
$this->assertSelectorTextContains('h1', 'Bulk Edit Drink Type Wanted Stock');
|
||||
$this->assertSelectorTextContains('h1', 'Bulk Edit Drink Type Current Stock');
|
||||
|
||||
// Check that drink types are displayed in the table (they're in the value attribute of disabled inputs)
|
||||
$this->assertSelectorExists('input[value="Cola"]');
|
||||
$this->assertSelectorExists('input[value="Beer"]');
|
||||
|
||||
// Check that the form has the correct submit button
|
||||
$this->assertSelectorTextContains('button[type="submit"]', 'Update Wanted Stock Levels');
|
||||
$this->assertSelectorTextContains('button[type="submit"]', 'Update Current Stock Levels');
|
||||
|
||||
// Check that input fields exist for each drink type
|
||||
$this->assertCount(2, $crawler->filter('input[name*="[wantedStock]"]'));
|
||||
$this->assertCount(2, $crawler->filter('input[name*="[currentStock]"]'));
|
||||
});
|
||||
|
||||
test('Bulk Edit Form submission updates drink type wanted stock levels', function (): void {
|
||||
test('Bulk Edit Form submission updates drink type current stock levels', function (): void {
|
||||
$this->ensureKernelShutdown();
|
||||
$client = static::createClient();
|
||||
|
||||
|
@ -71,12 +71,12 @@ test('Bulk Edit Form submission updates drink type wanted stock levels', functio
|
|||
$crawler = $client->request('GET', '/drink-types/bulk-edit-stock');
|
||||
|
||||
// Submit the form with updated values
|
||||
$form = $crawler->selectButton('Update Wanted Stock Levels')->form();
|
||||
$form = $crawler->selectButton('Update Current Stock Levels')->form();
|
||||
|
||||
// Update the wanted stock values - note: drink types are ordered by wantedStock DESC
|
||||
// Update the current stock values - note: drink types are ordered by wantedStock DESC
|
||||
// So Beer (wantedStock 20) comes first [0], Cola (wantedStock 10) comes second [1]
|
||||
$form['bulk_edit_drink_type_stock_form[drinkTypes][0][wantedStock]'] = 25; // Beer
|
||||
$form['bulk_edit_drink_type_stock_form[drinkTypes][1][wantedStock]'] = 15; // Cola
|
||||
$form['bulk_edit_drink_type_stock_form[drinkTypes][0][currentStock]'] = 25; // Beer
|
||||
$form['bulk_edit_drink_type_stock_form[drinkTypes][1][currentStock]'] = 15; // Cola
|
||||
|
||||
$client->submit($form);
|
||||
|
||||
|
@ -87,7 +87,7 @@ test('Bulk Edit Form submission updates drink type wanted stock levels', functio
|
|||
$client->followRedirect();
|
||||
|
||||
// Check for success message
|
||||
$this->assertSelectorTextContains('.alert-success', 'Wanted stock levels updated successfully!');
|
||||
$this->assertSelectorTextContains('.alert-success', 'Current stock levels updated successfully!');
|
||||
|
||||
// Verify the database was updated
|
||||
$em->clear(); // Clear entity manager to reload from database
|
||||
|
@ -95,8 +95,8 @@ test('Bulk Edit Form submission updates drink type wanted stock levels', functio
|
|||
$updatedDrinkType1 = $em->find(DrinkType::class, $drinkType1->getId());
|
||||
$updatedDrinkType2 = $em->find(DrinkType::class, $drinkType2->getId());
|
||||
|
||||
expect($updatedDrinkType1->getWantedStock())->toBe(15); // Cola
|
||||
expect($updatedDrinkType2->getWantedStock())->toBe(25); // Beer
|
||||
expect($updatedDrinkType1->getCurrentStock())->toBe(15); // Cola
|
||||
expect($updatedDrinkType2->getCurrentStock())->toBe(25); // Beer
|
||||
});
|
||||
|
||||
test('Bulk Edit Form handles empty drink types list', function (): void {
|
||||
|
@ -119,14 +119,14 @@ test('Bulk Edit Form handles empty drink types list', function (): void {
|
|||
$this->assertResponseIsSuccessful();
|
||||
|
||||
// Check page title
|
||||
$this->assertSelectorTextContains('h1', 'Bulk Edit Drink Type Wanted Stock');
|
||||
$this->assertSelectorTextContains('h1', 'Bulk Edit Drink Type Current Stock');
|
||||
|
||||
// Check that the table exists but has no rows (no tbody content)
|
||||
$this->assertSelectorExists('table');
|
||||
$this->assertCount(0, $crawler->filter('table tbody tr'));
|
||||
|
||||
// Check that the form still has the submit button
|
||||
$this->assertSelectorTextContains('button[type="submit"]', 'Update Wanted Stock Levels');
|
||||
$this->assertSelectorTextContains('button[type="submit"]', 'Update Current Stock Levels');
|
||||
});
|
||||
|
||||
test('Bulk Edit Form rejects negative values (validation)', function (): void {
|
||||
|
@ -148,20 +148,20 @@ test('Bulk Edit Form rejects negative values (validation)', function (): void {
|
|||
$crawler = $client->request('GET', '/drink-types/bulk-edit-stock');
|
||||
|
||||
// Submit the form with negative value
|
||||
$form = $crawler->selectButton('Update Wanted Stock Levels')->form();
|
||||
$form['bulk_edit_drink_type_stock_form[drinkTypes][0][wantedStock]'] = -5;
|
||||
$form = $crawler->selectButton('Update Current Stock Levels')->form();
|
||||
$form['bulk_edit_drink_type_stock_form[drinkTypes][0][currentStock]'] = -5;
|
||||
|
||||
$client->submit($form);
|
||||
|
||||
// The form should NOT redirect, but show the validation error
|
||||
$this->assertResponseIsSuccessful();
|
||||
$this->assertSelectorTextContains('h1', 'Bulk Edit Drink Type Wanted Stock');
|
||||
$this->assertSelectorTextContains('.form-error-message, .invalid-feedback', 'Wanted stock must not be negative');
|
||||
$this->assertSelectorTextContains('h1', 'Bulk Edit Drink Type Current Stock');
|
||||
$this->assertSelectorTextContains('.form-error-message, .invalid-feedback', 'Current stock must not be negative');
|
||||
|
||||
// Verify the database was not updated
|
||||
$em->clear();
|
||||
$updatedDrinkType = $em->find(DrinkType::class, $drinkType->getId());
|
||||
expect($updatedDrinkType->getWantedStock())->toBe(10); // Should remain unchanged
|
||||
expect($updatedDrinkType->getCurrentStock())->toBe(5); // Should remain unchanged
|
||||
});
|
||||
|
||||
test('Bulk Edit Form preserves drink type names as read-only', function (): void {
|
||||
|
@ -188,8 +188,8 @@ test('Bulk Edit Form preserves drink type names as read-only', function (): void
|
|||
expect($nameInput->attr('disabled'))->toBe('disabled');
|
||||
|
||||
// Submit the form
|
||||
$form = $crawler->selectButton('Update Wanted Stock Levels')->form();
|
||||
$form['bulk_edit_drink_type_stock_form[drinkTypes][0][wantedStock]'] = 15;
|
||||
$form = $crawler->selectButton('Update Current Stock Levels')->form();
|
||||
$form['bulk_edit_drink_type_stock_form[drinkTypes][0][currentStock]'] = 15;
|
||||
|
||||
$client->submit($form);
|
||||
|
||||
|
@ -200,5 +200,5 @@ test('Bulk Edit Form preserves drink type names as read-only', function (): void
|
|||
$em->clear();
|
||||
$updatedDrinkType = $em->find(DrinkType::class, $drinkType->getId());
|
||||
expect($updatedDrinkType->getName())->toBe('Original Name');
|
||||
expect($updatedDrinkType->getWantedStock())->toBe(15);
|
||||
expect($updatedDrinkType->getCurrentStock())->toBe(15);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue