Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linting CI #101

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CI

on:
push:
branches:
- main
pull_request:

jobs:
lint:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3

- uses: erlef/setup-beam@v1
with:
otp-version: 27.x
elixir-version: 1.17.x

- uses: actions/cache@v3
id: cache-deps
with:
path: |
deps
_build
key: ${{ runner.os }}-mix-lint-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-lint-

- run: mix do deps.get --check-locked, deps.compile
if: steps.cache-deps.outputs.cache-hit != 'true'

- run: mix deps.unlock --check-unused
- run: mix compile --warnings-as-errors
- run: mix format --check-formatted
2 changes: 1 addition & 1 deletion lib/haj_web/live/poll_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ defmodule HajWeb.PollLive.Show do
role="list"
phx-update="stream"
id="options"
class="divide mt-4 grid gap-x-4 divide-gray-100 md:grid-cols-2"
class="divide mt-4 grid grid-cols-2 gap-x-4 divide-gray-100"
>
<div
:for={{id, option} <- @streams.options}
Expand Down
10 changes: 8 additions & 2 deletions lib/haj_web/live/responsibility_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,14 @@ defmodule HajWeb.ResponsibilityLive.Show do

@impl true
def handle_event("select_tab", %{"tab_form" => %{"tab" => tab}}, socket) do
{:noreply,
socket |> push_patch(to: ~p"/responsibilities/#{socket.assigns.responsibility}/#{tab}")}
to =
case tab do
"comments" -> ~p"/responsibilities/#{socket.assigns.responsibility}/comments"
"history" -> ~p"/responsibilities/#{socket.assigns.responsibility}/history"
"description" -> ~p"/responsibilities/#{socket.assigns.responsibility}/"
end

{:noreply, socket |> push_patch(to: to)}
end

@impl true
Expand Down
2 changes: 1 addition & 1 deletion lib/haj_web/live/responsibility_live/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
f,
:tab,
[
{"Beskrivning", ""},
{"Beskrivning", "description"},
{"Testamenten", "comments"},
{"Historia", "history"}
],
Expand Down
4 changes: 2 additions & 2 deletions lib/haj_web/live/settings_live/polls/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ defmodule HajWeb.SettingsLive.Poll.Show do
|> assign(:option, nil)
end

defp apply_action(socket, :show_option, %{"id" => id, "option_id" => option_id}) do
defp apply_action(socket, :show_option, %{"id" => _id, "option_id" => option_id}) do
socket
|> assign(:page_title, "Show Option")
|> assign(:option, Polls.get_option!(option_id))
end

defp apply_action(socket, :edit_option, %{"id" => id, "option_id" => option_id}) do
defp apply_action(socket, :edit_option, %{"id" => _id, "option_id" => option_id}) do
socket
|> assign(:page_title, "Edit Option")
|> assign(:option, Polls.get_option!(option_id))
Expand Down
162 changes: 83 additions & 79 deletions test/haj_web/live/option_live_test.exs
Original file line number Diff line number Diff line change
@@ -1,113 +1,117 @@
defmodule HajWeb.OptionLiveTest do
use HajWeb.ConnCase
use HajWeb.ConnCase

import Phoenix.LiveViewTest
import Haj.PollsFixtures
import Phoenix.LiveViewTest
import Haj.PollsFixtures

@create_attrs %{name: "some name", description: "some description", url: "some url"}
@update_attrs %{name: "some updated name", description: "some updated description", url: "some updated url"}
@invalid_attrs %{name: nil, description: nil, url: nil}
@create_attrs %{name: "some name", description: "some description", url: "some url"}
@update_attrs %{
name: "some updated name",
description: "some updated description",
url: "some updated url"
}
@invalid_attrs %{name: nil, description: nil, url: nil}

defp create_option(_) do
option = option_fixture()
%{option: option}
end
defp create_option(_) do
option = option_fixture()
%{option: option}
end

describe "Index" do
setup [:create_option]
describe "Index" do
setup [:create_option]

test "lists all options", %{conn: conn, option: option} do
{:ok, _index_live, html} = live(conn, ~p"/settings/options")
test "lists all options", %{conn: conn, option: option} do
{:ok, _index_live, html} = live(conn, ~p"/settings/options")

assert html =~ "Listing Options"
assert html =~ option.name
end
assert html =~ "Listing Options"
assert html =~ option.name
end

