initial shift template migration & schema working with user field/assoc for default shift template
This commit is contained in:
parent
61db634c36
commit
a151bfcee7
16 changed files with 665 additions and 4 deletions
test
78
test/shift73k/shift_templates_test.exs
Normal file
78
test/shift73k/shift_templates_test.exs
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
defmodule Shift73k.ShiftTemplatesTest do
|
||||
use Shift73k.DataCase
|
||||
|
||||
alias Shift73k.ShiftTemplates
|
||||
|
||||
describe "shift_templates" do
|
||||
alias Shift73k.ShiftTemplates.ShiftTemplate
|
||||
|
||||
@valid_attrs %{description: "some description", label: "some label", length_hours: 42, length_minutes: 42, location: "some location", start_time: ~T[14:00:00], subject: "some subject", timezone: "some timezone"}
|
||||
@update_attrs %{description: "some updated description", label: "some updated label", length_hours: 43, length_minutes: 43, location: "some updated location", start_time: ~T[15:01:01], subject: "some updated subject", timezone: "some updated timezone"}
|
||||
@invalid_attrs %{description: nil, label: nil, length_hours: nil, length_minutes: nil, location: nil, start_time: nil, subject: nil, timezone: nil}
|
||||
|
||||
def shift_template_fixture(attrs \\ %{}) do
|
||||
{:ok, shift_template} =
|
||||
attrs
|
||||
|> Enum.into(@valid_attrs)
|
||||
|> ShiftTemplates.create_shift_template()
|
||||
|
||||
shift_template
|
||||
end
|
||||
|
||||
test "list_shift_templates/0 returns all shift_templates" do
|
||||
shift_template = shift_template_fixture()
|
||||
assert ShiftTemplates.list_shift_templates() == [shift_template]
|
||||
end
|
||||
|
||||
test "get_shift_template!/1 returns the shift_template with given id" do
|
||||
shift_template = shift_template_fixture()
|
||||
assert ShiftTemplates.get_shift_template!(shift_template.id) == shift_template
|
||||
end
|
||||
|
||||
test "create_shift_template/1 with valid data creates a shift_template" do
|
||||
assert {:ok, %ShiftTemplate{} = shift_template} = ShiftTemplates.create_shift_template(@valid_attrs)
|
||||
assert shift_template.description == "some description"
|
||||
assert shift_template.label == "some label"
|
||||
assert shift_template.length_hours == 42
|
||||
assert shift_template.length_minutes == 42
|
||||
assert shift_template.location == "some location"
|
||||
assert shift_template.start_time == ~T[14:00:00]
|
||||
assert shift_template.subject == "some subject"
|
||||
assert shift_template.timezone == "some timezone"
|
||||
end
|
||||
|
||||
test "create_shift_template/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = ShiftTemplates.create_shift_template(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_shift_template/2 with valid data updates the shift_template" do
|
||||
shift_template = shift_template_fixture()
|
||||
assert {:ok, %ShiftTemplate{} = shift_template} = ShiftTemplates.update_shift_template(shift_template, @update_attrs)
|
||||
assert shift_template.description == "some updated description"
|
||||
assert shift_template.label == "some updated label"
|
||||
assert shift_template.length_hours == 43
|
||||
assert shift_template.length_minutes == 43
|
||||
assert shift_template.location == "some updated location"
|
||||
assert shift_template.start_time == ~T[15:01:01]
|
||||
assert shift_template.subject == "some updated subject"
|
||||
assert shift_template.timezone == "some updated timezone"
|
||||
end
|
||||
|
||||
test "update_shift_template/2 with invalid data returns error changeset" do
|
||||
shift_template = shift_template_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = ShiftTemplates.update_shift_template(shift_template, @invalid_attrs)
|
||||
assert shift_template == ShiftTemplates.get_shift_template!(shift_template.id)
|
||||
end
|
||||
|
||||
test "delete_shift_template/1 deletes the shift_template" do
|
||||
shift_template = shift_template_fixture()
|
||||
assert {:ok, %ShiftTemplate{}} = ShiftTemplates.delete_shift_template(shift_template)
|
||||
assert_raise Ecto.NoResultsError, fn -> ShiftTemplates.get_shift_template!(shift_template.id) end
|
||||
end
|
||||
|
||||
test "change_shift_template/1 returns a shift_template changeset" do
|
||||
shift_template = shift_template_fixture()
|
||||
assert %Ecto.Changeset{} = ShiftTemplates.change_shift_template(shift_template)
|
||||
end
|
||||
end
|
||||
end
|
||||
116
test/shift73k_web/live/shift_template_live_test.exs
Normal file
116
test/shift73k_web/live/shift_template_live_test.exs
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
defmodule Shift73kWeb.ShiftTemplateLiveTest do
|
||||
use Shift73kWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
|
||||
alias Shift73k.ShiftTemplates
|
||||
|
||||
@create_attrs %{description: "some description", label: "some label", length_hours: 42, length_minutes: 42, location: "some location", start_time: ~T[14:00:00], subject: "some subject", timezone: "some timezone"}
|
||||
@update_attrs %{description: "some updated description", label: "some updated label", length_hours: 43, length_minutes: 43, location: "some updated location", start_time: ~T[15:01:01], subject: "some updated subject", timezone: "some updated timezone"}
|
||||
@invalid_attrs %{description: nil, label: nil, length_hours: nil, length_minutes: nil, location: nil, start_time: nil, subject: nil, timezone: nil}
|
||||
|
||||
defp fixture(:shift_template) do
|
||||
{:ok, shift_template} = ShiftTemplates.create_shift_template(@create_attrs)
|
||||
shift_template
|
||||
end
|
||||
|
||||
defp create_shift_template(_) do
|
||||
shift_template = fixture(:shift_template)
|
||||
%{shift_template: shift_template}
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
setup [:create_shift_template]
|
||||
|
||||
test "lists all shift_templates", %{conn: conn, shift_template: shift_template} do
|
||||
{:ok, _index_live, html} = live(conn, Routes.shift_template_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Listing Shift templates"
|
||||
assert html =~ shift_template.description
|
||||
end
|
||||
|
||||
test "saves new shift_template", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.shift_template_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", "New Shift template") |> render_click() =~
|
||||
"New Shift template"
|
||||
|
||||
assert_patch(index_live, Routes.shift_template_index_path(conn, :new))
|
||||
|
||||
assert index_live
|
||||
|> form("#shift_template-form", shift_template: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
{:ok, _, html} =
|
||||
index_live
|
||||
|> form("#shift_template-form", shift_template: @create_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.shift_template_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Shift template created successfully"
|
||||
assert html =~ "some description"
|
||||
end
|
||||
|
||||
test "updates shift_template in listing", %{conn: conn, shift_template: shift_template} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.shift_template_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("#shift_template-#{shift_template.id} a", "Edit") |> render_click() =~
|
||||
"Edit Shift template"
|
||||
|
||||
assert_patch(index_live, Routes.shift_template_index_path(conn, :edit, shift_template))
|
||||
|
||||
assert index_live
|
||||
|> form("#shift_template-form", shift_template: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
{:ok, _, html} =
|
||||
index_live
|
||||
|> form("#shift_template-form", shift_template: @update_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.shift_template_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Shift template updated successfully"
|
||||
assert html =~ "some updated description"
|
||||
end
|
||||
|
||||
test "deletes shift_template in listing", %{conn: conn, shift_template: shift_template} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.shift_template_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("#shift_template-#{shift_template.id} a", "Delete") |> render_click()
|
||||
refute has_element?(index_live, "#shift_template-#{shift_template.id}")
|
||||
end
|
||||
end
|
||||
|
||||
describe "Show" do
|
||||
setup [:create_shift_template]
|
||||
|
||||
test "displays shift_template", %{conn: conn, shift_template: shift_template} do
|
||||
{:ok, _show_live, html} = live(conn, Routes.shift_template_show_path(conn, :show, shift_template))
|
||||
|
||||
assert html =~ "Show Shift template"
|
||||
assert html =~ shift_template.description
|
||||
end
|
||||
|
||||
test "updates shift_template within modal", %{conn: conn, shift_template: shift_template} do
|
||||
{:ok, show_live, _html} = live(conn, Routes.shift_template_show_path(conn, :show, shift_template))
|
||||
|
||||
assert show_live |> element("a", "Edit") |> render_click() =~
|
||||
"Edit Shift template"
|
||||
|
||||
assert_patch(show_live, Routes.shift_template_show_path(conn, :edit, shift_template))
|
||||
|
||||
assert show_live
|
||||
|> form("#shift_template-form", shift_template: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
{:ok, _, html} =
|
||||
show_live
|
||||
|> form("#shift_template-form", shift_template: @update_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.shift_template_show_path(conn, :show, shift_template))
|
||||
|
||||
assert html =~ "Shift template updated successfully"
|
||||
assert html =~ "some updated description"
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue