@@ -1108,6 +1108,121 @@ def test_given_empty_result_then_return_no_dashboards_message(
11081108 assert 'No dashboards found' in smart_str (response .content )
11091109
11101110
1111+ class TestLoadDashboardView :
1112+ def test_given_existing_dashboard_it_should_return_navlets_template (
1113+ self , db , client , admin_account
1114+ ):
1115+ """Tests that loading an existing dashboard returns the navlets template"""
1116+ dashboard = create_dashboard (admin_account , name = "Load Test Dashboard" )
1117+ create_widget (dashboard )
1118+
1119+ url = reverse ('dashboard-load' , args = (dashboard .id ,))
1120+ response = client .get (url )
1121+
1122+ assert response .status_code == 200
1123+ assert 'class="row' in smart_str (response .content )
1124+
1125+ def test_given_nonexistent_dashboard_it_should_return_404 (
1126+ self , db , client , admin_account
1127+ ):
1128+ """Tests that loading a non-existent dashboard returns 404"""
1129+ url = reverse ('dashboard-load' , args = (9999 ,))
1130+ response = client .get (url )
1131+
1132+ assert response .status_code == 404
1133+
1134+ def test_given_other_users_private_dashboard_it_should_return_404 (
1135+ self , db , client , non_admin_account
1136+ ):
1137+ """Tests that loading another user's private dashboard returns 404"""
1138+ dashboard = create_dashboard (non_admin_account , is_shared = False )
1139+
1140+ url = reverse ('dashboard-load' , args = (dashboard .id ,))
1141+ response = client .get (url )
1142+
1143+ assert response .status_code == 404
1144+
1145+ def test_given_other_users_shared_dashboard_it_should_return_navlets (
1146+ self , db , client , admin_account , non_admin_account
1147+ ):
1148+ """Tests that loading another user's shared dashboard works"""
1149+ dashboard = create_dashboard (non_admin_account , is_shared = True )
1150+ create_widget (dashboard )
1151+
1152+ url = reverse ('dashboard-load' , args = (dashboard .id ,))
1153+ response = client .get (url )
1154+
1155+ assert response .status_code == 200
1156+ assert 'class="row' in smart_str (response .content )
1157+
1158+ def test_given_dashboard_with_compact_preference_it_should_add_collapse_class (
1159+ self , db , client , admin_account
1160+ ):
1161+ """Tests that compact preference adds collapse class to row"""
1162+ admin_account .preferences ['widget_display_density' ] = 'compact'
1163+ admin_account .save ()
1164+
1165+ dashboard = create_dashboard (admin_account )
1166+ url = reverse ('dashboard-load' , args = (dashboard .id ,))
1167+ response = client .get (url )
1168+
1169+ assert response .status_code == 200
1170+ assert 'class="row collapse"' in smart_str (response .content )
1171+
1172+ def test_given_dashboard_with_no_widgets_it_should_show_empty_state (
1173+ self , db , client , admin_account
1174+ ):
1175+ """Tests that dashboard with no widgets shows proper empty state"""
1176+ dashboard = create_dashboard (admin_account )
1177+ url = reverse ('dashboard-load' , args = (dashboard .id ,))
1178+ response = client .get (url )
1179+
1180+ assert response .status_code == 200
1181+ assert response .context ['has_navlets' ] is False
1182+ assert "no-widgets-message" in smart_str (response .content )
1183+
1184+ def test_dashboard_load_contains_correct_number_of_columns (
1185+ self , db , client , admin_account
1186+ ):
1187+ """Tests that the loaded dashboard contains the correct number of columns"""
1188+ num_columns = 4
1189+ dashboard = create_dashboard (admin_account )
1190+ dashboard .num_columns = num_columns
1191+ dashboard .save ()
1192+
1193+ url = reverse ('dashboard-load' , args = (dashboard .id ,))
1194+ response = client .get (url )
1195+
1196+ assert response .status_code == 200
1197+ content = smart_str (response .content )
1198+ for col_index in range (1 , num_columns + 1 ):
1199+ assert f'data-col="{ col_index } "' in content
1200+
1201+ def test_given_navlets_in_different_columns_it_should_distribute_them_correctly (
1202+ self , db , client , admin_account
1203+ ):
1204+ """Tests that navlets are distributed correctly across columns when loading"""
1205+ dashboard = create_dashboard (admin_account )
1206+ widget1 = create_widget (dashboard , column = 1 , order = 0 )
1207+ widget2 = create_widget (dashboard , column = 2 , order = 0 )
1208+ widget3 = create_widget (dashboard , column = 1 , order = 1 )
1209+
1210+ url = reverse ('dashboard-load' , args = (dashboard .id ,))
1211+ response = client .get (url )
1212+ assert response .status_code == 200
1213+
1214+ columns = response .context ['columns' ]
1215+ assert isinstance (columns , dict )
1216+ assert set (columns .keys ()) >= {1 , 2 }
1217+
1218+ # Check widgets are in the correct columns and orders
1219+ column1_ids = [w ['id' ] for w in columns [1 ]]
1220+ column2_ids = [w ['id' ] for w in columns [2 ]]
1221+
1222+ assert column1_ids == [widget1 .id , widget3 .id ]
1223+ assert column2_ids == [widget2 .id ]
1224+
1225+
11111226def create_dashboard (account , name = "Test Dashboard" , is_default = False , is_shared = False ):
11121227 return AccountDashboard .objects .create (
11131228 name = name ,
@@ -1117,11 +1232,15 @@ def create_dashboard(account, name="Test Dashboard", is_default=False, is_shared
11171232 )
11181233
11191234
1120- def create_widget (dashboard , navlet = 'nav.web.navlets.welcome.WelcomeNavlet' ):
1235+ def create_widget (
1236+ dashboard , navlet = 'nav.web.navlets.welcome.WelcomeNavlet' , column = 1 , order = 0
1237+ ):
11211238 return AccountNavlet .objects .create (
11221239 dashboard = dashboard ,
11231240 account = dashboard .account ,
11241241 navlet = navlet ,
1242+ column = column ,
1243+ order = order ,
11251244 )
11261245
11271246
0 commit comments