Skip to content

Commit

Permalink
Add cleanup and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Vardy authored and alanvardy committed Mar 30, 2022
1 parent 7377fd9 commit 893d419
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -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"]
]
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 '....'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coveralls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion .github/workflows/credo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/dialyzer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# General application configuration
import Config

config :stream_data, max_runs: 1000

# Configure your database
config :exzeitable, TestWeb.Repo,
username: "postgres",
Expand Down
26 changes: 2 additions & 24 deletions coveralls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/*"
]
}
2 changes: 1 addition & 1 deletion lib/exzeitable/html/pagination.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 12 additions & 7 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
42 changes: 42 additions & 0 deletions test/exzeitable/html/pagination_test.exs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

0 comments on commit 893d419

Please sign in to comment.