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

homebase-app: Integrate testing suite #673

Open
EightRice opened this issue Sep 26, 2023 · 15 comments
Open

homebase-app: Integrate testing suite #673

EightRice opened this issue Sep 26, 2023 · 15 comments
Assignees

Comments

@EightRice
Copy link
Contributor

Have the tests perform on every merge / PR creation

@Man-Jain Man-Jain self-assigned this Oct 4, 2023
@magentaceiba magentaceiba assigned benefacto and unassigned Man-Jain Dec 21, 2023
@benefacto
Copy link
Member

This is a priority immediately after my onboarding.

@benefacto
Copy link
Member

benefacto commented Dec 27, 2023

Duplicate issue: #702

Integrate the tests done by the upwork team, so that as we're doing new features and fixes we run them through a testing pipeline.

@benefacto
Copy link
Member

benefacto commented Dec 27, 2023

Tests being referred to seem to be in this repository: https://github.com/W3DevTeam/TezosHomebaseTests
Below is a good example of a GitHub action that could be run (might have to be adapted for Netlify).

name: Playwright Tests
on:
  deployment_status:
jobs:
  test:
    timeout-minutes: 60
    runs-on: ubuntu-latest
    if: github.event.deployment_status.state == 'success'
    steps:
    - uses: actions/checkout@v3
    - uses: actions/setup-node@v3
      with:
        node-version: 18
    - name: Install dependencies
      run: npm ci
    - name: Install Playwright
      run: npx playwright install --with-deps
    - name: Run Playwright tests
      run: npx playwright test
      env:
        PLAYWRIGHT_TEST_BASE_URL: ${{ github.event.deployment_status.target_url }}

Playwright has good documentation to execute on this: https://playwright.dev/docs/ci-intro

@benefacto
Copy link
Member

Sadly, Netlfiy does not currently send a deployment_status event: https://answers.netlify.com/t/can-netlify-deliver-deploy-event-to-github-api-after-successful-deployment/10905

@benefacto
Copy link
Member

Current approach seems to be working but CSS class paths seem to be the cause of the current test failures (timeouts likely due to being unable to find the elements)

@benefacto
Copy link
Member

It seems like the first test is now getting stuck when it's prompted to connect a wallet when it clicks the deploy button

@benefacto
Copy link
Member

WIP pull request: #740
New tests repository (fork) to make changes to: https://github.com/dOrgTech/homebase-app-tests

@benefacto
Copy link
Member

@Man-Jain @EightRice @thenerdcat Were the tests intended to work without a wallet connection? I'm asking because it seems like a wallet was never setup for the tests and yet, when I'm debugging the first test case, it seems to be getting stuck at the wallet connection prompt:
image.png
If wallet connection needs to be added, I'm happy to do so, I just wanted to check first since adding that may be somewhat time consuming.

@benefacto benefacto changed the title Integrate testing suite homebase-app: Integrate testing suite Dec 29, 2023
@benefacto
Copy link
Member

Andrei has custom deployment preview for hardcoded wallet which can be extended

@EightRice
Copy link
Contributor Author

EightRice commented Jan 2, 2024

@benefacto This is the deploy preview with the hardcoded wallet: https://deploy-preview-629--tezos-homebase.netlify.app/

@benefacto
Copy link
Member

This pull request reconfigured the codebase to be testable: #629

@benefacto
Copy link
Member

Will actually need to use a URL parameter to handle the test mode, maybe something like this:
To maintain the test mode URL parameter across navigations in your React app, you can use one of the following approaches:

Approach 1: Higher-Order Component (HOC)

You can create a HOC that wraps your components and automatically appends the test mode parameter to any navigation links.

  1. Create the HOC:

    import React from 'react';
    import { useLocation, useNavigate } from 'react-router-dom';
    
    const withTestMode = (WrappedComponent) => {
      return (props) => {
        const location = useLocation();
        const navigate = useNavigate();
        const testMode = new URLSearchParams(location.search).get('testMode');
    
        const handleNavigation = (path) => {
          navigate(`${path}${testMode ? `?testMode=${testMode}` : ''}`);
        };
    
        return <WrappedComponent {...props} navigate={handleNavigation} />;
      };
    };
    
    export default withTestMode;
  2. Use the HOC:

    import withTestMode from './withTestMode';
    
    const MyComponent = ({ navigate }) => {
      // Use the `navigate` function passed by the HOC
      return (
        <button onClick={() => navigate('/next-page')}>Go to Next Page</button>
      );
    };
    
    export default withTestMode(MyComponent);

Approach 2: Custom Hook

Alternatively, you can create a custom hook to handle the navigation logic with the test mode parameter.

  1. Create the Custom Hook:

    import { useLocation, useNavigate } from 'react-router-dom';
    
    const useTestModeNavigation = () => {
      const location = useLocation();
      const navigate = useNavigate();
      const testMode = new URLSearchParams(location.search).get('testMode');
    
      const navigateWithTestMode = (path) => {
        navigate(`${path}${testMode ? `?testMode=${testMode}` : ''}`);
      };
    
      return navigateWithTestMode;
    };
    
    export default useTestModeNavigation;
  2. Use the Custom Hook:

    import useTestModeNavigation from './useTestModeNavigation';
    
    const MyComponent = () => {
      const navigateWithTestMode = useTestModeNavigation();
    
      return (
        <button onClick={() => navigateWithTestMode('/next-page')}>Go to Next Page</button>
      );
    };
    
    export default MyComponent;

In both approaches, the test mode parameter is preserved in the URL during navigation. This helps maintain a consistent application state based on the URL parameter, ensuring that the test mode remains active across different views and user interactions. Choose the approach that best fits your application architecture and coding style.

@benefacto
Copy link
Member

Need access to LaunchDarkly as that's the feature flag system that's already setup:

import { useFlags } from "launchdarkly-react-client-sdk"

@benefacto
Copy link
Member

Magenta now has access and can grant me it

@benefacto
Copy link
Member

benefacto commented Jan 18, 2024

What's remaining on this one is to setup a feature flag (LaunchDarkly) such that when it is passed, the app is considered to be in test mode (using the test wallet rather than the connected one), then this URL should be used by the GitHub action for testing purposes (possible that you might need a wait for Netlify action: https://github.com/JakePartusch/wait-for-netlify-action); possible that tests may need tweaks to use the latest UI

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

No branches or pull requests

4 participants