package handlers

import (
	"path/filepath"
	"testing"
)

func TestFileIconMapLoadsAndResolvesCommonTypes(t *testing.T) {
	icons, err := loadFileIcons(filepath.Join("..", "..", "static"))
	if err != nil {
		t.Fatalf("loadFileIcons returned error: %v", err)
	}

	tests := []struct {
		name         string
		contentType  string
		wantStandard string
		wantRetro    string
	}{
		{
			name:         "photo.jpg",
			contentType:  "application/octet-stream",
			wantStandard: "image-document-svgrepo-com.svg",
			wantRetro:    "shimgvw.dll_14_1-2.png",
		},
		{
			name:         "movie.mkv",
			contentType:  "",
			wantStandard: "video-document-svgrepo-com.svg",
			wantRetro:    "wmploc.dll_14_504-2.png",
		},
		{
			name:         "archive.7z",
			contentType:  "",
			wantStandard: "zip-document-svgrepo-com.svg",
			wantRetro:    "zipfldr.dll_14_101-2.png",
		},
		{
			name:         "unknown.bin",
			contentType:  "application/octet-stream",
			wantStandard: "txt-document-svgrepo-com.svg",
			wantRetro:    "shell32.dll_14_152-2.png",
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got := icons.lookup(tt.name, tt.contentType)
			if got.Standard != tt.wantStandard || got.Retro != tt.wantRetro {
				t.Fatalf("lookup returned %+v, want standard=%q retro=%q", got, tt.wantStandard, tt.wantRetro)
			}
		})
	}
}
