diff --git a/network-api/networkapi/management/commands/load_fake_data.py b/network-api/networkapi/management/commands/load_fake_data.py index 45e6400007a..a2f6f56ad69 100644 --- a/network-api/networkapi/management/commands/load_fake_data.py +++ b/network-api/networkapi/management/commands/load_fake_data.py @@ -11,6 +11,7 @@ import networkapi.donate.factory as donate_factory import networkapi.highlights.factory as highlights_factory import networkapi.mozfest.factory as mozfest_factory +import networkapi.nav.factories as nav_factory import networkapi.news.factory as news_factory import networkapi.wagtailpages.factory as wagtailpages_factory from networkapi.utility.faker.helpers import reseed @@ -89,6 +90,7 @@ def handle(self, *args, **options): wagtailpages_factory, mozfest_factory, donate_factory, + nav_factory, ] ] diff --git a/network-api/networkapi/nav/factories.py b/network-api/networkapi/nav/factories.py index 9dfcd32c33e..8189329d26c 100644 --- a/network-api/networkapi/nav/factories.py +++ b/network-api/networkapi/nav/factories.py @@ -7,7 +7,9 @@ from networkapi.nav import blocks as nav_blocks from networkapi.nav import models as nav_models +from networkapi.utility.faker.helpers import get_homepage, reseed from networkapi.wagtailcustomization.factories.blocks import ExtendedStructBlockFactory +from networkapi.wagtailpages.models import BlogPageTopic class NavItemFactory(ExtendedStructBlockFactory): @@ -265,3 +267,381 @@ class Meta: locale = factory.LazyFunction(lambda: wagtail_models.Locale.get_default()) menu = factory.SubFactory("networkapi.nav.factories.NavMenuFactory") topic = factory.SubFactory("networkapi.wagtailpages.factory.blog.BlogPageTopicFactory") + + +# Build "Who We Are" dropdown +def generate_first_dropdown(seed): + reseed(seed) + # Create prerequisite data + # Set dropdown title + title = "Who We Are" + # Create a test page for linking purposes only + page_a1 = wagtail_factories.PageFactory(parent=get_homepage(), title="Test 1st dropdown page") + + # Create Overview section for dropdown + overview = wagtail_factories.ListBlockFactory( + NavOverviewFactory, + **{ + "0__title": "About Us", + "0__description": RichText( + ( + "Mozilla is a global nonprofit dedicated to keeping the Internet" + " a public resource that is open and accessible to all." + ) + ), + }, + ) + + # Build out nav items (columns) + # Column 1 nav items + nav_items_0 = wagtail_factories.ListBlockFactory( + NavItemFactory, + **{ + "0__link_to": "page", + "0__page": page_a1, + "0__description": "", + "1__external_url_link": True, + "1__external_url": "https://mozilla.org/", + "1__description": "", + }, + ) + # Column 2 nav items + nav_items_1 = wagtail_factories.ListBlockFactory( + NavItemFactory, + **{ + "0__external_url_link": True, + "0__description": "", + "0__external_url": "https://mozilla.org/", + "1__external_url_link": True, + "1__external_url": "https://mozilla.org/", + "1__description": "", + }, + ) + # Build out columns + columns = wagtail_factories.ListBlockFactory( + NavColumnFactory, + **{ + "0__title": "Approach", + "0__nav_items": nav_items_0, + "0__button": wagtail_factories.ListBlockFactory(NavButtonFactory, **{}), + "1__title": "Legal", + "1__nav_items": nav_items_1, + "1__button": wagtail_factories.ListBlockFactory(NavButtonFactory, **{}), + }, + ) + # Build button + button = factory.SubFactory( + NavButtonFactory, link_to="relative_url", relative_url="/who-we-are/", label="Learn More" + ) + + # Generate dropdown + dropdown = NavDropdownFactory( + title=title, + overview=overview, + columns=columns, + button=button, + ) + + return dropdown + + +# Build "What We Do" dropdown +def generate_second_dropdown(seed): + reseed(seed) + # Create prerequisite data + # Set dropdown title + title = "What We Do" + + # Build out nav items (columns) + # Column 1 nav items + nav_items_0 = wagtail_factories.ListBlockFactory( + NavItemFactory, + **{ + "0__relative_url_link": True, + "0__relative_url": "/", + "1__relative_url_link": True, + "1__relative_url": "/", + "2__relative_url_link": True, + "2__relative_url": "/", + }, + ) + # Column 2 nav items + nav_items_1 = wagtail_factories.ListBlockFactory( + NavItemFactory, + **{ + "0__relative_url_link": True, + "0__relative_url": "/", + "0__description": "", + "1__relative_url_link": True, + "1__relative_url": "/", + "2__relative_url_link": True, + "2__relative_url": "/", + }, + ) + # Column 3 nav items + nav_items_2 = wagtail_factories.ListBlockFactory( + NavItemFactory, + **{ + "0__relative_url_link": True, + "0__relative_url": "/", + "1__relative_url_link": True, + "1__relative_url": "/", + }, + ) + # Column 4 nav items + nav_items_3 = wagtail_factories.ListBlockFactory( + NavItemFactory, + **{ + "0__relative_url_link": True, + "0__relative_url": "/", + "1__relative_url_link": True, + "1__relative_url": "/", + }, + ) + + # Build out columns + columns = wagtail_factories.ListBlockFactory( + NavColumnFactory, + **{ + "0__title": "Connect People", + "0__nav_items": nav_items_0, + "0__button": wagtail_factories.ListBlockFactory(NavButtonFactory, **{}), + "1__title": "Rally Communities", + "1__nav_items": nav_items_1, + "1__button": wagtail_factories.ListBlockFactory(NavButtonFactory, **{}), + "2__title": "Influence Policies", + "2__nav_items": nav_items_2, + "2__button": wagtail_factories.ListBlockFactory(NavButtonFactory, **{}), + "3__title": "Research & Analysis", + "3__nav_items": nav_items_3, + "3__button": wagtail_factories.ListBlockFactory(NavButtonFactory, **{}), + }, + ) + + # Build button + button = factory.SubFactory( + NavButtonFactory, link_to="relative_url", relative_url="/", label="Learn more about what we do" + ) + + # Generate dropdown + dropdown = NavDropdownFactory( + title=title, + columns=columns, + button=button, + ) + + return dropdown + + +# Build "What You Can Do" dropdown +def generate_third_dropdown(seed): + reseed(seed) + # Create prerequisite data + # Set dropdown title + title = "What You Can Do" + # Create a test page for linking purposes only + page_a2 = wagtail_factories.PageFactory(parent=get_homepage(), title="Test 3rd dropdown page") + + # Create Overview section for dropdown + overview = wagtail_factories.ListBlockFactory( + NavOverviewFactory, + **{ + "0__title": "Get Involved", + "0__description": RichText( + ( + "From donating funds or data, to signing a petition, to applying to become a " + "volunteer or fellow there are many ways to get involved with the community." + ) + ), + }, + ) + + # Build out nav items (columns) + # Column 1 nav items + nav_items_0 = wagtail_factories.ListBlockFactory( + NavItemFactory, + **{ + "0__relative_url_link": True, + "0__relative_url": "/", + "0__description": "", + "1__relative_url_link": True, + "1__relative_url": "/", + "2__relative_url_link": True, + "2__relative_url": "/", + }, + ) + # Column 2 nav items + nav_items_1 = wagtail_factories.ListBlockFactory( + NavItemFactory, + **{ + "0__relative_url_link": True, + "0__relative_url": "/", + "0__description": "", + "1__relative_url_link": True, + "1__relative_url": "/", + "2__relative_url_link": True, + "2__relative_url": "/", + }, + ) + + # Build out columns + columns = wagtail_factories.ListBlockFactory( + NavColumnFactory, + **{ + "0__title": "Act", + "0__nav_items": nav_items_0, + "0__button": wagtail_factories.ListBlockFactory(NavButtonFactory, **{}), + "1__title": "Learn", + "1__nav_items": nav_items_1, + "1__button": wagtail_factories.ListBlockFactory(NavButtonFactory, **{}), + }, + ) + + # Build featured nav items + featured_nav_items = wagtail_factories.ListBlockFactory( + NavItemFactory, + **{ + "0__label": "Make a Donation", + "0__relative_url_link": True, + "0__relative_url": "/", + "0__description": "", + "1__label": "Ways to Give", + "1__relative_url_link": True, + "1__relative_url": "/", + "1__description": "", + }, + ) + + # Build featured column + featured_column = wagtail_factories.ListBlockFactory( + NavFeaturedColumnFactory, + **{ + "0__title": "Donate", + "0__nav_items": featured_nav_items, + }, + ) + + # Build button + button = factory.SubFactory(NavButtonFactory, link_to="page", page=page_a2, label="Learn More") + + # Generate dropdown + dropdown = NavDropdownFactory( + title=title, + overview=overview, + columns=columns, + featured_column=featured_column, + button=button, + ) + + return dropdown + + +# Build "What We Fund" dropdown +def generate_fourth_dropdown(seed): + reseed(seed) + # Create prerequisite data + # Set dropdown title + title = "What We Fund" + # Create a test page for linking purposes only + page_a2 = wagtail_factories.PageFactory(parent=get_homepage(), title="Test 4th dropdown page") + + # Create Overview section for dropdown + overview = wagtail_factories.ListBlockFactory( + NavOverviewFactory, + **{ + "0__title": "Apply for Funding", + "0__description": RichText( + ( + "The Mozilla Foundation provides funding and resources to individuals," + " groups, and organizations aligned with creating a more human-centered internet." + ) + ), + }, + ) + + # Build out nav items (columns) + # Column 1 nav items + nav_items_0 = wagtail_factories.ListBlockFactory( + NavItemFactory, + **{ + "0__relative_url_link": True, + "0__relative_url": "/", + "1__relative_url_link": True, + "1__relative_url": "/", + }, + ) + # Column 2 nav items + nav_items_1 = wagtail_factories.ListBlockFactory( + NavItemFactory, + **{ + "0__relative_url_link": True, + "0__relative_url": "/", + "1__relative_url_link": True, + "1__relative_url": "/", + }, + ) + + # Build out columns + columns = wagtail_factories.ListBlockFactory( + NavColumnFactory, + **{ + "0__title": "Opportunities", + "0__nav_items": nav_items_0, + "0__button": wagtail_factories.ListBlockFactory(NavButtonFactory, **{}), + "1__title": "Community Impact", + "1__nav_items": nav_items_1, + "1__button": wagtail_factories.ListBlockFactory(NavButtonFactory, **{}), + }, + ) + + # Build button + button = factory.SubFactory(NavButtonFactory, link_to="page", page=page_a2, label="Learn More") + + # Generate dropdown + dropdown = NavDropdownFactory( + title=title, + overview=overview, + columns=columns, + button=button, + ) + + return dropdown + + +# Generate the Nav Menu +def generate(seed): + reseed(seed) + + try: + menu = nav_models.NavMenu.objects.get() + print("Main Navigation exists") + except nav_models.NavMenu.DoesNotExist: + print("Generating Main Navigation") + + dropdown_0 = generate_first_dropdown(seed) + dropdown_1 = generate_second_dropdown(seed) + dropdown_2 = generate_third_dropdown(seed) + dropdown_3 = generate_fourth_dropdown(seed) + + # Build menu + menu = NavMenuFactory( + dropdowns__0__dropdown=dropdown_0, + dropdowns__1__dropdown=dropdown_1, + dropdowns__2__dropdown=dropdown_2, + dropdowns__3__dropdown=dropdown_3, + enable_blog_dropdown=True, + blog_button_label="See all blog posts", + ) + + print("Linking blog topics to New Main Navigation") + # Get existing topics and create relationships + topics = BlogPageTopic.objects.all()[:5] + for topic in topics: + NavMenuFeaturedBlogTopicRelationshipFactory(menu=menu, topic=topic) + + # Activate menu + print("Activating New Main Navigation") + site = wagtail_models.Site.objects.first() + site_active_nav = nav_models.SiteNavMenu.for_site(site) + site_active_nav.active_nav_menu = menu + site_active_nav.save() diff --git a/tests/integration/navigation/001-site-nav.spec.js b/tests/integration/navigation/001-site-nav.spec.js index c7b9cb224a4..05409ac03fc 100644 --- a/tests/integration/navigation/001-site-nav.spec.js +++ b/tests/integration/navigation/001-site-nav.spec.js @@ -26,11 +26,6 @@ test.describe("Main site primary nav", () => { await navToggleButton.click(); await expect(nav).toBeInViewport(); - // check if the active link is the current page - const activeLink = nav.locator(".nav-links a.active"); - expect(await activeLink.count()).toBe(1); - expect(await activeLink.getAttribute("href")).toBe(PAGE_URL); - // check if clicking the nav button again hides the nav await navToggleButton.click(); await expect(nav).not.toBeInViewport();