diff --git a/.formatter.exs b/.formatter.exs index 8a6391c6..21f7ecd8 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -1,5 +1,5 @@ [ - import_deps: [:ecto, :phoenix], + import_deps: [:ecto, :phoenix, :stream_data], inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"], subdirectories: ["priv/*/migrations"] ] diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index f68c9b66..e931454a 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -12,6 +12,7 @@ A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behaviour: + 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' diff --git a/.github/workflows/coveralls.yml b/.github/workflows/coveralls.yml index c808bb36..ff3087a1 100644 --- a/.github/workflows/coveralls.yml +++ b/.github/workflows/coveralls.yml @@ -30,7 +30,7 @@ jobs: otp-version: 24.2 elixir-version: 1.13.3 - run: mix deps.get - - run: MIX_ENV=test mix coveralls.json + - run: mix coveralls.json - name: Upload to codecov.io uses: codecov/codecov-action@v1 diff --git a/.github/workflows/credo.yml b/.github/workflows/credo.yml index 3fcf5fff..c194e81f 100644 --- a/.github/workflows/credo.yml +++ b/.github/workflows/credo.yml @@ -30,4 +30,4 @@ jobs: otp-version: 24.2 elixir-version: 1.13.3 - run: mix deps.get - - run: MIX_ENV=test mix credo --strict + - run: mix credo --strict diff --git a/.github/workflows/dialyzer.yml b/.github/workflows/dialyzer.yml index 1d8043d4..8e44a3f0 100644 --- a/.github/workflows/dialyzer.yml +++ b/.github/workflows/dialyzer.yml @@ -31,4 +31,4 @@ jobs: otp-version: 24.2 elixir-version: 1.13.3 - run: mix deps.get - - run: MIX_ENV=dev mix check --only dialyzer + - run: mix dialyzer diff --git a/CHANGELOG.md b/CHANGELOG.md index e1e6ce70..7f454f76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- Add formatter to field options - Update Erlang to 24.2 - Update Elixir to 1.13.3 - Add link to ElixirCasts video in Readme diff --git a/config/config.exs b/config/config.exs index beb1a471..6f05c02e 100644 --- a/config/config.exs +++ b/config/config.exs @@ -7,6 +7,8 @@ # General application configuration import Config +config :stream_data, max_runs: 1000 + # Configure your database config :exzeitable, TestWeb.Repo, username: "postgres", diff --git a/coveralls.json b/coveralls.json index f848ce8d..b966c0bd 100644 --- a/coveralls.json +++ b/coveralls.json @@ -3,29 +3,7 @@ "minimum_coverage": 50 }, "skip_files": [ - "error_helpers.ex", - "channel_case.ex", - "conn_case.ex", - "helpers.ex", - "endpoint.ex", - "application.ex", - "repo.ex", - "data_case.ex", - "exzeitable_web.ex", - "fallback_controller.ex", - "query.ex", - "router.ex", - "post.ex", - "user.ex", - "post_controller.ex", - "user_controller.ex", - "post_view.ex", - "user_view.ex", - "error_view.ex", - "layout_view.ex", - "gettext.ex", - "user_socket.ex", - "user_table.ex", - "post_table.ex" + "lib/test_web/*", + "test/support/*" ] } diff --git a/lib/exzeitable/html/pagination.ex b/lib/exzeitable/html/pagination.ex index 5954c0a9..fc7a4298 100644 --- a/lib/exzeitable/html/pagination.ex +++ b/lib/exzeitable/html/pagination.ex @@ -4,7 +4,7 @@ defmodule Exzeitable.HTML.Pagination do """ use Exzeitable.HTML.Helpers - @type name :: String.t() | atom | integer + @type name :: :next | :previous | :dots | pos_integer @type params :: %{ :page => pos_integer, :count => non_neg_integer, diff --git a/mix.exs b/mix.exs index 962e955b..82219f27 100644 --- a/mix.exs +++ b/mix.exs @@ -18,7 +18,11 @@ defmodule Exzeitable.MixProject do preferred_cli_env: [ dialyzer: :test, credo: :test, - "coveralls.html": :test + check: :test, + docs: :test, + "coveralls.html": :test, + "coveralls.json": :test, + "coveralls.lcov": :test ], dialyzer: [ plt_add_apps: [:ex_unit, :mix], @@ -109,13 +113,14 @@ defmodule Exzeitable.MixProject do {:gettext, "~> 0.18"}, {:jason, "~> 1.2"}, {:plug_cowboy, "~> 2.5"}, - {:timex, "~> 3.5", only: [:dev, :test, :systemtest]}, - {:ex_check, "~>0.12", only: :dev, runtime: false}, - {:credo, "~> 1.5", only: [:dev, :test], runtime: false}, - {:dialyxir, "~> 1.1", only: [:dev, :test], runtime: false}, + {:timex, "~> 3.5", only: [:test, :systemtest]}, + {:ex_check, "~>0.12", only: :test, runtime: false}, + {:credo, "~> 1.5", only: :test, runtime: false}, + {:dialyxir, "~> 1.1", only: :test, runtime: false}, {:excoveralls, "~> 0.10", only: :test, runtime: false}, - {:ex_doc, "~> 0.21", only: :dev, runtime: false}, - {:inch_ex, github: "rrrene/inch_ex", only: [:dev, :test]} + {:ex_doc, "~> 0.21", only: :test, runtime: false}, + {:inch_ex, github: "rrrene/inch_ex", only: [:test]}, + {:stream_data, "~> 0.5", only: :test} ] end diff --git a/mix.lock b/mix.lock index d3387773..f2fb85a8 100644 --- a/mix.lock +++ b/mix.lock @@ -49,6 +49,7 @@ "postgrex": {:hex, :postgrex, "0.16.2", "0f83198d0e73a36e8d716b90f45f3bde75b5eebf4ade4f43fa1f88c90a812f74", [:mix], [{:connection, "~> 1.1", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "a9ea589754d9d4d076121090662b7afe155b374897a6550eb288f11d755acfa0"}, "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"}, + "stream_data": {:hex, :stream_data, "0.5.0", "b27641e58941685c75b353577dc602c9d2c12292dd84babf506c2033cd97893e", [:mix], [], "hexpm", "012bd2eec069ada4db3411f9115ccafa38540a3c78c4c0349f151fc761b9e271"}, "swoosh": {:hex, :swoosh, "1.6.3", "598d3f07641004bedb3eede40057760ae18be1073cff72f079ca1e1fc9cd97b9", [:mix], [{:cowboy, "~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:finch, "~> 0.6", [hex: :finch, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13 or ~> 1.0", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "81ff9d7c7c4005a57465a7eb712edd71db51829aef94c8a34c30c5b9e9964adf"}, "telemetry": {:hex, :telemetry, "1.0.0", "0f453a102cdf13d506b7c0ab158324c337c41f1cc7548f0bc0e130bbf0ae9452", [:rebar3], [], "hexpm", "73bc09fa59b4a0284efb4624335583c528e07ec9ae76aca96ea0673850aec57a"}, "telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"}, diff --git a/test/exzeitable/html/pagination_test.exs b/test/exzeitable/html/pagination_test.exs index 8a2c814f..a6f6a32c 100644 --- a/test/exzeitable/html/pagination_test.exs +++ b/test/exzeitable/html/pagination_test.exs @@ -1,9 +1,12 @@ defmodule Exzeitable.HTML.PaginationTest do @moduledoc false use TestWeb.DataCase, async: true + use ExUnitProperties alias Exzeitable.HTML.Pagination + @params %{module: TestWeb.PostTable, text: Exzeitable.Text.Default, assigns: %{}} + describe "filter_pages/2" do test "returns no more than 7 buttons no matter the entry" do for pages <- 1..20 do @@ -20,4 +23,43 @@ defmodule Exzeitable.HTML.PaginationTest do assert buttons == expected_result end end + + describe "build/1" do + property "always returns html without error" do + check all page <- positive_integer(), + count <- integer(0..100_000), + per_page <- positive_integer() do + result = + @params + |> Map.merge(%{page: page, count: count, per_page: per_page}) + |> Pagination.build() + + assert {:safe, [_ | _]} = result + end + end + end + + describe "page_count/1" do + test "counts the number of pages" do + assert 2 = Pagination.page_count(%{count: 10, per_page: 5}) + end + + test "counts partial pages" do + assert 3 = Pagination.page_count(%{count: 11, per_page: 5}) + end + + property "always returns a positive integer" do + check all page <- positive_integer(), + count <- integer(0..100_000), + per_page <- positive_integer() do + result = + @params + |> Map.merge(%{page: page, count: count, per_page: per_page}) + |> Pagination.page_count() + + assert is_integer(result) + assert result > 0 + end + end + end end