krz/skunky-art

Alternative privacy frontend for DeviantArt.

clone: git clone https://gitbay.org/krz/skunky-art.git

v1.3.9: app/parsers_test.go · raw

 1package app
 2
 3import (
 4	"strings"
 5	"testing"
 6
 7	"github.com/krazywarez/devianter"
 8)
 9
10// aiListDevs returns one human-made and one AI-flagged deviation, each with a
11// distinct title so the rendered output can be searched for either one.
12func aiListDevs() []devianter.Deviation {
13	human := devianter.Deviation{Title: "HumanArt"}
14	human.Author.Username = "alice"
15
16	robot := devianter.Deviation{Title: "RobotArt", AI: true}
17	robot.Author.Username = "bob"
18
19	return []devianter.Deviation{human, robot}
20}
21
22// TestDeviationListHidesAIWhenConfigured is the regression test for the hide-ai
23// option: with it on, deviations flagged data.AI must not appear in a listing at
24// all, while human-made ones are untouched.
25func TestDeviationListHidesAIWhenConfigured(t *testing.T) {
26	nsfw, hide := CFG.Nsfw, CFG.HideAI
27	CFG.Nsfw, CFG.HideAI = true, true
28	defer func() { CFG.Nsfw, CFG.HideAI = nsfw, hide }()
29
30	out := skunkyart{Host: "http://localhost"}.DeviationList(aiListDevs(), false)
31
32	if !strings.Contains(out, "HumanArt") {
33		t.Error("human deviation was dropped, want it kept")
34	}
35	if strings.Contains(out, "RobotArt") {
36		t.Error("AI deviation rendered while hide-ai is on, want it omitted")
37	}
38	if strings.Contains(out, "🤖") {
39		t.Error("AI marker present while hide-ai is on")
40	}
41}
42
43// TestDeviationListShowsAIByDefault pins down that the filter is opt-in: with
44// hide-ai off the AI deviation is still listed and still carries its marker.
45func TestDeviationListShowsAIByDefault(t *testing.T) {
46	nsfw, hide := CFG.Nsfw, CFG.HideAI
47	CFG.Nsfw, CFG.HideAI = true, false
48	defer func() { CFG.Nsfw, CFG.HideAI = nsfw, hide }()
49
50	out := skunkyart{Host: "http://localhost"}.DeviationList(aiListDevs(), false)
51
52	if !strings.Contains(out, "RobotArt") {
53		t.Error("AI deviation dropped while hide-ai is off, want it kept")
54	}
55	if !strings.Contains(out, "🤖") {
56		t.Error("AI marker missing while hide-ai is off")
57	}
58}