test "saves new option", %{conn: conn} do
{:ok, index_live, _html} = live(conn, ~p"/settings/options")
test "saves new option", %{conn: conn} do
{:ok, index_live, _html} = live(conn, ~p"/settings/options")

assert index_live |> element("a", "New Option") |> render_click() =~
"New Option"
assert index_live |> element("a", "New Option") |> render_click() =~
"New Option"

assert_patch(index_live, ~p"/settings/options/new")
assert_patch(index_live, ~p"/settings/options/new")

assert index_live
|> form("#option-form", option: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"
assert index_live
|> form("#option-form", option: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"

assert index_live
|> form("#option-form", option: @create_attrs)
|> render_submit()
assert index_live
|> form("#option-form", option: @create_attrs)
|> render_submit()

assert_patch(index_live, ~p"/settings/options")
assert_patch(index_live, ~p"/settings/options")

html = render(index_live)
assert html =~ "Option created successfully"
assert html =~ "some name"
end
html = render(index_live)
assert html =~ "Option created successfully"
assert html =~ "some name"
end

test "updates option in listing", %{conn: conn, option: option} do
{:ok, index_live, _html} = live(conn, ~p"/settings/options")
test "updates option in listing", %{conn: conn, option: option} do
{:ok, index_live, _html} = live(conn, ~p"/settings/options")

assert index_live |> element("#options-#{option.id} a", "Edit") |> render_click() =~
"Edit Option"
assert index_live |> element("#options-#{option.id} a", "Edit") |> render_click() =~
"Edit Option"

assert_patch(index_live, ~p"/settings/options/#{option}/edit")
assert_patch(index_live, ~p"/settings/options/#{option}/edit")

assert index_live
|> form("#option-form", option: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"
assert index_live
|> form("#option-form", option: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"

assert index_live
|> form("#option-form", option: @update_attrs)
|> render_submit()
assert index_live
|> form("#option-form", option: @update_attrs)
|> render_submit()

assert_patch(index_live, ~p"/settings/options")
assert_patch(index_live, ~p"/settings/options")

html = render(index_live)
assert html =~ "Option updated successfully"
assert html =~ "some updated name"
end
html = render(index_live)
assert html =~ "Option updated successfully"
assert html =~ "some updated name"
end

test "deletes option in listing", %{conn: conn, option: option} do
{:ok, index_live, _html} = live(conn, ~p"/settings/options")
test "deletes option in listing", %{conn: conn, option: option} do
{:ok, index_live, _html} = live(conn, ~p"/settings/options")

assert index_live |> element("#options-#{option.id} a", "Delete") |> render_click()
refute has_element?(index_live, "#options-#{option.id}")
end
end
assert index_live |> element("#options-#{option.id} a", "Delete") |> render_click()
refute has_element?(index_live, "#options-#{option.id}")
end
end

describe "Show" do
setup [:create_option]
describe "Show" do
setup [:create_option]

test "displays option", %{conn: conn, option: option} do
{:ok, _show_live, html} = live(conn, ~p"/settings/options/#{option}")
test "displays option", %{conn: conn, option: option} do
{:ok, _show_live, html} = live(conn, ~p"/settings/options/#{option}")

assert html =~ "Show Option"
assert html =~ option.name
end
assert html =~ "Show Option"
assert html =~ option.name
end

test "updates option within modal", %{conn: conn, option: option} do
{:ok, show_live, _html} = live(conn, ~p"/settings/options/#{option}")
test "updates option within modal", %{conn: conn, option: option} do
{:ok, show_live, _html} = live(conn, ~p"/settings/options/#{option}")

assert show_live |> element("a", "Edit") |> render_click() =~
"Edit Option"
assert show_live |> element("a", "Edit") |> render_click() =~
"Edit Option"

assert_patch(show_live, ~p"/settings/options/#{option}/show/edit")
assert_patch(show_live, ~p"/settings/options/#{option}/show/edit")

assert show_live
|> form("#option-form", option: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"
assert show_live
|> form("#option-form", option: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"

assert show_live
|> form("#option-form", option: @update_attrs)
|> render_submit()
assert show_live
|> form("#option-form", option: @update_attrs)
|> render_submit()

assert_patch(show_live, ~p"/settings/options/#{option}")
assert_patch(show_live, ~p"/settings/options/#{option}")

html = render(show_live)
assert html =~ "Option updated successfully"
assert html =~ "some updated name"
end
end
html = render(show_live)
assert html =~ "Option updated successfully"
assert html =~ "some updated name"
end
end
end
Loading