1 defmodule Mix.Tasks.Pleroma.EmojiTest do
2 use ExUnit.Case, async: true
4 import ExUnit.CaptureIO
7 alias Mix.Tasks.Pleroma.Emoji
10 test "with default manifest as url" do
14 url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/index.json"
18 body: File.read!("test/fixtures/emoji/packs/default-manifest.json")
22 capture_io(fn -> Emoji.run(["ls-packs"]) end) =~
23 "https://finland.fi/wp-content/uploads/2017/06/finland-emojis.zip"
26 test "with passed manifest as file" do
28 Emoji.run(["ls-packs", "-m", "test/fixtures/emoji/packs/manifest.json"])
29 end) =~ "https://git.pleroma.social/pleroma/emoji-index/raw/master/packs/blobs_gg.zip"
33 describe "get-packs" do
34 test "download pack from default manifest" do
38 url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/index.json"
42 body: File.read!("test/fixtures/emoji/packs/default-manifest.json")
47 url: "https://finland.fi/wp-content/uploads/2017/06/finland-emojis.zip"
51 body: File.read!("test/fixtures/emoji/packs/blank.png.zip")
56 url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/finmoji.json"
60 body: File.read!("test/fixtures/emoji/packs/finmoji.json")
64 assert capture_io(fn -> Emoji.run(["get-packs", "finmoji"]) end) =~ "Writing pack.json for"
68 Pleroma.Config.get!([:instance, :static_dir]),
72 assert File.exists?(Path.join([emoji_path, "finmoji", "pack.json"]))
73 on_exit(fn -> File.rm_rf!("test/instance_static/emoji/finmoji") end)
76 test "install local emoji pack" do
77 assert capture_io(fn ->
82 "test/instance_static/local_pack/manifest.json"
84 end) =~ "Writing pack.json for"
86 on_exit(fn -> File.rm_rf!("test/instance_static/emoji/local") end)
89 test "pack not found" do
93 url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/index.json"
97 body: File.read!("test/fixtures/emoji/packs/default-manifest.json")
101 assert capture_io(fn -> Emoji.run(["get-packs", "not_found"]) end) =~
102 "No pack named \"not_found\" found"
105 test "raise on bad sha256" do
109 url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/packs/blobs_gg.zip"
113 body: File.read!("test/fixtures/emoji/packs/blank.png.zip")
117 assert_raise RuntimeError, ~r/^Bad SHA256 for blobs.gg/, fn ->
119 Emoji.run(["get-packs", "blobs.gg", "-m", "test/fixtures/emoji/packs/manifest.json"])
125 describe "gen-pack" do
127 url = "https://finland.fi/wp-content/uploads/2017/06/finland-emojis.zip"
133 %Tesla.Env{status: 200, body: File.read!("test/fixtures/emoji/packs/blank.png.zip")}
139 test "with default extensions", %{url: url} do
141 pack_json = "#{name}.json"
142 files_json = "#{name}_file.json"
143 refute File.exists?(pack_json)
144 refute File.exists?(files_json)
166 assert captured =~ "#{pack_json} has been created with the pack1 pack"
167 assert captured =~ "Using .png .gif extensions"
169 assert File.exists?(pack_json)
170 assert File.exists?(files_json)
178 test "with custom extensions and update existing files", %{url: url} do
180 pack_json = "#{name}.json"
181 files_json = "#{name}_file.json"
182 refute File.exists?(pack_json)
183 refute File.exists?(files_json)
205 assert captured =~ "#{pack_json} has been created with the pack2 pack"
206 assert captured =~ "Using .png .gif .jpeg extensions"
208 assert File.exists?(pack_json)
209 assert File.exists?(files_json)
231 assert captured =~ "#{pack_json} has been updated with the pack2 pack"