Add Translations

mix phx.gen.live Translations Translation translations \
  lang:string title:string teaser:text content:map \
  date:utc_datetime user_id:references:users \
  public:boolean unauthorized:boolean article_id:references:articles
This commit is contained in:
Thelonius Kort
2022-12-26 18:45:40 +01:00
parent f7f1e1a284
commit f66521dba8
13 changed files with 600 additions and 0 deletions

View File

@ -0,0 +1,71 @@
defmodule Outlook.TranslationsTest do
use Outlook.DataCase
alias Outlook.Translations
describe "translations" do
alias Outlook.Translations.Translation
import Outlook.TranslationsFixtures
@invalid_attrs %{content: nil, date: nil, lang: nil, public: nil, teaser: nil, title: nil, unauthorized: nil}
test "list_translations/0 returns all translations" do
translation = translation_fixture()
assert Translations.list_translations() == [translation]
end
test "get_translation!/1 returns the translation with given id" do
translation = translation_fixture()
assert Translations.get_translation!(translation.id) == translation
end
test "create_translation/1 with valid data creates a translation" do
valid_attrs = %{content: %{}, date: ~U[2022-12-25 17:13:00Z], lang: "some lang", public: true, teaser: "some teaser", title: "some title", unauthorized: true}
assert {:ok, %Translation{} = translation} = Translations.create_translation(valid_attrs)
assert translation.content == %{}
assert translation.date == ~U[2022-12-25 17:13:00Z]
assert translation.lang == "some lang"
assert translation.public == true
assert translation.teaser == "some teaser"
assert translation.title == "some title"
assert translation.unauthorized == true
end
test "create_translation/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Translations.create_translation(@invalid_attrs)
end
test "update_translation/2 with valid data updates the translation" do
translation = translation_fixture()
update_attrs = %{content: %{}, date: ~U[2022-12-26 17:13:00Z], lang: "some updated lang", public: false, teaser: "some updated teaser", title: "some updated title", unauthorized: false}
assert {:ok, %Translation{} = translation} = Translations.update_translation(translation, update_attrs)
assert translation.content == %{}
assert translation.date == ~U[2022-12-26 17:13:00Z]
assert translation.lang == "some updated lang"
assert translation.public == false
assert translation.teaser == "some updated teaser"
assert translation.title == "some updated title"
assert translation.unauthorized == false
end
test "update_translation/2 with invalid data returns error changeset" do
translation = translation_fixture()
assert {:error, %Ecto.Changeset{}} = Translations.update_translation(translation, @invalid_attrs)
assert translation == Translations.get_translation!(translation.id)
end
test "delete_translation/1 deletes the translation" do
translation = translation_fixture()
assert {:ok, %Translation{}} = Translations.delete_translation(translation)
assert_raise Ecto.NoResultsError, fn -> Translations.get_translation!(translation.id) end
end
test "change_translation/1 returns a translation changeset" do
translation = translation_fixture()
assert %Ecto.Changeset{} = Translations.change_translation(translation)
end
end
end

View File

@ -0,0 +1,110 @@
defmodule OutlookWeb.TranslationLiveTest do
use OutlookWeb.ConnCase
import Phoenix.LiveViewTest
import Outlook.TranslationsFixtures
@create_attrs %{content: %{}, date: "2022-12-25T17:13:00Z", lang: "some lang", public: true, teaser: "some teaser", title: "some title", unauthorized: true}
@update_attrs %{content: %{}, date: "2022-12-26T17:13:00Z", lang: "some updated lang", public: false, teaser: "some updated teaser", title: "some updated title", unauthorized: false}
@invalid_attrs %{content: nil, date: nil, lang: nil, public: false, teaser: nil, title: nil, unauthorized: false}
defp create_translation(_) do
translation = translation_fixture()
%{translation: translation}
end
describe "Index" do
setup [:create_translation]
test "lists all translations", %{conn: conn, translation: translation} do
{:ok, _index_live, html} = live(conn, ~p"/translations")
assert html =~ "Listing Translations"
assert html =~ translation.lang
end
test "saves new translation", %{conn: conn} do
{:ok, index_live, _html} = live(conn, ~p"/translations")
assert index_live |> element("a", "New Translation") |> render_click() =~
"New Translation"
assert_patch(index_live, ~p"/translations/new")
assert index_live
|> form("#translation-form", translation: @invalid_attrs)
|> render_change() =~ "can't be blank"
{:ok, _, html} =
index_live
|> form("#translation-form", translation: @create_attrs)
|> render_submit()
|> follow_redirect(conn, ~p"/translations")
assert html =~ "Translation created successfully"
assert html =~ "some lang"
end
test "updates translation in listing", %{conn: conn, translation: translation} do
{:ok, index_live, _html} = live(conn, ~p"/translations")
assert index_live |> element("#translations-#{translation.id} a", "Edit") |> render_click() =~
"Edit Translation"
assert_patch(index_live, ~p"/translations/#{translation}/edit")
assert index_live
|> form("#translation-form", translation: @invalid_attrs)
|> render_change() =~ "can't be blank"
{:ok, _, html} =
index_live
|> form("#translation-form", translation: @update_attrs)
|> render_submit()
|> follow_redirect(conn, ~p"/translations")
assert html =~ "Translation updated successfully"
assert html =~ "some updated lang"
end
test "deletes translation in listing", %{conn: conn, translation: translation} do
{:ok, index_live, _html} = live(conn, ~p"/translations")
assert index_live |> element("#translations-#{translation.id} a", "Delete") |> render_click()
refute has_element?(index_live, "#translation-#{translation.id}")
end
end
describe "Show" do
setup [:create_translation]
test "displays translation", %{conn: conn, translation: translation} do
{:ok, _show_live, html} = live(conn, ~p"/translations/#{translation}")
assert html =~ "Show Translation"
assert html =~ translation.lang
end
test "updates translation within modal", %{conn: conn, translation: translation} do
{:ok, show_live, _html} = live(conn, ~p"/translations/#{translation}")
assert show_live |> element("a", "Edit") |> render_click() =~
"Edit Translation"
assert_patch(show_live, ~p"/translations/#{translation}/show/edit")
assert show_live
|> form("#translation-form", translation: @invalid_attrs)
|> render_change() =~ "can't be blank"
{:ok, _, html} =
show_live
|> form("#translation-form", translation: @update_attrs)
|> render_submit()
|> follow_redirect(conn, ~p"/translations/#{translation}")
assert html =~ "Translation updated successfully"
assert html =~ "some updated lang"
end
end
end

View File

@ -0,0 +1,26 @@
defmodule Outlook.TranslationsFixtures do
@moduledoc """
This module defines test helpers for creating
entities via the `Outlook.Translations` context.
"""
@doc """
Generate a translation.
"""
def translation_fixture(attrs \\ %{}) do
{:ok, translation} =
attrs
|> Enum.into(%{
content: %{},
date: ~U[2022-12-25 17:13:00Z],
lang: "some lang",
public: true,
teaser: "some teaser",
title: "some title",
unauthorized: true
})
|> Outlook.Translations.create_translation()
translation
end
end