@@ -1354,6 +1354,52 @@ def test_revert_history_after_component_move_uses_current_translate_url(
13541354 f'href="{ translate_url } ?checksum={ unit .checksum } &revert={ change .id } "' ,
13551355 )
13561356
1357+ def test_project_language_warns_when_switching_component (self ) -> None :
1358+ Component .objects .filter (pk = self .component .pk ).update (priority = 120 )
1359+ high_component = self .create_po (name = "High" , priority = 80 , project = self .project )
1360+ high_translation = high_component .translation_set .get (
1361+ language = self .translation .language
1362+ )
1363+ translate_url = ProjectLanguage (
1364+ self .project , self .translation .language
1365+ ).get_translate_url ()
1366+ high_component_offset = high_translation .unit_set .count ()
1367+
1368+ response = self .client .get (translate_url , {"offset" : high_component_offset })
1369+ self .assertNotContains (response , "You have shifted from" )
1370+
1371+ response = self .client .get (translate_url , {"offset" : high_component_offset + 1 })
1372+ self .assertContains (response , "You have shifted from" )
1373+
1374+ def test_project_language_ignores_stale_component_shift_unit (self ) -> None :
1375+ Component .objects .filter (pk = self .component .pk ).update (priority = 120 )
1376+ high_component = self .create_po (name = "High" , priority = 80 , project = self .project )
1377+ high_translation = high_component .translation_set .get (
1378+ language = self .translation .language
1379+ )
1380+ translate_url = ProjectLanguage (
1381+ self .project , self .translation .language
1382+ ).get_translate_url ()
1383+ high_component_offset = high_translation .unit_set .count ()
1384+
1385+ response = self .client .get (translate_url , {"offset" : high_component_offset })
1386+ self .assertEqual (response .status_code , 200 )
1387+
1388+ stale_unit_id = Unit .objects .order_by ("-pk" ).values_list ("pk" , flat = True )[0 ] + 1
1389+ session = self .client .session
1390+ search_key = next (key for key in session if key .startswith ("search_" ))
1391+ session_result = session [search_key ]
1392+ session_result ["last_viewed_unit_id" ] = stale_unit_id
1393+ session [search_key ] = session_result
1394+ session .save ()
1395+
1396+ response = self .client .get (translate_url , {"offset" : high_component_offset + 1 })
1397+ self .assertEqual (response .status_code , 200 )
1398+ self .assertNotContains (response , "You have shifted from" )
1399+ self .assertNotEqual (
1400+ self .client .session [search_key ]["last_viewed_unit_id" ], stale_unit_id
1401+ )
1402+
13571403 def test_revert_plural (self ) -> None :
13581404 source = "Orangutan has %d banana.\n "
13591405 target = [
0 commit comments