Skip to content

Commit

Permalink
cy-test: refatorando comando para inserir texto em dispositivo (usado…
Browse files Browse the repository at this point in the history
… em testes com Cypress)

Refs #877
  • Loading branch information
robsonbarrosdf committed Jun 26, 2024
1 parent e0d1527 commit 8d80ea9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 32 deletions.
18 changes: 3 additions & 15 deletions cypress/e2e/nova-emenda/nova-emenda-mpv-905.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Emenda para MPV 905', () => {
cy.getContainerArtigoByNumero(2).click().selecionarOpcaoDeMenuDoDispositivo('Adicionar artigo depois');

const texto = 'Texto do novo artigo.';
cy.get('div.container__elemento.dispositivo--adicionado').should('have.length', 1).inserirTextoNoDispositivo(texto).contains(texto);
cy.get('div.container__elemento.dispositivo--adicionado').should('have.length', 1).alterarTextoDoDispositivo(texto).contains(texto);
cy.checarComandoEmenda();
cy.checarTextoPresenteEmComandoEmenda(texto);
});
Expand All @@ -24,7 +24,7 @@ describe('Emenda para MPV 905', () => {
cy.checarEstadoInicialAoCriarNovaEmendaPadrao({ nomeProposicao: 'MPV 905/2019', totalElementos: 563 });

const texto = 'Novo texto do parágrafo 1º do artigo 2º.';
cy.getContainerArtigoByNumero(2).next().click().should('have.length', 1).inserirTextoNoDispositivo(texto).contains(texto);
cy.getContainerArtigoByNumero(2).next().click().should('have.length', 1).alterarTextoDoDispositivo(texto).contains(texto);
// cy.checarComandoEmenda();
cy.checarTextoPresenteEmComandoEmenda(texto);
});
Expand All @@ -37,20 +37,8 @@ describe('Emenda para MPV 905', () => {

cy.checarEstadoInicialAoCriarNovaEmendaOndeCouber({ nomeProposicao: 'MPV 905/2019', totalElementos: 2 });

// cy.get('#texto__dispositivo3').then($el => {
// // $el[0].textContent = 'AAA BBB CCC DDD EEE FFF GGG HHH';

// // cy.get('lexml-eta-editor').then($eta => {
// // const eta = $eta[0];
// // (eta as any).emitirEventoOnChange('cypress');
// // });

// const $el0 = cy.wrap($el[0]);
// $el0.type('PPP QQQ RRR SSS TTT UUU WWW XXX YYY ZZZ.', { force: true });
// });

const texto = 'Texto do artigo onde couber.';
cy.get('div.container__elemento.dispositivo--adicionado').should('have.length', 1).inserirTextoNoDispositivo(texto).contains(texto);
cy.get('div.container__elemento.dispositivo--adicionado').should('have.length', 1).alterarTextoDoDispositivo(texto).contains(texto);
cy.checarComandoEmenda();
cy.checarTextoPresenteEmComandoEmenda(texto);
});
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/revisao/revisao.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ describe('Revisão', () => {
cy.ativarRevisaoDispositivo();
cy.getSwitchRevisaoDispositivo().getContadorRevisao().as('contadorRevisaoDispositivo').contains('0');

cy.getContainerArtigoByNumero(1).click().inserirTextoNoDispositivo('Novo texto do artigo. Teste de contador.');
cy.getContainerArtigoByNumero(1).click().alterarTextoDoDispositivo('Novo texto do artigo. Teste de contador.');
cy.get('@contadorRevisaoDispositivo').contains('1');

cy.getContainerArtigoByNumero(2).next().click().inserirTextoNoDispositivo('Novo texto do § 1º do Art. 2º.');
cy.getContainerArtigoByNumero(2).next().click().alterarTextoDoDispositivo('Novo texto do § 1º do Art. 2º.');
cy.get('@contadorRevisaoDispositivo').contains('2');
});
});
58 changes: 43 additions & 15 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// <reference types="cypress" />

import { LexmlEmendaComponent } from '../../src';
import { Emenda, ModoEdicaoEmenda } from '../../src/model/emenda/emenda';
import { removeAllHtmlTags } from '../../src/util/string-util';
Expand Down Expand Up @@ -129,13 +128,7 @@ Cypress.Commands.add('focusOnConteudo', { prevSubject: 'element' }, (subject: JQ
return cy.wrap(subject);
});

