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

feat: Programmatically determine when links should open in new tabs #1100

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

meissadia
Copy link
Contributor

@meissadia meissadia commented Dec 20, 2024

Closes #1071

Changes

  • New hook useIsNewTabImplied that determines when links should open in new tabs
  • Update test utilities:
    • Rename to clarify their intent (openLink, openLinkNewTab)
    • New helpers (expectLinkOpensSameTab, expectLinkOpensNewTab)
  • Add E2E tests to verify link targets on each page
    • Unauthenticated homepage
    • Complete your user profile
    • Authenticated landing page
    • View your user profile
    • View your financial institution profile
    • Updated your financial institution profile
    • Filing home for each filing step
      • Start filing
      • Resolve syntax errors
      • Resolve logic errors
      • Review warnings
      • Provide filing details
      • Sign and Submit
    • Filing homepage for each step of the Filing process
      • Provide type of financial institution
      • Upload file
      • Resolve syntax errors
      • Resolve logic errors
      • Review warnings
      • Provide filing details
      • Sign and submit

Follow-up ticket?

I did a refactor of E2E tests to address my concerns about:

  • Code duplication
  • Improve reusability of selectors for common page elements
  • Create reusable test functions for common patterns

However there is still inconsistency in

  • Naming of tests (i.e. test("Verify link targets", ...))
  • Where the verifications are implemented (some in separate files, some squished in to existing files)
  • Grouping of tests

It is probably easiest to identify where/how to make these improvements here in the same PR. At the same time, I feel like the tests we have implemented do a solid job of verifying the functionality and would identify any breaking changes, so are probably "good enough as-is".

@meissadia meissadia force-pushed the when-to-open-links-in-new-tab branch from b96809e to e2c6403 Compare December 30, 2024 19:43
@meissadia meissadia enabled auto-merge (squash) January 7, 2025 20:21
Copy link
Contributor

@billhimmelsbach billhimmelsbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work here @meissadia! Code looks good, I just added a few minor comments. Once Natalia gives her approval, we're good to go.

src/components/Link.utils.tsx Show resolved Hide resolved
};

/**
* Tests - Verify the state of the Filing homepage at each stage of the Filing process
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very thorough @meissadia and I super appreciate checking out all these card links!

Could you do me a favor, and while we're here, can we confirm the heading text on the card for these different states? Good way of confirming you're in the state you're expecting for each of these cards, and I'd be great to have some coverage on that.

Screenshot 2025-01-14 at 9 51 59 AM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validations added: commit

import { expectedPaperworkReductionActUrl } from '../../../utils/testFixture.utils';
import { SelectorLinkText, selectLink } from '../../../utils/verifyLinkTargets';

test('Unauthenticated homepage: Paperwork Reduction Act', async ({ page }) => {
await test.step('Verify on the Paperwork Reduction Act and link exists', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice little update here.

NIT: Could we change the title to this to begin with "Verify link" or something just so I can run all these tests as a batch when I search for them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title updated.

@@ -46,7 +48,54 @@ export function IconExternalLink(): ReactElement {
);
}

export function isNewTabImplied(href: string | undefined): boolean {
// Determine if the the target href should open in a new tab
export function useIsNewTabImplied(href: string | undefined): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Could you do me another favor here and just add like a 2 line comment explaining why we're doing it this way for our future selves? Something like, determines if a link should be opened in a new tab based on design team's rules to avoid bespoke logic per link?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update when links open in new tab
2 participants