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

Cypress Test Evaluation #941

Open
tomsmith8 opened this issue Jan 16, 2025 · 2 comments · May be fixed by #1001
Open

Cypress Test Evaluation #941

tomsmith8 opened this issue Jan 16, 2025 · 2 comments · May be fixed by #1001
Assignees

Comments

@tomsmith8
Copy link

Version one: Logs

describe('User Journey: Sign in and Submit Proof', () => {
  const userAlias = 'testUser';
  const proofText = 'Proof text here';

  before(() => {
    cy.setupUser();
    cy.setupWorkspace();
  });

  it('should sign in and submit proof successfully', () => {
    cy.visit('https://community.sphinx.chat/p/cs6elnatu2rsh7eq5hk0/assigned/3324/0');
    cy.get('[data-testid="close-btn"]').click();
    cy.visit('https://community.sphinx.chat/p/cs6elnatu2rsh7eq5hk0/assigned/3306/2');
    cy.visit('https://community.sphinx.chat/p/cs6elnatu2rsh7eq5hk0/assigned/3324/0');
    cy.login(userAlias);
    cy.contains('Submit Proof').click();
    cy.get('textarea[aria-label="Enter your proof"]').type(proofText);
    cy.get('button[color="primary"]').click();
    cy.contains('Proof submitted successfully').should('be.visible');
  });
});

Version two: Puppeteer

describe('User submits proof for a bounty and signs out', () => {
  const userAlias = 'john_doe';
  const expectedAlias = 'John Doe';

  before(() => {
    // Pre-setup: Ensure the environment is ready
    cy.setupTestEnvironment();
  });

  it('should allow the user to submit proof for a bounty', () => {
    // Launch browser and open bounties page
    cy.login(userAlias);
    cy.visit('https://community.sphinx.chat/bounties');

    // Close any modal if present
    cy.get('button > span').click({ force: true });

    // Select a bounty
    cy.get('div:nth-of-type(3) > div > a:nth-of-type(1) div.sc-pAKSZ > div').click();

    // Open proof submission modal
    cy.get('div.buttonSet').click();

    // Enter proof in textarea
    cy.get('textarea').click().type('Here is my proof: https://www.google.com');

    // Submit proof
    cy.get('div.base-Modal-root').contains('Submit Proof').click();

    // Close proof submission modal
    cy.get('[data-testid="close-btn"] > img').click();

    // Return to bounties page
    cy.visit('https://community.sphinx.chat/bounties');

    // Click on alias and sign out
    cy.clickAlias(expectedAlias);
    cy.logout(userAlias);
  });
});

@tomsmith8
Copy link
Author

@tobi-bams can you evaluate the following two cypress tests and try and get them to work on the tribes server.

User logs in and submits Proof of Work.

Can you provide feedback for what work was needed in order to get this to work.

Thanks!

@tobi-bams tobi-bams linked a pull request Jan 31, 2025 that will close this issue
@tobi-bams
Copy link
Collaborator

Summary
Version one: Logs

describe('User Journey: Sign in and Submit Proof', () => {
  const userAlias = 'testUser';
  const proofText = 'Proof text here';

  before(() => {
    cy.setupUser();
    cy.setupWorkspace();
  });

  it('should sign in and submit proof successfully', () => {
    cy.visit('https://community.sphinx.chat/p/cs6elnatu2rsh7eq5hk0/assigned/3324/0');
    cy.get('[data-testid="close-btn"]').click();
    cy.visit('https://community.sphinx.chat/p/cs6elnatu2rsh7eq5hk0/assigned/3306/2');
    cy.visit('https://community.sphinx.chat/p/cs6elnatu2rsh7eq5hk0/assigned/3324/0');
    cy.login(userAlias);
    cy.contains('Submit Proof').click();
    cy.get('textarea[aria-label="Enter your proof"]').type(proofText);
    cy.get('button[color="primary"]').click();
    cy.contains('Proof submitted successfully').should('be.visible');
  });
});

A working version of the test above

describe('User Journey: Sign in and Submit Proof', () => {
  const assignee = 'bob';
  const bounty: Cypress.Bounty = {
    title: `Proof of work bounty ${Date.now()}`,
    category: 'Web development',
    coding_language: ['Typescript', 'Javascript', 'Lightning'],
    description: 'We are testing Proof of Work',
    amount: '123',
    assign: assignee,
    deliverables: 'Ensure you summit a valid proof of work',
    tribe: '',
    estimate_session_length: '3 hours',
    estimate_completion_date: '09/09/2025'
  };
  const bountyCreator = 'alice';
  const proofText = 'Proof text here';

  it('should sign in and submit proof successfully', () => {
    cy.login(bountyCreator);
    cy.create_bounty(bounty);
    cy.contains('Filter').click();
    cy.contains('Assigned').click();
    cy.contains(bounty.title).click();
    cy.contains('Copy Link').click();
    cy.get('[data-testid="close-btn"]').click();
    cy.logout(bountyCreator);
    cy.login(assignee);
    cy.window()
      .then((win) => {
        return win.navigator.clipboard.readText();
      })
      .then((copiedText) => {
        cy.visit(copiedText);
        cy.contains('Submit Proof').click();
        cy.get('textarea[aria-label="Enter your proof"]').type(proofText);
        cy.get('[data-testid="submit-proof-handler"]').click();
        cy.contains('Proof of work submitted successfully').should('be.visible');
        cy.get('[data-testid="close-btn"]').click();
        cy.logout(assignee);
      });
  });
});

What was needed for the test to run:

  1. Remove the two functions below, they are not valid functions in our test suit
    cy.setupUser();
    cy.setupWorkspace();
  2. We can't access production bounties directly in our test environment, which means we have to first create the bounty then assign it to one of our test users alice, bob, carol, dave.
  3. You can't try to access a bounty then want to login, you first login then go to the bounty so you could submit proof.
  4. Selectors like the one below are not very great, because we can have a couple of it on the same page
    cy.get('button[color="primary"]').click();
  5. The command below is not the correct selector to use:
    cy.contains('Proof submitted successfully').should('be.visible');
    The correct selector is: cy.contains('Proof of work submitted successfully').should('be.visible');

@tobi-bams tobi-bams linked a pull request Jan 31, 2025 that will close this issue
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 a pull request may close this issue.

2 participants