- Statuses can now be bulk-imported/updated via CSV (Name, Color columns; matches and updates existing statuses by name). New internal/statuses/csv.go, tested. - Icon fields (folder create/rename, item type form) are now a searchable dropdown of the 50 most common Bootstrap Icons instead of a free-text box, via a small reusable .icon-picker widget in app.js/app.css. - CSV asset import is now folder-scoped when triggered from the tree: right-click a folder (or its background) > Import CSV... imports every row directly into that folder, so the CSV needs no Folder column at all, and the option no longer appears at the top level. The original global, Folder-path-aware import (with auto-create-missing-folders) moved to a new admin-only Settings > Import / Export page, alongside the new Statuses import and format examples for both. assets.Import gained ImportOptions.TargetFolderID to drive the folder-scoped mode. - Site Name (Settings > General) now actually renders in the navbar brand and <title>, via a per-App "siteName" template func bound in loadTemplates. The brand is plain text now, not a link to /inventory.
77 lines
1.8 KiB
Go
77 lines
1.8 KiB
Go
package statuses_test
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"inventree/internal/database"
|
|
"inventree/internal/statuses"
|
|
)
|
|
|
|
func testDB(t *testing.T) *sql.DB {
|
|
t.Helper()
|
|
dir := t.TempDir()
|
|
db, err := database.Open(filepath.Join(dir, "test.db"))
|
|
if err != nil {
|
|
t.Fatalf("open db: %v", err)
|
|
}
|
|
t.Cleanup(func() { db.Close() })
|
|
return db
|
|
}
|
|
|
|
func TestImportCreatesAndUpdatesByName(t *testing.T) {
|
|
ctx := context.Background()
|
|
s := statuses.NewStore(testDB(t))
|
|
|
|
// "In Use" already exists from seed data; this should update its
|
|
// color rather than create a duplicate, and create "Awaiting Parts".
|
|
csvData := "Name,Color\nIn Use,primary\nAwaiting Parts,warning\n"
|
|
result, err := s.Import(ctx, strings.NewReader(csvData))
|
|
if err != nil {
|
|
t.Fatalf("import: %v", err)
|
|
}
|
|
if result.Created != 1 || result.Updated != 1 {
|
|
t.Fatalf("expected 1 created, 1 updated, got %+v", result)
|
|
}
|
|
|
|
list, err := s.List(ctx)
|
|
if err != nil {
|
|
t.Fatalf("list: %v", err)
|
|
}
|
|
var foundInUse, foundAwaiting bool
|
|
for _, st := range list {
|
|
if st.Name == "In Use" {
|
|
foundInUse = true
|
|
if st.Color != "primary" {
|
|
t.Errorf("expected In Use color updated to primary, got %s", st.Color)
|
|
}
|
|
}
|
|
if st.Name == "Awaiting Parts" {
|
|
foundAwaiting = true
|
|
if st.Color != "warning" {
|
|
t.Errorf("expected Awaiting Parts color warning, got %s", st.Color)
|
|
}
|
|
}
|
|
}
|
|
if !foundInUse || !foundAwaiting {
|
|
t.Fatalf("expected both statuses present, got %+v", list)
|
|
}
|
|
}
|
|
|
|
func TestImportSkipsRowsMissingName(t *testing.T) {
|
|
ctx := context.Background()
|
|
s := statuses.NewStore(testDB(t))
|
|
|
|
csvData := "Name,Color\n,primary\n"
|
|
result, err := s.Import(ctx, strings.NewReader(csvData))
|
|
if err != nil {
|
|
t.Fatalf("import: %v", err)
|
|
}
|
|
if result.Created != 0 || len(result.Errors) != 1 {
|
|
t.Fatalf("expected 0 created and 1 error, got %+v", result)
|
|
}
|
|
}
|