diff --git a/src/apps/dashboard/migrations/0005_set_applet_grid_defaults.py b/src/apps/dashboard/migrations/0005_set_applet_grid_defaults.py index d44085a..7144235 100644 --- a/src/apps/dashboard/migrations/0005_set_applet_grid_defaults.py +++ b/src/apps/dashboard/migrations/0005_set_applet_grid_defaults.py @@ -4,6 +4,8 @@ from django.db import migrations def set_grid_defaults(apps, schema_editor): Applet = apps.get_model("dashboard", "Applet") Applet.objects.filter(slug__in=["username", "palette"]).update(grid_cols=6, grid_rows=3) + Applet.objects.get_or_create(slug="new-list", defaults={"name": "New List", "grid_cols": 9, "grid_rows": 3}) + Applet.objects.get_or_create(slug="my-lists", defaults={"name": "My Lists", "grid_cols": 3, "grid_rows": 3}) class Migration(migrations.Migration): dependencies = [ diff --git a/src/apps/dashboard/tests/integrated/test_views.py b/src/apps/dashboard/tests/integrated/test_views.py index 3a06d7e..10f500e 100644 --- a/src/apps/dashboard/tests/integrated/test_views.py +++ b/src/apps/dashboard/tests/integrated/test_views.py @@ -14,6 +14,11 @@ from apps.lyric.models import User class HomePageTest(TestCase): + def setUp(self): + self.user = User.objects.create(email="disco@test.io") + self.client.force_login(self.user) + Applet.objects.get_or_create(slug="new-list", defaults={"name": "New List"}) + def test_uses_home_template(self): response = self.client.get('/') self.assertTemplateUsed(response, 'apps/dashboard/home.html') @@ -28,8 +33,12 @@ class HomePageTest(TestCase): self.assertIn("text", [input.get("name") for input in inputs]) class NewListTest(TestCase): + def setUp(self): + user = User.objects.create(email="disco@test.io") + self.client.force_login(user) + def test_can_save_a_POST_request(self): - self. client.post("/dashboard/new_list", data={"text": "A new list item"}) + self.client.post("/dashboard/new_list", data={"text": "A new list item"}) self.assertEqual(Item.objects.count(), 1) new_item = Item.objects.get() self.assertEqual(new_item.text, "A new list item") diff --git a/src/apps/dashboard/views.py b/src/apps/dashboard/views.py index df72639..17c1e91 100644 --- a/src/apps/dashboard/views.py +++ b/src/apps/dashboard/views.py @@ -8,6 +8,7 @@ from apps.dashboard.models import Applet, Item, List, UserApplet from apps.lyric.models import User +APPLET_ORDER = ["new-list", "my-lists", "username", "palette"] UNLOCKED_PALETTES = frozenset(["palette-default"]) PALETTES = [ {"name": "palette-default", "label": "Earthman", "locked": False}, @@ -18,9 +19,11 @@ PALETTES = [ def _applet_context(user): ua_map = {ua.applet_id: ua.visible for ua in user.user_applets.all()} + applets = {a.slug: a for a in Applet.objects.all()} return [ - {"applet": applet, "visible": ua_map.get(applet.pk, applet.default_visible)} - for applet in Applet.objects.all() + {"applet": applets[slug], "visible": ua_map.get(applets[slug].pk, applets[slug].default_visible)} + for slug in APPLET_ORDER + if slug in applets ] def home_page(request): @@ -39,7 +42,10 @@ def new_list(request): form.save(for_list=nulist) return redirect(nulist) else: - return render(request, "apps/dashboard/home.html", {"form": form}) + context = {"form": form, "palettes": PALETTES, "page_class": "page-dashboard"} + if request.user.is_authenticated: + context["applets"] = _applet_context(request.user) + return render(request, "apps/dashboard/home.html", context) def view_list(request, list_id): our_list = List.objects.get(id=list_id) @@ -109,5 +115,6 @@ def toggle_applets(request): return render(request, "apps/dashboard/_partials/_applets.html", { "applets": _applet_context(request.user), "palettes": PALETTES, + "form": ItemForm(), }) return redirect("home") diff --git a/src/functional_tests/base.py b/src/functional_tests/base.py index 2658a2c..c979bc1 100644 --- a/src/functional_tests/base.py +++ b/src/functional_tests/base.py @@ -12,6 +12,7 @@ from selenium.webdriver.common.keys import Keys from .container_commands import create_session_on_server, reset_database from .management.commands.create_session import create_pre_authenticated_session +from apps.dashboard.models import Applet @@ -44,6 +45,7 @@ class FunctionalTest(StaticLiveServerTestCase): if self.test_server: self.live_server_url = 'http://' + self.test_server reset_database(self.test_server) + Applet.objects.get_or_create(slug="new-list", defaults={"name": "New List"}) def tearDown(self): if self._test_has_failed(): diff --git a/src/functional_tests/test_layout_and_styling.py b/src/functional_tests/test_layout_and_styling.py index 3f0546f..50bf92b 100644 --- a/src/functional_tests/test_layout_and_styling.py +++ b/src/functional_tests/test_layout_and_styling.py @@ -7,6 +7,7 @@ from .list_page import ListPage class LayoutAndStylingTest(FunctionalTest): def test_layout_and_styling(self): + self.create_pre_authenticated_session("disco@test.io") self.browser.get(self.live_server_url) list_page = ListPage(self) diff --git a/src/functional_tests/test_list_item_validation.py b/src/functional_tests/test_list_item_validation.py index 296b7a6..97ad5c6 100644 --- a/src/functional_tests/test_list_item_validation.py +++ b/src/functional_tests/test_list_item_validation.py @@ -12,6 +12,7 @@ class ItemValidationTest(FunctionalTest): # Test methods def test_cannot_add_empty_list_items(self): + self.create_pre_authenticated_session("disco@test.io") self.browser.get(self.live_server_url) list_page = ListPage(self) list_page.get_item_input_box().send_keys(Keys.ENTER) @@ -46,6 +47,7 @@ class ItemValidationTest(FunctionalTest): list_page.wait_for_row_in_list_table("Make tea", 2) def test_cannot_add_duplicate_items(self): + self.create_pre_authenticated_session("disco@test.io") self.browser.get(self.live_server_url) list_page = ListPage(self) list_page.add_list_item("Witness divinity") @@ -61,6 +63,7 @@ class ItemValidationTest(FunctionalTest): ) def test_error_messages_are_cleared_on_input(self): + self.create_pre_authenticated_session("disco@test.io") self.browser.get(self.live_server_url) list_page = ListPage(self) list_page.add_list_item("Gobbledygook") diff --git a/src/functional_tests/test_simple_list_creation.py b/src/functional_tests/test_simple_list_creation.py index 5a0b66a..845e40c 100644 --- a/src/functional_tests/test_simple_list_creation.py +++ b/src/functional_tests/test_simple_list_creation.py @@ -8,6 +8,7 @@ from .list_page import ListPage class NewVisitorTest(FunctionalTest): # Test methods def test_can_start_a_todo_list(self): + self.create_pre_authenticated_session("alice@test.io") self.browser.get(self.live_server_url) list_page = ListPage(self) @@ -29,6 +30,7 @@ class NewVisitorTest(FunctionalTest): list_page.wait_for_row_in_list_table("Buy peacock feathers", 1) def test_multiple_users_can_start_lists_at_different_urls(self): + self.create_pre_authenticated_session("alice@test.io") self.browser.get(self.live_server_url) list_page = ListPage(self) list_page.add_list_item("Buy peacock feathers") @@ -41,6 +43,7 @@ class NewVisitorTest(FunctionalTest): self.browser.delete_all_cookies() + self.create_pre_authenticated_session("disco@test.io") self.browser.get(self.live_server_url) list_page = ListPage(self) page_text = self.browser.find_element(By.TAG_NAME, 'body').text diff --git a/src/templates/apps/dashboard/_partials/_applets.html b/src/templates/apps/dashboard/_partials/_applets.html index 65d7e51..b1c0e6e 100644 --- a/src/templates/apps/dashboard/_partials/_applets.html +++ b/src/templates/apps/dashboard/_partials/_applets.html @@ -24,7 +24,32 @@ {% for entry in applets %} {% if entry.visible %} - {% if entry.applet.slug == "username" %} + {% if entry.applet.slug == "new-list" %} +
+

Start a new to-do list

+ {% url "new_list" as form_action %} + {% include "apps/dashboard/_partials/_form.html" with form=form form_action=form_action %} +
+ {% elif entry.applet.slug == "my-lists" %} +
+ {% for list in user.lists.all %} +
  • + {{ list.name }} +
  • + {% endfor %} + {% for list in user.shared_lists.all %} +
  • + {{ list.name }} +
  • + {% endfor %} +
    + {% elif entry.applet.slug == "username" %}