diff --git a/config/config.exs b/config/config.exs index 6048e84..3c32b1b 100644 --- a/config/config.exs +++ b/config/config.exs @@ -4,3 +4,7 @@ config :bitstyles_phoenix, trim_e2e_classes: [enabled: true] config :phoenix, :json_library, Jason + +if config_env() === :test do + config :bitstyles_phoenix, add_version_test_classes: true +end diff --git a/lib/bitstyles_phoenix/bitstyles.ex b/lib/bitstyles_phoenix/bitstyles.ex index eae9eed..9902545 100644 --- a/lib/bitstyles_phoenix/bitstyles.ex +++ b/lib/bitstyles_phoenix/bitstyles.ex @@ -77,10 +77,11 @@ defmodule BitstylesPhoenix.Bitstyles do "u-fg-text" -> "u-fg-gray-30" "u-fg-text-darker" -> "u-fg-gray-50" "u-bg-gray-darker" -> "u-bg-gray-80" - "u-version-5-0-0" -> "u-version-4" class -> class end + class = test_only_downgrade(class, "u-version-5-0-0", "u-version-4") + downgrade_classname(class, target_version, {4, 3, 0}) end @@ -127,10 +128,11 @@ defmodule BitstylesPhoenix.Bitstyles do "u-border-radius-" <> variant -> "u-round--#{variant}" "u-overflow-x-auto" -> "u-overflow--x" "u-overflow-y-auto" -> "u-overflow--y" - "u-version-4" -> "u-version-2" _ -> class end + class = test_only_downgrade(class, "u-version-4", "u-version-2") + downgrade_classname(class, target_version, {3, 0, 0}) end @@ -147,10 +149,11 @@ defmodule BitstylesPhoenix.Bitstyles do "u-flex-grow-" <> number -> "u-flex__grow-#{number}" "u-flex-wrap" -> "u-flex--wrap" "u-flex-col" -> "u-flex--col" - "u-version-2" -> "u-version-1-4" _ -> class end + class = test_only_downgrade(class, "u-version-2", "u-version-1-4") + downgrade_classname(class, target_version, {1, 5, 0}) end @@ -161,16 +164,17 @@ defmodule BitstylesPhoenix.Bitstyles do defp downgrade_classname(class, target_version, {1, 4, 0}) do # downgrading 1.4.0 -> 1.3.0 - mapping = + class = case class do "u-grid-cols-" <> number -> "u-grid--#{number}-col" "u-col-span-" <> number -> "u-grid__col-span-#{number}" "u-col-start-" <> number -> "u-grid__col-#{number}" - "u-version-1-4" -> "u-version-1-3" _ -> class end - downgrade_classname(mapping, target_version, {1, 3, 0}) + class = test_only_downgrade(class, "u-version-1-4", "u-version-1-3") + + downgrade_classname(class, target_version, {1, 3, 0}) end defp downgrade_classname(class, target_version, {1, 3, 0}) do @@ -184,4 +188,12 @@ defmodule BitstylesPhoenix.Bitstyles do Please upgrade bitsyles and set the `bitsyles_version` to the updated version. """) end + + defp test_only_downgrade(class, from, to) do + if Application.get_env(:bitstyles_phoenix, :add_version_test_classes, false) do + if(class == from, do: to, else: class) + else + class + end + end end diff --git a/test/bitstyles_phoenix/bitstyles_test.exs b/test/bitstyles_phoenix/bitstyles_test.exs index 4c8e935..c367223 100644 --- a/test/bitstyles_phoenix/bitstyles_test.exs +++ b/test/bitstyles_phoenix/bitstyles_test.exs @@ -11,8 +11,9 @@ defmodule BitstylesPhoenix.BitstylesTest do ) end - # TODO: delete - test "chained version" do + test "chained version downgrade" do + # those class changes are only added in the test environment, to test that chaining works + # and won't be available to the users of bitstyles_phoenix assert classname("u-version-5-0-0", {5, 0, 1}) == "u-version-5-0-0" assert classname("u-version-5-0-0", {5, 0, 0}) == "u-version-5-0-0" assert classname("u-version-5-0-0", {4, 3, 0}) == "u-version-4"