Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
automatically add segments for fill steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Ceolin committed Aug 4, 2024
1 parent d4a4cee commit d20f371
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/content/content_context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,24 @@ defmodule Zoonk.Content do
lesson_step |> change_lesson_step(attrs) |> Repo.update()
end

@doc """
Updates a lesson step kind.
## Examples
iex> update_lesson_step_kind(%LessonStep{}, "fill")
{:ok, %LessonStep{}}
"""
@spec update_lesson_step_kind(LessonStep.t(), String.t()) :: lesson_step_changeset()
def update_lesson_step_kind(%LessonStep{} = lesson_step, "fill") do
segments = [dgettext("orgs", "This is a"), nil, dgettext("orgs", "step.")]
lesson_step |> change_lesson_step(%{kind: :fill, segments: segments}) |> Repo.update()
end

def update_lesson_step_kind(%LessonStep{} = lesson_step, kind) do
lesson_step |> change_lesson_step(%{kind: kind}) |> Repo.update()
end

@doc """
Deletes a lesson step.
Expand Down
6 changes: 6 additions & 0 deletions lib/dashboard/lessons/lesson_editor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ defmodule ZoonkWeb.Live.Dashboard.LessonEditor do
icon: "tabler-writing",
title: dgettext("orgs", "Open-ended"),
description: dgettext("orgs", "Users can write their own answer.")
},
%{
kind: :fill,
icon: "tabler-forms",
title: dgettext("orgs", "Fill in the blank"),
description: dgettext("orgs", "Users can fill in the blank space in a sentence.")
}
]
end
Expand Down
15 changes: 15 additions & 0 deletions test/content/content_context_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,21 @@ defmodule Zoonk.ContentTest do
end
end

describe "update_lesson_step_kind/2" do
test "updates the kind of a lesson step" do
lesson_step = lesson_step_fixture(%{kind: :readonly})
assert {:ok, %LessonStep{} = updated} = Content.update_lesson_step_kind(lesson_step, "quiz")
assert updated.kind == :quiz
end

test "automatically adds segments for fill kind" do
lesson_step = lesson_step_fixture(%{kind: :readonly})
assert {:ok, %LessonStep{} = updated} = Content.update_lesson_step_kind(lesson_step, "fill")
assert updated.kind == :fill
assert updated.segments == ["This is a", nil, "step."]
end
end

describe "delete_lesson_step/1" do
test "deletes a lesson step" do
lesson = lesson_fixture()
Expand Down
13 changes: 13 additions & 0 deletions test/dashboard/lesson_editor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,19 @@ defmodule ZoonkWeb.DashboardLessonEditorLiveTest do
assert Content.get_lesson_step_by_order(lesson.id, 1).kind == :open_ended
end

test "updates a step to a fill kind", %{conn: conn, course: course} do
lesson = lesson_fixture(%{course_id: course.id})
lesson_step_fixture(%{lesson_id: lesson.id, kind: :readonly, order: 1})

assert Content.get_lesson_step_by_order(lesson.id, 1).segments == nil

{:ok, lv, _html} = live(conn, ~p"/dashboard/c/#{course.slug}/l/#{lesson.id}/s/1")

lv |> element("button", "Fill in the blank") |> render_click()

assert Content.get_lesson_step_by_order(lesson.id, 1).kind == :fill
end

test "embeds youtube video", %{conn: conn, course: course} do
lesson = lesson_fixture(%{course_id: course.id})
lesson_step_fixture(%{lesson_id: lesson.id, order: 2, content: "watch video: https://www.youtube.com/watch?v=12345678901"})
Expand Down

0 comments on commit d20f371

Please sign in to comment.