@@ -1177,6 +1177,121 @@ def test_response_contains_nav_dashboard_reload_event(
11771177 assert 'nav.dashboard.reload' in response .headers ['HX-Trigger' ]
11781178
11791179
1180+ class TestLoadDashboardView :
1181+ def test_given_existing_dashboard_it_should_return_navlets_template (
1182+ self , db , client , admin_account
1183+ ):
1184+ """Tests that loading an existing dashboard returns the navlets template"""
1185+ dashboard = create_dashboard (admin_account , name = "Load Test Dashboard" )
1186+ create_widget (dashboard )
1187+
1188+ url = reverse ('dashboard-load' , args = (dashboard .id ,))
1189+ response = client .get (url )
1190+
1191+ assert response .status_code == 200
1192+ assert 'class="row' in smart_str (response .content )
1193+
1194+ def test_given_nonexistent_dashboard_it_should_return_404 (
1195+ self , db , client , admin_account
1196+ ):
1197+ """Tests that loading a non-existent dashboard returns 404"""
1198+ url = reverse ('dashboard-load' , args = (9999 ,))
1199+ response = client .get (url )
1200+
1201+ assert response .status_code == 404
1202+
1203+ def test_given_other_users_private_dashboard_it_should_return_404 (
1204+ self , db , client , non_admin_account
1205+ ):
1206+ """Tests that loading another user's private dashboard returns 404"""
1207+ dashboard = create_dashboard (non_admin_account , is_shared = False )
1208+
1209+ url = reverse ('dashboard-load' , args = (dashboard .id ,))
1210+ response = client .get (url )
1211+
1212+ assert response .status_code == 404
1213+
1214+ def test_given_other_users_shared_dashboard_it_should_return_navlets (
1215+ self , db , client , admin_account , non_admin_account
1216+ ):
1217+ """Tests that loading another user's shared dashboard works"""
1218+ dashboard = create_dashboard (non_admin_account , is_shared = True )
1219+ create_widget (dashboard )
1220+
1221+ url = reverse ('dashboard-load' , args = (dashboard .id ,))
1222+ response = client .get (url )
1223+
1224+ assert response .status_code == 200
1225+ assert 'class="row' in smart_str (response .content )
1226+
1227+ def test_given_dashboard_with_compact_preference_it_should_add_collapse_class (
1228+ self , db , client , admin_account
1229+ ):
1230+ """Tests that compact preference adds collapse class to row"""
1231+ admin_account .preferences ['widget_display_density' ] = 'compact'
1232+ admin_account .save ()
1233+
1234+ dashboard = create_dashboard (admin_account )
1235+ url = reverse ('dashboard-load' , args = (dashboard .id ,))
1236+ response = client .get (url )
1237+
1238+ assert response .status_code == 200
1239+ assert 'class="row collapse"' in smart_str (response .content )
1240+
1241+ def test_given_dashboard_with_no_widgets_it_should_show_empty_state (
1242+ self , db , client , admin_account
1243+ ):
1244+ """Tests that dashboard with no widgets shows proper empty state"""
1245+ dashboard = create_dashboard (admin_account )
1246+ url = reverse ('dashboard-load' , args = (dashboard .id ,))
1247+ response = client .get (url )
1248+
1249+ assert response .status_code == 200
1250+ assert response .context ['has_navlets' ] is False
1251+ assert "no-widgets-message" in smart_str (response .content )
1252+
1253+ def test_dashboard_load_contains_correct_number_of_columns (
1254+ self , db , client , admin_account
1255+ ):
1256+ """Tests that the loaded dashboard contains the correct number of columns"""
1257+ num_columns = 4
1258+ dashboard = create_dashboard (admin_account )
1259+ dashboard .num_columns = num_columns
1260+ dashboard .save ()
1261+
1262+ url = reverse ('dashboard-load' , args = (dashboard .id ,))
1263+ response = client .get (url )
1264+
1265+ assert response .status_code == 200
1266+ content = smart_str (response .content )
1267+ for col_index in range (1 , num_columns + 1 ):
1268+ assert f'data-col="{ col_index } "' in content
1269+
1270+ def test_given_navlets_in_different_columns_it_should_distribute_them_correctly (
1271+ self , db , client , admin_account
1272+ ):
1273+ """Tests that navlets are distributed correctly across columns when loading"""
1274+ dashboard = create_dashboard (admin_account )
1275+ widget1 = create_widget (dashboard , column = 1 , order = 0 )
1276+ widget2 = create_widget (dashboard , column = 2 , order = 0 )
1277+ widget3 = create_widget (dashboard , column = 1 , order = 1 )
1278+
1279+ url = reverse ('dashboard-load' , args = (dashboard .id ,))
1280+ response = client .get (url )
1281+ assert response .status_code == 200
1282+
1283+ columns = response .context ['columns' ]
1284+ assert isinstance (columns , dict )
1285+ assert set (columns .keys ()) >= {1 , 2 }
1286+
1287+ # Check widgets are in the correct columns and orders
1288+ column1_ids = [w ['id' ] for w in columns [1 ]]
1289+ column2_ids = [w ['id' ] for w in columns [2 ]]
1290+
1291+ assert column1_ids == [widget1 .id , widget3 .id ]
1292+ assert column2_ids == [widget2 .id ]
1293+
1294+
11801295def create_dashboard (account , name = "Test Dashboard" , is_default = False , is_shared = False ):
11811296 return AccountDashboard .objects .create (
11821297 name = name ,
@@ -1186,11 +1301,15 @@ def create_dashboard(account, name="Test Dashboard", is_default=False, is_shared
11861301 )
11871302
11881303
1189- def create_widget (dashboard , navlet = 'nav.web.navlets.welcome.WelcomeNavlet' ):
1304+ def create_widget (
1305+ dashboard , navlet = 'nav.web.navlets.welcome.WelcomeNavlet' , column = 1 , order = 0
1306+ ):
11901307 return AccountNavlet .objects .create (
11911308 dashboard = dashboard ,
11921309 account = dashboard .account ,
11931310 navlet = navlet ,
1311+ column = column ,
1312+ order = order ,
11941313 )
11951314
11961315
0 commit comments