import {
  beforeEach,
  describe,
  it,
} from '@bigtest/mocha';
import { expect } from 'chai';

import setupApplication from '../helpers/setup-application';
import OpenLoansInteractor from '../interactors/open-loans';

describe('Change due date', () => {
  setupApplication({
    permissions: {
      'circulation.loans.collection.get': true,
    },
  });

  describe('test change due date overlay', () => {
    const requestsAmount = 2;

    beforeEach(async function () {
      const loan = this.server.create('loan', { status: { name: 'Open' }, item: { status: {} } });

      this.server.createList('request', requestsAmount, { itemId: loan.itemId });
      this.visit(`/users/${loan.userId}/loans/open`);
      await OpenLoansInteractor.whenLoaded();
    });

    it('should be presented', () => {
      expect(OpenLoansInteractor.isPresent).to.be.true;
    });

    describe('action dropdown', () => {
      it('icon button should be presented', () => {
        expect(OpenLoansInteractor.actionDropdowns(0).isPresent).to.be.true;
      });

      describe('action dropdown click', () => {
        beforeEach(async () => {
          await OpenLoansInteractor.actionDropdowns(0).click('button');
        });

        it('change due date button should be presented', () => {
          expect(OpenLoansInteractor.actionDropdownChangeDueDateButton.isPresent).to.be.true;
        });

        describe.skip('click change due date button', () => {
          beforeEach(async () => {
            await OpenLoansInteractor.actionDropdownChangeDueDateButton.click();
          });

          describe('change due date overlay', () => {
            it('should be presented', () => {
              expect(OpenLoansInteractor.changeDueDateOverlay.isPresent).to.be.true;
            });

            it('requests count equals', () => {
              expect(OpenLoansInteractor.changeDueDateOverlay.requestsCount.text).to.equal(requestsAmount.toString());
            });

            it('save button is presented and disabled', () => {
              expect(OpenLoansInteractor.changeDueDateOverlay.saveButton.isPresent).to.be.true;
              expect(OpenLoansInteractor.changeDueDateOverlay.isSaveButtonDisabled).to.be.true;
            });

            it('control due date calendar button is presented', () => {
              expect(OpenLoansInteractor.changeDueDateOverlay.dueDateCalendarButton.isPresent).to.be.true;
            });

            it('cancel button is presented', () => {
              expect(OpenLoansInteractor.changeDueDateOverlay.dueDateCalendarButton.isPresent).to.be.true;
            });

            describe('change due date', () => {
              beforeEach(async () => {
                await OpenLoansInteractor.changeDueDateOverlay.dueDateCalendarButton.click();
                await OpenLoansInteractor.dueDateCalendarCellButton.click();
              });

              it('save button is enabled after changes in form', () => {
                expect(OpenLoansInteractor.changeDueDateOverlay.isSaveButtonDisabled).to.be.false;
              });
            });

            describe('cancel due date change', () => {
              beforeEach(async () => {
                await OpenLoansInteractor.changeDueDateOverlay.cancelButton.click();
              });

              it('change due date overlay is hidden after click on cancel button', () => {
                expect(OpenLoansInteractor.changeDueDateOverlay.isPresent).to.be.false;
              });
            });
          });
        });
      });
    });
  });
});

@@ -1401,13 +1401,8 @@
 ribe
-.skip
 ('cl

Work with tests