|
1 | 1 | import { describe, test, expect } from 'bun:test' |
2 | 2 | import type { ColumnInfo } from '@frontend/types/wikibase-schema' |
| 3 | +import { useColumnDataTypeIndicators } from '@frontend/composables/useColumnDataTypeIndicators' |
| 4 | + |
| 5 | +/** |
| 6 | + * ColumnPalette Component Tests |
| 7 | + * |
| 8 | + * These tests verify the integration between the ColumnPalette component and the |
| 9 | + * useColumnDataTypeIndicators composable |
| 10 | + */ |
3 | 11 |
|
4 | 12 | // Test the component logic without DOM testing since we don't have full test setup |
5 | 13 | describe('ColumnPalette Component Logic', () => { |
@@ -192,4 +200,137 @@ describe('ColumnPalette Component Logic', () => { |
192 | 200 | expect(column.nullable).toBe(true) |
193 | 201 | }) |
194 | 202 | }) |
| 203 | + |
| 204 | + describe('column data type display and tooltips', () => { |
| 205 | + const { |
| 206 | + getCompatibleWikibaseTypes, |
| 207 | + formatDataTypeDisplayName, |
| 208 | + generateDataTypeTooltip, |
| 209 | + generateColumnTooltip, |
| 210 | + } = useColumnDataTypeIndicators() |
| 211 | + |
| 212 | + test('should generate correct tooltip content for data types', () => { |
| 213 | + const column: ColumnInfo = { |
| 214 | + name: 'test_column', |
| 215 | + dataType: 'VARCHAR', |
| 216 | + sampleValues: ['sample1', 'sample2', 'sample3'], |
| 217 | + nullable: true, |
| 218 | + uniqueCount: 150, |
| 219 | + } |
| 220 | + |
| 221 | + const tooltip = generateDataTypeTooltip(column) |
| 222 | + |
| 223 | + expect(tooltip).toContain('Data Type: Text (VARCHAR)') |
| 224 | + expect(tooltip).toContain('Nullable: Yes') |
| 225 | + expect(tooltip).toContain('Unique Values: 150') |
| 226 | + expect(tooltip).toContain('Wikibase Compatible: string, url, external-id, monolingualtext') |
| 227 | + }) |
| 228 | + |
| 229 | + test('should handle tooltip content for columns without unique count', () => { |
| 230 | + const column: ColumnInfo = { |
| 231 | + name: 'test_column', |
| 232 | + dataType: 'INTEGER', |
| 233 | + sampleValues: ['1', '2'], |
| 234 | + nullable: false, |
| 235 | + } |
| 236 | + |
| 237 | + const tooltip = generateDataTypeTooltip(column) |
| 238 | + |
| 239 | + expect(tooltip).toContain('Data Type: Number (INTEGER)') |
| 240 | + expect(tooltip).not.toContain('Nullable: Yes') |
| 241 | + expect(tooltip).not.toContain('Unique Values:') |
| 242 | + expect(tooltip).toContain('Wikibase Compatible: quantity') |
| 243 | + }) |
| 244 | + |
| 245 | + test('should generate data type compatibility information', () => { |
| 246 | + expect(getCompatibleWikibaseTypes('VARCHAR')).toEqual([ |
| 247 | + 'string', |
| 248 | + 'url', |
| 249 | + 'external-id', |
| 250 | + 'monolingualtext', |
| 251 | + ]) |
| 252 | + expect(getCompatibleWikibaseTypes('INTEGER')).toEqual(['quantity']) |
| 253 | + expect(getCompatibleWikibaseTypes('DATE')).toEqual(['time']) |
| 254 | + expect(getCompatibleWikibaseTypes('UNKNOWN')).toEqual([]) |
| 255 | + }) |
| 256 | + |
| 257 | + test('should format data type display names', () => { |
| 258 | + expect(formatDataTypeDisplayName('VARCHAR')).toBe('Text') |
| 259 | + expect(formatDataTypeDisplayName('INTEGER')).toBe('Number') |
| 260 | + expect(formatDataTypeDisplayName('DATE')).toBe('Date') |
| 261 | + expect(formatDataTypeDisplayName('DATETIME')).toBe('Date/Time') |
| 262 | + expect(formatDataTypeDisplayName('BOOLEAN')).toBe('Boolean') |
| 263 | + expect(formatDataTypeDisplayName('DECIMAL')).toBe('Decimal') |
| 264 | + expect(formatDataTypeDisplayName('UNKNOWN_TYPE')).toBe('UNKNOWN_TYPE') |
| 265 | + }) |
| 266 | + |
| 267 | + test('should generate comprehensive column tooltip with data type and sample values', () => { |
| 268 | + const column: ColumnInfo = { |
| 269 | + name: 'test_column', |
| 270 | + dataType: 'VARCHAR', |
| 271 | + sampleValues: ['sample1', 'sample2', 'sample3'], |
| 272 | + nullable: true, |
| 273 | + uniqueCount: 150, |
| 274 | + } |
| 275 | + |
| 276 | + const tooltip = generateColumnTooltip(column) |
| 277 | + |
| 278 | + expect(tooltip).toContain('Data Type: Text (VARCHAR)') |
| 279 | + expect(tooltip).toContain('Nullable: Yes') |
| 280 | + expect(tooltip).toContain('Unique Values: 150') |
| 281 | + expect(tooltip).toContain('Sample Values:') |
| 282 | + expect(tooltip).toContain('sample1, sample2, sample3') |
| 283 | + }) |
| 284 | + }) |
| 285 | + |
| 286 | + describe('sample value display functionality', () => { |
| 287 | + const { formatSampleValuesForTooltip, generateSampleStats } = useColumnDataTypeIndicators() |
| 288 | + |
| 289 | + test('should format sample values with proper truncation', () => { |
| 290 | + const manyValues = ['val1', 'val2', 'val3', 'val4', 'val5', 'val6', 'val7'] |
| 291 | + const fewValues = ['val1', 'val2', 'val3'] |
| 292 | + const emptyValues: string[] = [] |
| 293 | + |
| 294 | + expect(formatSampleValuesForTooltip(manyValues, 5)).toBe( |
| 295 | + 'val1, val2, val3, val4, val5, ... (+2 more)', |
| 296 | + ) |
| 297 | + expect(formatSampleValuesForTooltip(fewValues, 5)).toBe('val1, val2, val3') |
| 298 | + expect(formatSampleValuesForTooltip(emptyValues)).toBe('No sample data available') |
| 299 | + }) |
| 300 | + |
| 301 | + test('should handle long sample values with truncation', () => { |
| 302 | + const longValues = ['This is a very long sample value that should be truncated for display'] |
| 303 | + const shortValues = ['Short value'] |
| 304 | + |
| 305 | + const longResult = formatSampleValuesForTooltip(longValues) |
| 306 | + const shortResult = formatSampleValuesForTooltip(shortValues) |
| 307 | + |
| 308 | + expect(longResult).toContain('...') |
| 309 | + expect(shortResult).toBe('Short value') |
| 310 | + }) |
| 311 | + |
| 312 | + test('should generate sample value statistics', () => { |
| 313 | + const valuesWithNulls = ['value1', 'null', 'value2', ''] |
| 314 | + const valuesWithoutNulls = ['value1', 'value2', 'value3'] |
| 315 | + const emptyValues: string[] = [] |
| 316 | + |
| 317 | + const statsWithNulls = generateSampleStats(valuesWithNulls) |
| 318 | + expect(statsWithNulls.isEmpty).toBe(false) |
| 319 | + expect(statsWithNulls.count).toBe(4) |
| 320 | + expect(statsWithNulls.hasNulls).toBe(true) |
| 321 | + expect(statsWithNulls.nullCount).toBe(2) |
| 322 | + |
| 323 | + const statsWithoutNulls = generateSampleStats(valuesWithoutNulls) |
| 324 | + expect(statsWithoutNulls.isEmpty).toBe(false) |
| 325 | + expect(statsWithoutNulls.count).toBe(3) |
| 326 | + expect(statsWithoutNulls.hasNulls).toBe(false) |
| 327 | + expect(statsWithoutNulls.nullCount).toBe(0) |
| 328 | + |
| 329 | + const emptyStats = generateSampleStats(emptyValues) |
| 330 | + expect(emptyStats.isEmpty).toBe(true) |
| 331 | + expect(emptyStats.count).toBe(0) |
| 332 | + expect(emptyStats.hasNulls).toBe(false) |
| 333 | + expect(emptyStats.nullCount).toBe(0) |
| 334 | + }) |
| 335 | + }) |
195 | 336 | }) |
0 commit comments