/* eslint-disable cypress/no-unnecessary-waiting */
/*
 * Copyright (C) 2022 Robert Bosch GmbH Copyright (C) 2022 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved.
 */

describe('Functionality of the Loading Screen Component', () => {

  before(() => {
    cy.visit('/modals-popups/loading-screen-demo');
  });

  beforeEach(() => {
    cy.viewport(1920, 1200);
  });

  describe('Closeable Loading Screen', () => {
    it('should close loading Screen with typing on ESC-Key', () => {
      cy.get('[data-test="show-closeable-loading-screen"]').click();
      cy.get('mat-dialog-container').find("bci-loading-screen").should('exist');
      cy.get('mat-dialog-container').type('{esc}');
      cy.get('mat-dialog-container').should('not.exist');
    });
    it('should close loading Screen with clicking on Backdrop', () => {
      cy.get('[data-test="show-closeable-loading-screen"]').click();
      cy.get('mat-dialog-container').find("bci-loading-screen").should('exist');
      cy.get(".cdk-overlay-backdrop").click({ force: true });
      cy.get('mat-dialog-container').should('not.exist');
    });
    it('close Icon in the upper right corner should exist and work', () => {
      cy.get('[data-test="show-closeable-loading-screen"]').click();
      cy.get('mat-dialog-container').find("bci-loading-screen").should('exist');
      cy.get('[data-test="modal-window-close-button"]').should('be.visible');
      cy.get('[data-test="modal-window-close-button"]').click();
      cy.get('mat-dialog-container').should('not.exist');
    });
  });
  
  describe('Not closeable Loading Screen', () => {
    it('should not close loading Screen with typing on ESC-Key', () => {
      cy.get('[data-test="show-not-closeable-loading-screen"]').click();
      cy.get('mat-dialog-container').find("bci-loading-screen").should('exist');
      cy.get('mat-dialog-container').type('{esc}');
      cy.get('mat-dialog-container').should('exist').and('be.visible');
      cy.wait(10000);
    });
    it('should not close loading Screen with clicking on Backdrop', () => {
      cy.get('[data-test="show-not-closeable-loading-screen"]').click();
      cy.get('mat-dialog-container').find("bci-loading-screen").should('exist');
      cy.get(".cdk-overlay-backdrop").click({ force: true });
      cy.get('mat-dialog-container').should('exist').and('be.visible');
    });
  });
});
