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

import setupApplication from '../helpers/setup-application';
import LoanActionsHistory from '../interactors/loan-actions-history';

import translations from '../../../translations/ui-users/en.json';

describe.only('loans actions history', () => {
  setupApplication({ permissions: {
    'manualblocks.collection.get': true,
    'circulation.loans.collection.get': true,
  } });

  const requestsAmount = 2;

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

    this.server.createList('request', requestsAmount, { itemId: loan.itemId });
    this.visit(`/users/view/${user.id}?layer=loan&loan=${loan.id}&query=%20%20&sort=name`);
  });

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

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

    it('should have proper value', () => {
      expect(LoanActionsHistory.requests.value.text).to.equal(requestsAmount.toString());
    });

    it('should have proper label', () => {
      expect(LoanActionsHistory.requests.label.text).to.equal(translations['loans.details.requestQueue']);
    });
  });
});

@@ -279,13 +279,8 @@
 s/en
-.json
 ';%0A%0A
@@ -1379,16 +1379,551 @@
 %0A    %7D);
+%0A%0A    describe('loan without loanPolicy', () =%3E %7B%0A      beforeEach(async function () %7B%0A        const user = this.server.create('user');%0A        const loan = this.server.create('loan', %7B status: %7B name: 'Open' %7D %7D);%0A%0A        this.server.createList('request', requestsAmount, %7B itemId: loan.itemId %7D);%0A        this.visit(%60/users/view/$%7Buser.id%7D?layer=loan&loan=$%7Bloan.id%7D&query=%2520%2520&sort=name%60);%0A      %7D);%0A%0A      it('should not be presented', () =%3E %7B%0A        expect(LoanActionsHistory.requests.isPresent).to.be.false;%0A      %7D);%0A    %7D);
 %0A  %7D);%0A%7D

Add more tests.