Cypress.on('uncaught:exception', (error) => {
  if (String(error?.message || '').includes('$(...).pointer is not a function')) {
    return false;
  }

  return undefined;
});

Cypress.Commands.add('loginToWordPress', () => {
  const username = Cypress.env('wpUser');
  const password = Cypress.env('wpPassword');

  cy.session([username, password], () => {
    cy.visit('/wp-login.php', { timeout: 60000, failOnStatusCode: false });
    cy.get('form#loginform', { timeout: 60000 }).should('be.visible');
    cy.get('#user_login', { timeout: 60000 }).clear().type(username);
    cy.get('#user_pass', { timeout: 60000 }).clear().type(password, { log: false });
    cy.get('#wp-submit', { timeout: 60000 }).click();
    cy.url().should('include', '/wp-admin/');
  });
});

Cypress.Commands.add('openLabelEditor', () => {
  cy.loginToWordPress();
  cy.visit(Cypress.env('labelEditorPath'), { timeout: 60000 });
  cy.get('[data-testid="label-editor-shell"]', { timeout: 30000 }).should('be.visible');
});
