<commit_before>/* tslint:disable:no-unused-variable */

import {TestBed, fakeAsync, getTestBed, tick} from '@angular/core/testing';
import {APP_BASE_HREF} from '@angular/common';
import {RouterTestingModule} from '@angular/router/testing';
import {ApplicationWorkflowComponent} from './application.workflow.component';
import {ApplicationModule} from '../../application.module';
import {SharedModule} from '../../../../shared/shared.module';
import {ApplicationWorkflowService} from '../../../../service/application/application.workflow.service';
import {Injector} from '@angular/core';
import {TranslateService, TranslateLoader, TranslateParser} from 'ng2-translate';
import {Project} from '../../../../model/project.model';
import {Application, ApplicationFilter} from '../../../../model/application.model';
import {XHRBackend} from '@angular/http';
import {MockBackend} from '@angular/http/testing';
import {Observable} from 'rxjs/Rx';
import {WorkflowItem, WorkflowStatusResponse} from '../../../../model/application.workflow.model';
import {PipelineBuild, Pipeline} from '../../../../model/pipeline.model';
import {Environment} from '../../../../model/environment.model';
import {Scheduler, SchedulerExecution} from '../../../../model/scheduler.model';
import {HttpClientTestingModule} from '@angular/common/http/testing';

describe('CDS: Application Workflow', () => {

    let injector: Injector;
    let backend: MockBackend;

    beforeEach(() => {
        TestBed.configureTestingModule({
            declarations: [
            ],
            providers: [
                MockBackend,
                { provide: APP_BASE_HREF, useValue: '/' },
                { provide: XHRBackend, useClass: MockBackend },
                ApplicationWorkflowService,
                TranslateService,
                TranslateLoader,
                TranslateParser
            ],
            imports : [
                ApplicationModule,
                RouterTestingModule.withRoutes([]),
                SharedModule,
                HttpClientTestingModule
            ]
        });

        injector = getTestBed();
        backend = injector.get(MockBackend);
    });

    afterEach(() => {
        injector = undefined;
        backend = undefined;
    });

    it('should load component', fakeAsync( () => {
        // Create component
        let fixture = TestBed.createComponent(ApplicationWorkflowComponent);
        let component = fixture.debugElement.componentInstance;
        expect(component).toBeTruthy();

        // Init Input Data
        let p: Project = new Project();
        p.key = 'key1';
        p.name = 'projectName';

        let a: Application = new Application();
        a.name = 'appName';

        let appFilter: ApplicationFilter = { branch: 'foo', version: '1', remote: 'barremote' };

        fixture.componentInstance.project = p;
        fixture.componentInstance.application = a;
        fixture.componentInstance.applicationFilter = appFilter;

        // Create spy
        let workflowService: ApplicationWorkflowService = injector.get(ApplicationWorkflowService);
        spyOn(workflowService, 'getRemotes').and.callFake(() => {
            return Observable.of([{ 'name' : 'barremote', url: 'https://github.com/barremote/barremote.git' }]);
        });
        spyOn(workflowService, 'getBranches').and.callFake(() => {
            return Observable.of([{ 'display_id' : 'branche1', default: true}, { 'display_id' : 'branche2'}, { 'display_id' : 'master'},
                { 'display_id' : 'branche3' }]);
        });
        spyOn(workflowService, 'getVersions').and.callFake(() => {
            return Observable.of([1, 2, 3]);
        });

        // Run component initialisation
        fixture.componentInstance.ngOnInit();

        // Check
        expect(fixture.componentInstance.applicationFilter.branch).toBe('foo');
        expect(JSON.stringify(fixture.componentInstance.versions)).toBe(JSON.stringify([' ', '1', '2', '3']));
        expect(JSON.stringify(fixture.componentInstance.remotes)).toBe(JSON.stringify([{
            'name' : 'barremote',
            url: 'https://github.com/barremote/barremote.git'<commit_msg>fix (ui) : ut with git remotes (#1334)<commit_after>/* tslint:disable:no-unused-variable */

import {TestBed, fakeAsync, getTestBed, tick} from '@angular/core/testing';
import {APP_BASE_HREF} from '@angular/common';
import {RouterTestingModule} from '@angular/router/testing';
import {ApplicationWorkflowComponent} from './application.workflow.component';
import {ApplicationModule} from '../../application.module';
import {SharedModule} from '../../../../shared/shared.module';
import {ApplicationWorkflowService} from '../../../../service/application/application.workflow.service';
import {Injector} from '@angular/core';
import {TranslateService, TranslateLoader, TranslateParser} from 'ng2-translate';
import {Project} from '../../../../model/project.model';
import {Application, ApplicationFilter} from '../../../../model/application.model';
import {XHRBackend} from '@angular/http';
import {MockBackend} from '@angular/http/testing';
import {Observable} from 'rxjs/Rx';
import {WorkflowItem, WorkflowStatusResponse} from '../../../../model/application.workflow.model';
import {PipelineBuild, Pipeline} from '../../../../model/pipeline.model';
import {Environment} from '../../../../model/environment.model';
import {Scheduler, SchedulerExecution} from '../../../../model/scheduler.model';
import {HttpClientTestingModule} from '@angular/common/http/testing';

describe('CDS: Application Workflow', () => {

    let injector: Injector;
    let backend: MockBackend;

    beforeEach(() => {
        TestBed.configureTestingModule({
            declarations: [
            ],
            providers: [
                MockBackend,
                { provide: APP_BASE_HREF, useValue: '/' },
                { provide: XHRBackend, useClass: MockBackend },
                ApplicationWorkflowService,
                TranslateService,
                TranslateLoader,
                TranslateParser
            ],
            imports : [
                ApplicationModule,
                RouterTestingModule.withRoutes([]),
                SharedModule,
                HttpClientTestingModule
            ]
        });

        injector = getTestBed();
        backend = injector.get(MockBackend);
    });

    afterEach(() => {
        injector = undefined;
        backend = undefined;
    });

    it('should load component', fakeAsync( () => {
        // Create component
        let fixture = TestBed.createComponent(ApplicationWorkflowComponent);
        let component = fixture.debugElement.componentInstance;
        expect(component).toBeTruthy();

        // Init Input Data
        let p: Project = new Project();
        p.key = 'key1';
        p.name = 'projectName';

        let a: Application = new Application();
        a.repository_fullname = 'repoFullName';
        a.name = 'appName';

        let appFilter: ApplicationFilter = { branch: '', version: '1', remote: 'barremote' };

        fixture.componentInstance.project = p;
        fixture.componentInstance.application = a;
        fixture.componentInstance.applicationFilter = appFilter;

        // Create spy
        let workflowService: ApplicationWorkflowService = injector.get(ApplicationWorkflowService);
        spyOn(workflowService, 'getRemotes').and.callFake(() => {
            return Observable.of([{ 'name' : 'barremote', url: 'https://github.com/barremote/barremote.git' }]);
        });
        spyOn(workflowService, 'getBranches').and.callFake(() => {
            return Observable.of([{ 'display_id' : 'branche1', default: true}, { 'display_id' : 'branche2'}, { 'display_id' : 'master'},
                { 'display_id' : 'branche3' }]);
        });
        spyOn(workflowService, 'getVersions').and.callFake(() => {
            return Observable.of([1, 2, 3]);
        });

        // Run component initialisation
        fixture.componentInstance.ngOnInit();

        // Check
        expect(fixture.componentInstance.applicationFilter.branch).toBe('branche1');
        expect(JSON.stringify(fixture.componentInstance.versions)).toBe(JSON.stringify([' ', '1', '2', '3']));
        expect(JSON.stringify(fixture.componentInstance.remotes)).toBe(JSON.stringify([{
            'name' : 'barremote',
            url: 'https://github.com/barremote/barremote.git'
{'fraction_non_alphanumeric': 0.15210432720806163, 'fraction_numerical': 0.0034380557202133965, 'mean_word_length': 2.6742160278745644, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 4, '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': '2773321', 'n_tokens_mistral': 2231, 'n_tokens_neox': 2212, 'n_words': 450}