<commit_before>import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { WalletBalanceTokensComponent } from './balance.component';
import { TokenPipe } from '../../../../common/pipes/token.pipe';
import { TooltipComponentMock } from '../../../../mocks/common/components/tooltip/tooltip.component';
import { clientMock } from '../../../../../tests/client-mock.spec';
import { Client } from '../../../../services/api/client';
import { Web3WalletService } from '../../../blockchain/web3-wallet.service';
import { TokenContractService } from '../../../blockchain/contracts/token-contract.service';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';

describe('WalletBalanceTokensComponent', () => {

  let comp: WalletBalanceTokensComponent;
  let fixture: ComponentFixture<WalletBalanceTokensComponent>;

  function getAddress(i: number): DebugElement {
    return fixture.debugElement.query(By.css(`.m-wallet--balance--addresses .m-wallet--balance--addresses-address:nth-child(${i})`));
  }

  function getAddressLabel(i: number): DebugElement {
    return fixture.debugElement.query(By.css(`.m-wallet--balance--addresses .m-wallet--balance--addresses-address:nth-child(${i}) .m-wallet--balance--addresses-address-label span`));
  }

  function getAddressAddress(i: number): DebugElement {
    return fixture.debugElement.query(By.css(`.m-wallet--balance--addresses .m-wallet--balance--addresses-address:nth-child(${i}) span.m-wallet--balance--addresses-address-address`));
  }

  function getAddressBalance(i: number): DebugElement {
    return fixture.debugElement.query(By.css(`.m-wallet--balance--addresses .m-wallet--balance--addresses-address:nth-child(${i}) .m-wallet--balance--addresses-address-col span.m-wallet--balance--addresses-address-balance`));
  }

  const Web3WalletServiceMock = new function () {
    this.getCurrentWallet = jasmine.createSpy('getCurrentWallet').and.callFake(async () => {
      return '0xONCHAIN';
    });
  }

  const TokenContractServiceMock = new function () {
    this.balanceOf = jasmine.createSpy('balanceOf').and.callFake(async () => {
      return 30000000;
    });
  }

  beforeEach(async(() => {

    TestBed.configureTestingModule({
      declarations: [
        TokenPipe,
        TooltipComponentMock,
        WalletBalanceTokensComponent
      ],
      providers: [
        { provide: Client, useValue: clientMock },
        { provide: Web3WalletService, useValue: Web3WalletServiceMock },
        { provide: TokenContractService, useValue: TokenContractServiceMock },
      ]
    })
      .compileComponents();  // compile template and css
  }));

  // synchronous beforeEach
  beforeEach((done) => {
    jasmine.MAX_PRETTY_PRINT_DEPTH = 10;
    jasmine.clock().uninstall();
    jasmine.clock().install();
    fixture = TestBed.createComponent(WalletBalanceTokensComponent);

    comp = fixture.componentInstance; // WalletBalanceTokensComponent test instance
    clientMock.response = {};
    clientMock.response[`api/v2/blockchain/wallet/balance`] = {
      'status': 'success',
      'balance': 301529,
      'addresses': [
        {
          'label': 'Receiver',
          'address': '0xreceiver',
          'balance': 9000000000000000000,
        },
        {
          'label': 'OffChain',
          'address': '0xoffchain',<commit_msg>(fix): failing test<commit_after>import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { WalletBalanceTokensComponent } from './balance.component';
import { TokenPipe } from '../../../../common/pipes/token.pipe';
import { TooltipComponentMock } from '../../../../mocks/common/components/tooltip/tooltip.component';
import { clientMock } from '../../../../../tests/client-mock.spec';
import { Client } from '../../../../services/api/client';
import { Web3WalletService } from '../../../blockchain/web3-wallet.service';
import { TokenContractService } from '../../../blockchain/contracts/token-contract.service';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { Session } from '../../../../services/session';
import { sessionMock } from '../../../../../tests/session-mock.spec';

describe('WalletBalanceTokensComponent', () => {

  let comp: WalletBalanceTokensComponent;
  let fixture: ComponentFixture<WalletBalanceTokensComponent>;

  function getAddress(i: number): DebugElement {
    return fixture.debugElement.query(By.css(`.m-wallet--balance--addresses .m-wallet--balance--addresses-address:nth-child(${i})`));
  }

  function getAddressLabel(i: number): DebugElement {
    return fixture.debugElement.query(By.css(`.m-wallet--balance--addresses .m-wallet--balance--addresses-address:nth-child(${i}) .m-wallet--balance--addresses-address-label span`));
  }

  function getAddressAddress(i: number): DebugElement {
    return fixture.debugElement.query(By.css(`.m-wallet--balance--addresses .m-wallet--balance--addresses-address:nth-child(${i}) span.m-wallet--balance--addresses-address-address`));
  }

  function getAddressBalance(i: number): DebugElement {
    return fixture.debugElement.query(By.css(`.m-wallet--balance--addresses .m-wallet--balance--addresses-address:nth-child(${i}) .m-wallet--balance--addresses-address-col span.m-wallet--balance--addresses-address-balance`));
  }

  const Web3WalletServiceMock = new function () {
    this.getCurrentWallet = jasmine.createSpy('getCurrentWallet').and.callFake(async () => {
      return '0xONCHAIN';
    });
  }

  const TokenContractServiceMock = new function () {
    this.balanceOf = jasmine.createSpy('balanceOf').and.callFake(async () => {
      return 30000000;
    });
  }

  beforeEach(async(() => {

    TestBed.configureTestingModule({
      declarations: [
        TokenPipe,
        TooltipComponentMock,
        WalletBalanceTokensComponent
      ],
      providers: [
        { provide: Client, useValue: clientMock },
        { provide: Web3WalletService, useValue: Web3WalletServiceMock },
        { provide: TokenContractService, useValue: TokenContractServiceMock },
        { provide: Session, useValue: sessionMock }
      ]
    })
      .compileComponents();  // compile template and css
  }));

  // synchronous beforeEach
  beforeEach((done) => {
    jasmine.MAX_PRETTY_PRINT_DEPTH = 10;
    jasmine.clock().uninstall();
    jasmine.clock().install();
    fixture = TestBed.createComponent(WalletBalanceTokensComponent);

    comp = fixture.componentInstance; // WalletBalanceTokensComponent test instance
    clientMock.response = {};
    clientMock.response[`api/v2/blockchain/wallet/balance`] = {
      'status': 'success',
      'balance': 301529,
      'addresses': [
        {
          'label': 'Receiver',
          'address': '0xreceiver',
          'balance': 9000000000000000000,
        },
        {
          'label': 'OffChain',
          'address': '0xoffchain',
{'fraction_non_alphanumeric': 0.16396526772793055, 'fraction_numerical': 0.012735166425470333, 'mean_word_length': 3.3907242693773822, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2142648', 'n_tokens_mistral': 2047, 'n_tokens_neox': 2046, 'n_words': 319}