// Test tagging feature in UIManager const { test } = require('node:test'); const assert = require('node:assert'); const fs = require('fs'); const path = require('path'); // Read UIManager to check the tagging implementation const uiManagerContent = fs.readFileSync('./utils/renderer/UIManager.js', 'utf8'); test('Tagging feature - verify handleTagClick logic', () => { // Check that handleTagClick function exists assert.ok(uiManagerContent.includes('handleTagClick'), 'handleTagClick function should exist'); // Check that it processes all tag types assert.ok(uiManagerContent.includes('allTagTypes'), 'Should have allTagTypes array'); // Verify the logic for untagging other tags assert.ok( uiManagerContent.includes('existingTagType !== tagType') || uiManagerContent.includes('if (existingTagType !== tagType'), 'Should check if tag is different before removing' ); // Verify it removes other tags before applying new one assert.ok( uiManagerContent.includes('Remove all other tags first') || uiManagerContent.includes('fileItem.hasAttribute(`data-tagged-'), 'Should check for existing tags on file item' ); console.log('✅ handleTagClick logic verified'); }); test('Tagging feature - verify addTagToEpisode function', () => { // Check that addTagToEpisode function exists assert.ok(uiManagerContent.includes('addTagToEpisode'), 'addTagToEpisode function should exist'); // Verify it sets visual styles assert.ok(uiManagerContent.includes('tagIcon.style.opacity'), 'Should set opacity'); assert.ok(uiManagerContent.includes('tagIcon.style.color'), 'Should set color'); assert.ok(uiManagerContent.includes('tagIcon.style.textShadow'), 'Should set text shadow'); assert.ok(uiManagerContent.includes('tagIcon.style.transform'), 'Should set transform'); // Verify it adds data attribute assert.ok(uiManagerContent.includes('item.setAttribute(\'data-tagged-'), 'Should set data-tagged attribute'); // Verify it enables play button assert.ok(uiManagerContent.includes('playButton.style.opacity'), 'Should set play button opacity'); assert.ok(uiManagerContent.includes('playButton.disabled = false'), 'Should enable play button'); console.log('✅ addTagToEpisode function verified'); }); test('Tagging feature - verify untagFile function', () => { // Check that untagFile function exists assert.ok(uiManagerContent.includes('untagFile'), 'untagFile function should exist'); // Verify it resets visual styles assert.ok(uiManagerContent.includes('tagIcon.style.opacity = \'0.7\''), 'Should reset opacity'); assert.ok(uiManagerContent.includes('tagIcon.style.color = \'\''), 'Should reset color'); assert.ok(uiManagerContent.includes('tagIcon.style.textShadow = \'none\''), 'Should reset text shadow'); assert.ok(uiManagerContent.includes('tagIcon.style.transform = \'scale(1)\''), 'Should reset transform'); // Verify it removes data attribute assert.ok(uiManagerContent.includes('item.removeAttribute(\'data-tagged-'), 'Should remove data-tagged attribute'); // Verify it checks for other tags before disabling play button assert.ok( uiManagerContent.includes('hasOtherTags') || uiManagerContent.includes('item.hasAttribute(\'data-tagged-'), 'Should check for other tags' ); console.log('✅ untagFile function verified'); }); test('Tagging feature - verify tag colors', () => { // Check that yellow color is defined for extra tag assert.ok( uiManagerContent.includes('#FFD700') || uiManagerContent.includes('"#FFD700"') || uiManagerContent.includes("'#FFD700'"), 'Should have yellow color for extra tag' ); // Check that teal color is defined for behind-the-scenes tag assert.ok( uiManagerContent.includes('#17a2b8') || uiManagerContent.includes('"#17a2b8"') || uiManagerContent.includes("'#17a2b8'"), 'Should have teal color for behind-the-scenes tag' ); // Check that red color is defined for delete tag assert.ok( uiManagerContent.includes('#dc3545') || uiManagerContent.includes('"#dc3545"') || uiManagerContent.includes("'#dc3545'"), 'Should have red color for delete tag' ); console.log('✅ Tag colors verified'); }); test('Tagging feature - verify updateTaggedCount function', () => { // Check that updateTaggedCount function exists assert.ok(uiManagerContent.includes('updateTaggedCount'), 'updateTaggedCount function should exist'); // Verify it counts tagged items assert.ok( uiManagerContent.includes('data-tagged-extra') && uiManagerContent.includes('data-tagged-behind-the-scenes') && uiManagerContent.includes('data-tagged-delete'), 'Should count all tag types' ); console.log('✅ updateTaggedCount function verified'); }); test('Tagging feature - verify moveAllTaggedFiles function', () => { // Check that moveAllTaggedFiles function exists assert.ok(uiManagerContent.includes('moveAllTaggedFiles'), 'moveAllTaggedFiles function should exist'); // Verify it iterates through all tagged items assert.ok( uiManagerContent.includes('data-tagged-extra') && uiManagerContent.includes('data-tagged-behind-the-scenes') && uiManagerContent.includes('data-tagged-delete'), 'Should handle all tag types' ); // Verify it removes items after successful move assert.ok(uiManagerContent.includes('item.remove()'), 'Should remove items after move'); console.log('✅ moveAllTaggedFiles function verified'); }); test('Tagging feature - verify tag icon click handler', () => { // Check that tag icon click handler is set up assert.ok( uiManagerContent.includes('tag-icon') || uiManagerContent.includes('tagIcon'), 'Should have tag icon click handler' ); // Verify it determines tag type from class assert.ok( uiManagerContent.includes('extra-tag') || uiManagerContent.includes('behind-the-scenes-tag') || uiManagerContent.includes('delete-tag'), 'Should identify tag types from classes' ); console.log('✅ Tag icon click handler verified'); }); test('Tagging feature - verify integration with moveTaggedFile', () => { // Check that moveTaggedFile function exists assert.ok(uiManagerContent.includes('moveTaggedFile'), 'moveTaggedFile function should exist'); // Verify it logs audit event assert.ok( uiManagerContent.includes('logAuditEvent') || uiManagerContent.includes('log-audit'), 'Should log audit event' ); // Verify it sends IPC message to main process assert.ok( uiManagerContent.includes('ipcRenderer.invoke') && uiManagerContent.includes('move-file-to-folder'), 'Should send IPC message to move file' ); console.log('✅ moveTaggedFile integration verified'); }); console.log('\n✅ All tagging feature tests passed!');