<%#
 Copyright 2013-2026 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      https://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
<%_ if (clientTestFrameworkVitest) { _%>
import { afterEach, beforeEach, describe, expect, it, vitest } from 'vitest';
<%_ } _%>
import { ComponentRef } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
<%_ if (enableTranslation) { _%>
import { TranslateModule } from '@ngx-translate/core';
<%_ } _%>

import ItemCount from './item-count';

describe('ItemCount test', () => {
  let comp: ItemCount;
  let compRef: ComponentRef<ItemCount>;
  let fixture: ComponentFixture<ItemCount>;
  const inputParams = 'params';

  beforeEach(
    () => {
      TestBed.configureTestingModule({
<%_ if (enableTranslation) { _%>
        imports: [
          TranslateModule.forRoot(),
        ],
<%_ } _%>
      });
    }
  );

  beforeEach(() => {
    fixture = TestBed.createComponent(ItemCount);
    comp = fixture.componentInstance;
    compRef = fixture.componentRef;
  });

  describe('UI logic tests', () => {
    it('should initialize with undefined', () => {
      expect(comp.first()).toBeUndefined();
      expect(comp.second()).toBeUndefined();
      expect(comp.total()).toBeUndefined();
    });

    it('should set calculated numbers to undefined if the page value is not yet defined', () => {
      // GIVEN
      compRef.setInput(inputParams, { page: undefined, totalItems: 0, itemsPerPage: 10 });

      // THEN
      expect(comp.first()).toBeUndefined();
      expect(comp.second()).toBeUndefined();
    });

    it('should change the content on page change', () => {
      // GIVEN
      compRef.setInput(inputParams, { page: 1, totalItems: 100, itemsPerPage: 10 });

      // THEN
      expect(comp.first()).toBe(1);
      expect(comp.second()).toBe(10);
      expect(comp.total()).toBe(100);

      // GIVEN
      compRef.setInput(inputParams, { page: 2, totalItems: 100, itemsPerPage: 10 });

      // THEN
      expect(comp.first()).toBe(11);
      expect(comp.second()).toBe(20);
      expect(comp.total()).toBe(100);
    });

    it('should set the second number to totalItems if this is the last page which contains less than itemsPerPage items', () => {
      // GIVEN
      compRef.setInput(inputParams, { page: 2, totalItems: 16, itemsPerPage: 10 });

      // THEN
      expect(comp.first()).toBe(11);
      expect(comp.second()).toBe(16);
      expect(comp.total()).toBe(16);
    });
  });
});
