|
| 1 | +import { Component, Input, Output, EventEmitter, OnInit, ViewChild } from '@angular/core'; |
| 2 | +import { BasePopupComponent } from '../../../../elements/modals/basePopup.component'; |
| 3 | +import { Test } from '../../../../shared/models/test'; |
| 4 | +import { SimpleRequester } from '../../../../services/simple-requester'; |
| 5 | +import { TestSuite } from '../../../../shared/models/testSuite'; |
| 6 | +import { TableFilterComponent } from '../../../../elements/table/table.filter.component'; |
| 7 | +import { TestSuiteService } from '../../../../services/testSuite.service'; |
| 8 | + |
| 9 | +@Component({ |
| 10 | + selector: 'sync-suite-modal', |
| 11 | + templateUrl: 'sync-suite-modal.component.html', |
| 12 | + styleUrls: ['sync-suite-modal.component.css'], |
| 13 | + providers: [ |
| 14 | + SimpleRequester |
| 15 | + ] |
| 16 | +}) |
| 17 | +export class SyncSuiteModalComponent extends BasePopupComponent implements OnInit { |
| 18 | + title = 'Sync suite'; |
| 19 | + @Input() type = 'info'; |
| 20 | + @Input() buttons = [{ name: 'Sync', execute: true }, { name: 'Cancel', execute: false }]; |
| 21 | + @Input() suites: TestSuite[]; |
| 22 | + @Input() suite: TestSuite; |
| 23 | + @Output() testSyncTo = new EventEmitter(); |
| 24 | + @ViewChild(TableFilterComponent) syncTestTable: TableFilterComponent; |
| 25 | + tests: Test[] = []; |
| 26 | + testsToSync: Test[] = []; |
| 27 | + notExecutedFor = 5; |
| 28 | + removeNotExecuted = true; |
| 29 | + cols = [ |
| 30 | + { |
| 31 | + name: 'Name', |
| 32 | + property: 'name', |
| 33 | + filter: true, |
| 34 | + sorting: true, |
| 35 | + type: 'text' |
| 36 | + } |
| 37 | + ]; |
| 38 | + |
| 39 | + constructor( |
| 40 | + private testSuiteService: TestSuiteService, |
| 41 | + ) { |
| 42 | + super(); |
| 43 | + } |
| 44 | + |
| 45 | + async accept(execute: boolean) { |
| 46 | + this.testsToSync = this.syncTestTable.getSelectedEntitites(); |
| 47 | + if (execute) { |
| 48 | + if (this.testsToSync.length > 0) { |
| 49 | + if (this.testsToSync.length > 50) { |
| 50 | + this.testSuiteService.handleInfo(`You are running synchronization for ${this.testsToSync.length}, |
| 51 | + be patient it will take some time.`); |
| 52 | + } |
| 53 | + await this.testSuiteService.syncSuite(this.testsToSync, this.suite.id, this.removeNotExecuted); |
| 54 | + this.testSuiteService.handleSuccess('Tests were synchronized!'); |
| 55 | + } else { |
| 56 | + this.testSuiteService.handleWarning('No tests selected', 'You should select at least one test to sync!'); |
| 57 | + return; |
| 58 | + } |
| 59 | + } |
| 60 | + this.onClick(execute); |
| 61 | + } |
| 62 | + |
| 63 | + suiteChange(suite: TestSuite) { |
| 64 | + this.suite = suite; |
| 65 | + } |
| 66 | + |
| 67 | + async findTests() { |
| 68 | + this.tests = await this.testSuiteService.findTestToSync(this.notExecutedFor, this.suite.id); |
| 69 | + if (this.tests.length < 1) { |
| 70 | + this.testSuiteService.handleWarning('No tests found', |
| 71 | + `No test were stored with Not Executed result for at least ${this.notExecutedFor |
| 72 | + } last test runs for ${this.suite.name} suite!`); |
| 73 | + } |
| 74 | + } |
| 75 | +} |
0 commit comments