|
| 1 | +import { |
| 2 | + RdiStatisticsBlocksSection, |
| 3 | + RdiStatisticsInfoSection, |
| 4 | + RdiStatisticsTableSection, |
| 5 | + RdiStatisticsViewType, |
| 6 | +} from 'src/modules/rdi/models'; |
1 | 7 | import { |
2 | 8 | generateHeaderFromFieldName, |
3 | 9 | generateColumns, |
| 10 | + hasData, |
4 | 11 | } from './transformer.util'; |
5 | 12 |
|
6 | 13 | describe('transformer.util', () => { |
@@ -219,4 +226,96 @@ describe('transformer.util', () => { |
219 | 226 | ]); |
220 | 227 | }); |
221 | 228 | }); |
| 229 | + |
| 230 | + describe('hasData', () => { |
| 231 | + describe('table sections', () => { |
| 232 | + it('should return true when table section has columns and data', () => { |
| 233 | + const section: RdiStatisticsTableSection = { |
| 234 | + name: 'Test', |
| 235 | + view: RdiStatisticsViewType.Table, |
| 236 | + columns: [{ id: 'name', header: 'Name' }], |
| 237 | + data: [{ name: 'test' }], |
| 238 | + }; |
| 239 | + |
| 240 | + expect(hasData(section)).toBe(true); |
| 241 | + }); |
| 242 | + |
| 243 | + it('should return false when table section has empty columns', () => { |
| 244 | + const section: RdiStatisticsTableSection = { |
| 245 | + name: 'Test', |
| 246 | + view: RdiStatisticsViewType.Table, |
| 247 | + columns: [], |
| 248 | + data: [{ name: 'test' }], |
| 249 | + }; |
| 250 | + |
| 251 | + expect(hasData(section)).toBe(false); |
| 252 | + }); |
| 253 | + |
| 254 | + it('should return false when table section has empty data', () => { |
| 255 | + const section: RdiStatisticsTableSection = { |
| 256 | + name: 'Test', |
| 257 | + view: RdiStatisticsViewType.Table, |
| 258 | + columns: [{ id: 'name', header: 'Name' }], |
| 259 | + data: [], |
| 260 | + }; |
| 261 | + |
| 262 | + expect(hasData(section)).toBe(false); |
| 263 | + }); |
| 264 | + |
| 265 | + it('should return false when table section has both empty columns and data', () => { |
| 266 | + const section: RdiStatisticsTableSection = { |
| 267 | + name: 'Test', |
| 268 | + view: RdiStatisticsViewType.Table, |
| 269 | + columns: [], |
| 270 | + data: [], |
| 271 | + }; |
| 272 | + |
| 273 | + expect(hasData(section)).toBe(false); |
| 274 | + }); |
| 275 | + }); |
| 276 | + |
| 277 | + describe('blocks sections', () => { |
| 278 | + it('should return true when blocks section has data', () => { |
| 279 | + const section: RdiStatisticsBlocksSection = { |
| 280 | + name: 'Test', |
| 281 | + view: RdiStatisticsViewType.Blocks, |
| 282 | + data: [{ label: 'Count', value: 10, units: 'Total' }], |
| 283 | + }; |
| 284 | + |
| 285 | + expect(hasData(section)).toBe(true); |
| 286 | + }); |
| 287 | + |
| 288 | + it('should return false when blocks section has empty data', () => { |
| 289 | + const section: RdiStatisticsBlocksSection = { |
| 290 | + name: 'Test', |
| 291 | + view: RdiStatisticsViewType.Blocks, |
| 292 | + data: [], |
| 293 | + }; |
| 294 | + |
| 295 | + expect(hasData(section)).toBe(false); |
| 296 | + }); |
| 297 | + }); |
| 298 | + |
| 299 | + describe('info sections', () => { |
| 300 | + it('should return true for info sections regardless of data', () => { |
| 301 | + const section: RdiStatisticsInfoSection = { |
| 302 | + name: 'Test', |
| 303 | + view: RdiStatisticsViewType.Info, |
| 304 | + data: [], |
| 305 | + }; |
| 306 | + |
| 307 | + expect(hasData(section)).toBe(true); |
| 308 | + }); |
| 309 | + |
| 310 | + it('should return true for info sections with data', () => { |
| 311 | + const section: RdiStatisticsInfoSection = { |
| 312 | + name: 'Test', |
| 313 | + view: RdiStatisticsViewType.Info, |
| 314 | + data: [{ label: 'Version', value: '1.0.0' }], |
| 315 | + }; |
| 316 | + |
| 317 | + expect(hasData(section)).toBe(true); |
| 318 | + }); |
| 319 | + }); |
| 320 | + }); |
222 | 321 | }); |
0 commit comments