99 lines
3.8 KiB
Go
99 lines
3.8 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestCustomSchemeCanBeFavoritedAndAppliedToApps(t *testing.T) {
|
|
tinty, err := exec.LookPath("tinty")
|
|
if err != nil {
|
|
t.Skip("requires tinty 0.34+")
|
|
}
|
|
home := t.TempDir()
|
|
data := filepath.Join(home, "data")
|
|
bin := filepath.Join(home, "bin")
|
|
for _, dir := range []string{bin, filepath.Join(data, "repos", "schemes", "base16"), filepath.Join(data, "custom-schemes", "base16"), filepath.Join(home, ".config", "herdr")} {
|
|
if err := os.MkdirAll(dir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
palette, err := os.ReadFile("schemes/base16/terebi-sunset.yaml")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
files := map[string][]byte{
|
|
filepath.Join(data, "custom-schemes", "base16", "terebi-sunset.yaml"): palette,
|
|
filepath.Join(home, "config.toml"): []byte("items = []\n"),
|
|
filepath.Join(home, ".config", "herdr", "config.toml"): []byte("[server]\nport = 8080\n"),
|
|
filepath.Join(home, "zed.json"): []byte(`{"name":"Terebi Sunset","themes":[{"name":"Terebi Sunset","appearance":"dark"}]}`),
|
|
}
|
|
for path, contents := range files {
|
|
if err := os.WriteFile(path, contents, 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
writeExecutable(t, filepath.Join(bin, "tinty"), `#!/bin/sh
|
|
exec "$TINTY_TEST_BINARY" --data-dir "$TINTY_TEST_DATA" --config "$TINTY_TEST_CONFIG" "$@"
|
|
`)
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
|
|
t.Setenv("PATH", bin+":/usr/bin:/bin")
|
|
t.Setenv("TINTY_TEST_BINARY", tinty)
|
|
t.Setenv("TINTY_TEST_DATA", data)
|
|
t.Setenv("TINTY_TEST_CONFIG", filepath.Join(home, "config.toml"))
|
|
statePath := filepath.Join(home, "state.toml")
|
|
t.Setenv("TINT_STATE_FILE", statePath)
|
|
initial := state{Current: currentPair{Light: "personal-light", Dark: "personal-dark"}}
|
|
if err := saveState(statePath, initial); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var stdout, stderr bytes.Buffer
|
|
if err := runCLI([]string{"favorite", "base16-terebi-sunset"}, &stdout, &stderr); err != nil {
|
|
t.Fatalf("custom scheme could not be favorited: %v: %s", err, stderr.String())
|
|
}
|
|
value, err := loadState(statePath)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if value.Current != initial.Current || len(value.Catalog.FavoriteThemes) != 1 || value.Catalog.FavoriteThemes[0] != "base16-terebi-sunset" {
|
|
t.Fatalf("favorite changed the current pair or omitted the scheme: %#v", value)
|
|
}
|
|
before := readFile(t, statePath)
|
|
if err := runCLI([]string{"favorite", "base16-missing"}, &stdout, &stderr); err == nil {
|
|
t.Fatal("accepted a nonexistent custom scheme")
|
|
}
|
|
if readFile(t, statePath) != before {
|
|
t.Fatal("invalid scheme changed saved state")
|
|
}
|
|
if output, err := exec.Command("tinty", "apply", "base16-terebi-sunset").CombinedOutput(); err != nil {
|
|
t.Fatalf("Tinty could not apply the custom scheme: %v\n%s", err, output)
|
|
}
|
|
if err := applyApps(filepath.Join(home, "zed.json")); err != nil {
|
|
t.Fatalf("custom scheme could not be applied: %v", err)
|
|
}
|
|
var omp struct {
|
|
Colors map[string]string `json:"colors"`
|
|
}
|
|
if err := json.Unmarshal([]byte(readFile(t, filepath.Join(home, ".omp", "agent", "themes", "tinty-current.json"))), &omp); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if omp.Colors["text"] != "#ffe3b5" || omp.Colors["syntaxNumber"] != "#f2943b" {
|
|
t.Fatalf("OMP did not receive the custom scheme: %#v", omp.Colors)
|
|
}
|
|
var conjure struct {
|
|
Variant string `json:"variant"`
|
|
Colors map[string]string `json:"colors"`
|
|
}
|
|
if err := json.Unmarshal([]byte(readFile(t, filepath.Join(home, ".config", "conjure", "theme.json"))), &conjure); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if conjure.Variant != "dark" || conjure.Colors["background"] != "#1f1714" || conjure.Colors["secondaryText"] != "#d9c7a6" {
|
|
t.Fatalf("Conjure did not receive the custom scheme: %#v", conjure)
|
|
}
|
|
}
|