<commit_before>import { inject, TestBed, async } from '@angular/core/testing';
import { Http, BaseRequestOptions } from '@angular/http';
import { MockBackend } from '@angular/http/testing';
import { Events } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import { TilesApi } from './tilesApi.service';
import { MqttClient } from './mqttClient';
import { BleService } from './ble.service';
import { DevicesService }from './devices.service';
import { UtilsService }from './utils.service';
import { StorageMock } from '../mocks';
import { BLE } from 'ionic-native';
import { Observable } from 'rxjs';

import * as bleReturnValue from '../fixtures/bleDevice.json';
import * as virtualTile from '../fixtures/virtualTIle.json';
import * as testDevice from '../fixtures/tilesDevice.json';

describe('bleService', () => {

  let bleService: BleService = null;

  beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [
        Events,
        {
          provide: Storage,
          useClass: StorageMock
        },
        MockBackend,
        BaseRequestOptions,
        {
          provide : Http,
          useFactory: (backendInstance: MockBackend, defaultOptions: BaseRequestOptions) => {
            return new Http(backendInstance, defaultOptions);
          },
          deps: [MockBackend, BaseRequestOptions],
        },
        DevicesService,
        UtilsService,
        TilesApi,
        MqttClient,
        BleService,
        BLE,
      ],
    });
  });

  beforeEach(inject([BleService], (temp: BleService) => {
    bleService = temp;
  }));

  afterEach(() => {
    bleService = null;
  });

  it('should create an instance of the BleService', () => {
    expect(bleService).toBeTruthy;
  });

  describe('scanForDevices(virtualTiles: VirtualTile[]): void', () => {
    it('should check if BLE is enabled, scan for BLE-devices and have the tilesApi convert and store them', () => {
      spyOn(bleService, 'scanBLE').and.returnValue(Observable.of(bleReturnValue));
      bleService.scanForDevices([virtualTile]);
      expect(bleService['scanBLE']).toHaveBeenCalled;
    });
  });

  describe('scanBLE(virtualTiles: VirtualTile[]): void', () => {
    it('should scan for BLE-devices and have the tilesApi convert and store them', () => {
      spyOn(BLE, 'scan').and.returnValue(Observable.of(bleReturnValue));
      bleService.scanBLE([virtualTile]);
      expect(BLE['scan']).toHaveBeenCalled;
    });
  });

  describe('connect(device: Device): void', () => {
    it('should connect successfully to a device after being called with a Device argument', () => {
      spyOn(BLE, 'connect').and.returnValue(Observable.of(bleReturnValue));
      bleService.connect(testDevice);
      expect(BLE['connect']).toHaveBeenCalled;
    });
  });

  describe('startDeviceNotification(device: Device): void', () => {

  });

  describe('disconnect(device: Device): void', () => {

  });

  describe('sendData(device: Device, dataString: string): void', () => {

  });

});<commit_msg>added more test to the missing describes in ble.service.spec<commit_after>import { inject, TestBed, async } from '@angular/core/testing';
import { Http, BaseRequestOptions } from '@angular/http';
import { MockBackend } from '@angular/http/testing';
import { Events } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import { TilesApi } from './tilesApi.service';
import { MqttClient } from './mqttClient';
import { BleService } from './ble.service';
import { DevicesService }from './devices.service';
import { UtilsService }from './utils.service';
import { StorageMock } from '../mocks';
import { BLE } from 'ionic-native';
import { Observable } from 'rxjs';

import * as bleReturnValue from '../fixtures/bleDevice.json';
import * as virtualTile from '../fixtures/virtualTIle.json';
import * as testDevice from '../fixtures/tilesDevice.json';

describe('bleService', () => {

  let bleService: BleService = null;

  beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [
        Events,
        {
          provide: Storage,
          useClass: StorageMock
        },
        MockBackend,
        BaseRequestOptions,
        {
          provide : Http,
          useFactory: (backendInstance: MockBackend, defaultOptions: BaseRequestOptions) => {
            return new Http(backendInstance, defaultOptions);
          },
          deps: [MockBackend, BaseRequestOptions],
        },
        DevicesService,
        UtilsService,
        TilesApi,
        MqttClient,
        BleService,
        BLE,
      ],
    });
  });

  beforeEach(inject([BleService], (temp: BleService) => {
    bleService = temp;
  }));

  afterEach(() => {
    bleService = null;
  });

  it('should create an instance of the BleService', () => {
    expect(bleService).toBeTruthy;
  });

  describe('scanForDevices(virtualTiles: VirtualTile[]): void', () => {
    it('should check if BLE is enabled, scan for BLE-devices and have the tilesApi convert and store them', () => {
      spyOn(bleService, 'scanBLE').and.returnValue(Observable.of(bleReturnValue));
      bleService.scanForDevices([virtualTile]);
      expect(bleService['scanBLE']).toHaveBeenCalled;
    });
  });

  describe('scanBLE(virtualTiles: VirtualTile[]): void', () => {
    it('should scan for BLE-devices and have the tilesApi convert and store them', () => {
      spyOn(BLE, 'scan').and.returnValue(Observable.of(bleReturnValue));
      bleService.scanBLE([virtualTile]);
      expect(BLE['scan']).toHaveBeenCalled;
    });
  });

  describe('connect(device: Device): void', () => {
    it('should connect successfully to a device after being called with a Device argument', () => {
      spyOn(BLE, 'connect').and.returnValue(Observable.of(bleReturnValue));
      bleService.connect(testDevice);
      expect(BLE['connect']).toHaveBeenCalled;
    });
  });

  describe('startDeviceNotification(device: Device): void', () => {
    it('should get notifications of events from a deivce', () => {
      spyOn(BLE, 'startNotification').and.returnValue(Observable.of(bleReturnValue));
      bleService.startDeviceNotification(testDevice);
      expect(BLE['startNotification']).toHaveBeenCalled;
    });
  });

  describe('disconnect(device: Device): void', () => {
    it('should disconnect from the current device if it is paired', () => {
      spyOn(bleService, 'disconnect').and.returnValue(Observable.of(bleReturnValue));
      bleService.disconnect(testDevice);
      expect(bleService['disconnect']).toHaveBeenCalled;
    });
  });

  describe('sendData(device: Device, dataString: string): void', () => {
    it('should successfully send a dataString to a device using BLE', () => {
      spyOn(bleService, 'sendData').and.returnValue(Observable.of(bleReturnValue));
      bleService.sendData(testDevice, 'Hello!');
      expect(bleService['sendData']).toHaveBeenCalled;
    });

    it('should not be able to send data that is not of the type string', () => {
      spyOn(bleService, 'sendData').and.returnValue(Observable.of(bleReturnValue));
      bleService.sendData(testDevice, 2345);
      expect(bleService['sendData']).not.toHaveBeenCalled;
    })
  });

});
{'fraction_non_alphanumeric': 0.15113525560663044, 'fraction_numerical': 0.0005571806658308956, 'mean_word_length': 3.5043914680050188, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '1355851', 'n_tokens_mistral': 2105, 'n_tokens_neox': 2060, 'n_words': 458}