Cypress.Commands.add('inserirTextoNoDispositivo', { prevSubject: 'element' }, (subject: JQuery<HTMLElement>, texto: string): Cypress.Chainable<JQuery<HTMLElement>> => {
// Obs:
// O comando "type" deveria adicionar o texto ao parágrafo.
// Tem hora que funciona, tem hora que não.
// Por isso, foi necessário usar o comando "invoke" para setar o texto.
// cy.wrap(subject).type(texto, { force: true, delay: 0 });

Cypress.Commands.add('alterarTextoDoDispositivo', { prevSubject: 'element' }, (subject: JQuery<HTMLElement>, texto: string): Cypress.Chainable<JQuery<HTMLElement>> => {
const wrapSubject = cy.wrap(subject);
wrapSubject.find('div.container__texto p.texto__dispositivo').invoke('text', texto);
wrapSubject.closest('lexml-eta-editor').then($eta => {
Expand All @@ -145,6 +138,38 @@ Cypress.Commands.add('inserirTextoNoDispositivo', { prevSubject: 'element' }, (s
return wrapSubject;
});

Cypress.Commands.add('digitarNoDispositivo', { prevSubject: 'element' }, (subject: JQuery<HTMLElement>, texto: string, replace = false): Cypress.Chainable<JQuery<HTMLElement>> => {
// cy.wrap(subject).as('containerDispositivo').find('div.container__texto p.texto__dispositivo').focus().type(texto, { force: true });
cy.wrap(subject)
.as('containerDispositivo')
.find('div.container__texto p.texto__dispositivo')
.as('pTextoDispositivo')
// .focus()
.then($p => {
replace && $p.text('');
cy.wrap($p)
.wait(Cypress.config('isInteractive') ? tempoDeEsperaPadrao : tempoDeEsperaMaior)
.type(texto, { delay: 5 });
});
return cy.get('@containerDispositivo');
});

Cypress.Commands.add('inserirTextoNaJustificacao', (texto: string): Cypress.Chainable<JQuery<HTMLElement>> => {
cy.get('#sl-tab-2').click();
cy.get('#editor-texto-rico-justificativa-inner > .ql-editor')
.as('qlJustificacao')
.should('be.visible')
.focus()
.then($el => {
cy.wrap($el).type(texto, { force: true, delay: 0 });
});
return cy.get('@qlJustificacao');
});

Cypress.Commands.add('getTextoDoDispositivo', { prevSubject: 'element' }, (subject: JQuery<HTMLElement>): Cypress.Chainable<string> => {
return cy.wrap(subject).find('div.container__texto p.texto__dispositivo').invoke('text');
});

Cypress.Commands.add('getSwitchRevisaoDispositivo', () => {
return cy.get('lexml-eta lexml-switch-revisao.revisao-container').as('switchRevisaoDispositivo');
});
Expand Down Expand Up @@ -223,11 +248,12 @@ Cypress.Commands.add('checarEstadoInicialAoCriarNovaEmendaPadrao', (payload: Che
});

Cypress.Commands.add('checarComandoEmenda', (emenda?: Emenda): void => {
cy.wait(tempoDeEsperaPadrao);
cy.get('lexml-emenda').then($lexmlEmenda => {
const emendaAux = emenda ?? ($lexmlEmenda[0] as LexmlEmendaComponent).getEmenda();
fnChecarComandoCabecalho(emendaAux);
fnChecarComandoCitacao(emendaAux);
cy.wait(tempoDeEsperaMaior).then(() => {
cy.get('lexml-emenda').then($lexmlEmenda => {
const emendaAux = emenda ?? ($lexmlEmenda[0] as LexmlEmendaComponent).getEmenda();
fnChecarComandoCabecalho(emendaAux);
fnChecarComandoCitacao(emendaAux);
});
});
});

Expand Down Expand Up @@ -397,7 +423,6 @@ const fnChecarComandoCabecalho = (emenda: any): void => {
};

const fnChecarComandoCitacao = (emenda: any): void => {
cy.wait(tempoDeEsperaMaior);
const citacao = emenda.comandoEmenda.comandos[0].citacao;
cy.get('lexml-emenda lexml-emenda-comando')
.shadow()
Expand Down Expand Up @@ -447,7 +472,10 @@ declare global {
focusOnConteudo(): Cypress.Chainable<JQuery<HTMLElement>>;
selecionarOpcaoDeMenuDoDispositivo(opcaoDeMenu: string): void;
getOpcoesDeMenuDoDispositivo(): Cypress.Chainable<JQuery<HTMLElement>>;
inserirTextoNoDispositivo(texto: string): Cypress.Chainable<JQuery<HTMLElement>>;
getTextoDoDispositivo(): Cypress.Chainable<string>;
alterarTextoDoDispositivo(texto: string): Cypress.Chainable<JQuery<HTMLElement>>;
digitarNoDispositivo(texto: string, replace?: boolean): Cypress.Chainable<JQuery<HTMLElement>>;
inserirTextoNaJustificacao(texto: string): Cypress.Chainable<JQuery<HTMLElement>>;
getSwitchRevisaoDispositivo(): Cypress.Chainable<JQuery<HTMLElement>>;
getCheckRevisao(): Cypress.Chainable<JQuery<HTMLElement>>;
getContadorRevisao(): Cypress.Chainable<JQuery<HTMLElement>>;
Expand Down

0 comments on commit 8d80ea9

Please sign in to comment.