@@ -305,6 +305,86 @@ def test_batch_reject_requires_comment(self):
305305 with self .assertRaises (UserError ):
306306 wizard .action_confirm ()
307307
308+ def test_create_from_selection_no_active_ids (self ):
309+ """Test create_from_selection raises error with no active_ids."""
310+ with self .assertRaises (UserError ):
311+ self .env ["spp.cr.batch.approval.wizard" ].create_from_selection ("approve" )
312+
313+ def test_create_from_selection_returns_action (self ):
314+ """Test create_from_selection returns a valid window action."""
315+ result = (
316+ self .env ["spp.cr.batch.approval.wizard" ]
317+ .with_context (active_ids = self .pending_crs .ids )
318+ .create_from_selection ("approve" )
319+ )
320+ self .assertEqual (result ["type" ], "ir.actions.act_window" )
321+ self .assertEqual (result ["res_model" ], "spp.cr.batch.approval.wizard" )
322+ self .assertEqual (result ["target" ], "new" )
323+ self .assertTrue (result ["res_id" ])
324+
325+ def test_create_from_selection_action_types (self ):
326+ """Test create_from_selection sets action_type correctly."""
327+ for action_type in ("approve" , "reject" , "revision" ):
328+ result = (
329+ self .env ["spp.cr.batch.approval.wizard" ]
330+ .with_context (active_ids = self .pending_crs .ids )
331+ .create_from_selection (action_type )
332+ )
333+ wizard = self .env ["spp.cr.batch.approval.wizard" ].browse (result ["res_id" ])
334+ self .assertEqual (wizard .action_type , action_type )
335+
336+ def test_error_message_not_pending (self ):
337+ """Test error message for CR not in pending state."""
338+ cr_type = self .env ["spp.change.request.type" ].search ([], limit = 1 )
339+ draft_cr = self .env ["spp.change.request" ].create (
340+ {
341+ "request_type_id" : cr_type .id ,
342+ "registrant_id" : self .group .id ,
343+ }
344+ )
345+ wizard = self ._create_wizard ([draft_cr .id ])
346+ line = wizard .line_ids [0 ]
347+ self .assertFalse (line .can_process )
348+ self .assertIn ("Not pending approval" , line .error_message )
349+
350+ def test_error_message_not_authorized (self ):
351+ """Test error message for CR user cannot approve."""
352+ # Mix pending + draft CRs to test both error paths
353+ cr_type = self .env ["spp.change.request.type" ].search ([], limit = 1 )
354+ draft_cr = self .env ["spp.change.request" ].create (
355+ {
356+ "request_type_id" : cr_type .id ,
357+ "registrant_id" : self .group .id ,
358+ }
359+ )
360+ wizard = self ._create_wizard (self .pending_crs .ids + [draft_cr .id ])
361+ # Should have both valid and invalid lines
362+ self .assertTrue (wizard .total_count > 0 )
363+ invalid_lines = wizard .line_ids .filtered (lambda ln : not ln .can_process )
364+ for line in invalid_lines :
365+ self .assertTrue (line .error_message )
366+
367+ def test_batch_revision_requires_comment (self ):
368+ """Test batch revision requires notes."""
369+ wizard = self ._create_wizard (self .pending_crs .ids , action_type = "revision" , comment = "" )
370+
371+ with self .assertRaises (UserError ):
372+ wizard .action_confirm ()
373+
374+ def test_batch_wizard_line_removal (self ):
375+ """Test that lines can be removed from a saved wizard."""
376+ wizard = self ._create_wizard (self .pending_crs .ids )
377+ initial_count = wizard .total_count
378+ self .assertEqual (initial_count , 3 )
379+
380+ # Remove one line
381+ line_to_remove = wizard .line_ids [0 ]
382+ line_to_remove .unlink ()
383+
384+ # Count should update
385+ wizard .invalidate_recordset ()
386+ self .assertEqual (len (wizard .line_ids ), 2 )
387+
308388
309389@tagged ("post_install" , "-at_install" , "cr_ux" )
310390class TestConflictComparisonWizard (TestChangeRequestBase ):
0 commit comments