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

Filter browsable FAQs by tag #23

Merged
merged 2 commits into from
Oct 10, 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
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: praekeltfoundation/flow_tester
ref: v0.3.2
ref: v0.3.3
path: flow_tester
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Check formatting
Expand Down
7 changes: 6 additions & 1 deletion Browsable FAQs/QA/flows/Browsable FAQs.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ This menu displays all the titles of the index pages that are found in the CMS,
<!-- { section: "5717187d-7351-498d-a008-73fa6b29183d", x: 0, y: 0} -->

```stack
# Here you can initialise any filter parameters that will be used to filter index pages or pages
card InitFilterParams, then: MainMenu do
gender = if is_nil_or_empty("@contact.gender"), do: "", else: "@contact.gender"
end

card MainMenu do
# Main menu displays all of the index pages for the user to select from
# TODO: replace this with URL in config once Turn has fixed the bug that changes the URL into markdown
Expand Down Expand Up @@ -74,7 +79,7 @@ card IndexMenu, then: FetchContent do
headers: [
["Authorization", "Token @global.config.contentrepo_token"]
],
query: [["child_of", "@selected_index_id"], ["whatsapp", "true"]]
query: [["child_of", "@selected_index_id"], ["whatsapp", "true"], ["tag", "@gender"]]
)

index_menu_items = map(page_list_data.body.results, &[&1.title, &1.title])
Expand Down
2 changes: 1 addition & 1 deletion Browsable FAQs/QA/flows_json/Browsable FAQs.json

Large diffs are not rendered by default.

42 changes: 40 additions & 2 deletions Browsable FAQs/QA/tests/browsable_faqs_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ defmodule BrowsableFAQsTest do
]
}

tagged_leaf_page = %ContentPage{
parent: "topic-1",
slug: "tagged-leaf-page-1",
title: "Tagged Leaf Page 1",
tags: ["female"],
wa_messages: [
%WAMsg{
message: "Test tagged leaf content page",
buttons: [%Btn.Next{title: "Next"}]
},
%WAMsg{
message: "Last message"
}
]
}

parent_page = %ContentPage{
parent: "topic-1",
slug: "parent-page-1",
Expand Down Expand Up @@ -74,6 +90,7 @@ defmodule BrowsableFAQsTest do
parent: "topic-1",
slug: "variations-page",
title: "Variations test",
tags: ["female", "male"],
wa_messages: [
%WAMsg{
message: "Default message without variations",
Expand Down Expand Up @@ -158,7 +175,8 @@ defmodule BrowsableFAQsTest do
related_page_leaf,
media_index,
image_page,
variations_page
variations_page,
tagged_leaf_page
])

assert :ok = FakeCMS.add_images(wh_pid, [image])
Expand All @@ -171,13 +189,18 @@ defmodule BrowsableFAQsTest do
defp fake_cms(step, base_url, auth_token),
do: WH.set_adapter(step, base_url, setup_fake_cms(auth_token))

defp setup_contact_fields(context) do
context |> FlowTester.set_contact_properties(%{"gender" => ""})
end

defp setup_flow() do
auth_token = "testtoken"

flow_path("Browsable FAQs")
|> FlowTester.from_json!()
|> fake_cms("https://content-repo-api-qa.prk-k8s.prd-p6t.org/", auth_token)
|> FlowTester.set_global_dict("config", %{"contentrepo_token" => auth_token})
|> setup_contact_fields()
end

describe "browsable faqs" do
Expand All @@ -204,11 +227,26 @@ defmodule BrowsableFAQsTest do
{"Parent Page 1", "Parent Page 1"},
{"Multiple Messages Leaf", "Multiple Messages Leaf"},
{"Related Page Leaf", "Related Page Leaf"},
{"Variations test", "Variations test"}
{"Variations test", "Variations test"},
{"Tagged Leaf Page 1", "Tagged Leaf Page 1"}
]}
})
end

test "show menu of children of index page filtered by tag" do
setup_flow()
|> FlowTester.set_contact_properties(%{"gender" => "female"})
|> FlowTester.start()
|> receive_message(%{})
|> FlowTester.send("Topic 1")
|> receive_message(%{
text: "Topic 1\n-----\nSelect the topic you are interested in from the list\n",
list:
{"Select topic",
[{"Variations test", "Variations test"}, {"Tagged Leaf Page 1", "Tagged Leaf Page 1"}]}
})
end

test "show message content on content page leaf" do
setup_flow()
|> FlowTester.start()
Expand Down
Loading