Skip to content

Commit

Permalink
refactor: Adds an index file to enums file and refactor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
manikanta-reddy-t authored and tarun-testsigma committed Jan 5, 2023
1 parent 38c8b55 commit de4d5ec
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {PlatformBrowser} from "../../agents/models/platform-browser.model";
import {MobileOsType} from "../../agents/enums/mobile-os-type.enum";
import {AgentService} from "../../agents/services/agent.service";
import {Browser} from "../../agents/models/browser.model";
import {Browsers} from "../../enums/browsers";
import {WebBrowser} from "../../enums/web-browser";

@Component({
selector: 'app-test-plan-device-form',
Expand Down Expand Up @@ -104,9 +104,9 @@ export class TestPlanDeviceFormComponent extends TestPlanPlatformOsVersionFormCo
this.environmentFormGroup.controls['platformDeviceId'].setValue(cloudDevice?.id);
this.environmentFormGroup.controls['deviceName'].setValue(cloudDevice?.name);
if (this.version.workspace.isMobileWeb) {
let browser = new PlatformBrowser().deserialize({id: "chrome", name: "Chrome"});
let browser = new PlatformBrowser().deserialize({id: WebBrowser.CHROME, name: WebBrowser.CHROME});
if (this.platform.isIOS)
browser = new PlatformBrowser().deserialize({id: "safari", name: "Safari"});
browser = new PlatformBrowser().deserialize({id: WebBrowser.SAFARI, name: WebBrowser.SAFARI});
this.environmentFormGroup.controls['browser']?.setValue(browser.name.toUpperCase());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {Platform} from "../../agents/models/platform.model";
import {PlatformOsVersion} from "../../agents/models/platform-os-version.model";
import {FormGroup} from '@angular/forms';
import {WorkspaceVersion} from "../../models/workspace-version.model";
import {TestPlanLabType} from "../../enums/test-plan-lab-type.enum";
import {TestPlanLabType,WebBrowser} from "../../enums";
import {PlatformBrowser} from "../../agents/models/platform-browser.model";
import {PlatformBrowserVersion} from "../../agents/models/platform-browser-version.model";
import {Agent} from "../../agents/models/agent.model";
Expand All @@ -13,7 +13,6 @@ import {AgentService} from "../../agents/services/agent.service";
import {Page} from "../../shared/models/page";
import {Pageable} from "../../shared/models/pageable";
import {Platform as EnumPlatform} from "../../enums/platform.enum";
import {Browsers} from "../../enums/browsers";

@Component({
selector: 'app-test-plan-platform-os-version-form',
Expand Down Expand Up @@ -68,14 +67,14 @@ export class TestPlanPlatformOsVersionFormComponent implements OnInit {
this.platformBrowser = null;
this.browserVersion = null;
this.isBrowserLoaded = false;
this.platformOsVersions=null;
this.platformOsVersions = null;
if (changes && changes['testPlanLabType'] && !this.isEdit) {
if (!changes['testPlanLabType']['firstChange'] &&
(changes['testPlanLabType']['currentValue'] == TestPlanLabType.TestsigmaLab)) {
this.environmentFormGroup?.controls['platformOsVersionId']?.patchValue(null);
}
}
if(changes && changes['environmentFormGroup'] && !changes['environmentFormGroup']['firstChange'] && !this.isEdit && this.isHybrid) {
if (changes && changes['environmentFormGroup'] && !changes['environmentFormGroup']['firstChange'] && !this.isEdit && this.isHybrid) {
this.setTargetMachines();
}
}
Expand All @@ -96,7 +95,7 @@ export class TestPlanPlatformOsVersionFormComponent implements OnInit {
this.platform = this.platforms[0];
this.environmentFormGroup?.controls['platform']?.setValue(this.platform?.id);
}
if(!this.platform){
if (!this.platform) {
if (this.version.workspace.isWeb)
this.platform = this.platforms.find(platform => platform.isWindows);
else if (this.version.workspace.isAndroidNative)
Expand All @@ -107,7 +106,7 @@ export class TestPlanPlatformOsVersionFormComponent implements OnInit {
this.platform = this.platforms.find(platform => platform.isIOS);
}
this.fetchOsVersions();
});
});
}

setPlatform(platformId) {
Expand All @@ -119,14 +118,13 @@ export class TestPlanPlatformOsVersionFormComponent implements OnInit {
this.platformService.findAllOsVersions(this.platform, this.version.workspace.workspaceType, this.testPlanLabType).subscribe(res => {
this.platformOsVersions = res;
if (this.environmentFormGroup?.controls['platformOsVersionId']?.value)
this.platformOsVersion = this.platformOsVersions.find(osVersion => osVersion.id == this.environmentFormGroup?.controls['platformOsVersionId']?.value)
this.platformOsVersion = this.platformOsVersions.find(osVersion => osVersion.id == this.environmentFormGroup?.controls['platformOsVersionId']?.value)
if (!this.platformOsVersion || setValue) {
if (this.platformOsVersions.length>0) {
if (this.platformOsVersions.length > 0) {
this.platformOsVersion = this.platformOsVersions[0];
this.environmentFormGroup?.controls['platformOsVersionId'].setValue(this.platformOsVersion.id);
this.environmentFormGroup.controls['osVersion']?.setValue(this.platformOsVersion.version);
}
else{
} else {
this.platformOsVersion = null;
this.environmentFormGroup?.controls['platformOsVersionId'].setValue(null);
this.environmentFormGroup.controls['osVersion']?.setValue("Not Available");
Expand Down Expand Up @@ -157,12 +155,12 @@ export class TestPlanPlatformOsVersionFormComponent implements OnInit {
if (!this.platformBrowser || setValue) {
this.platformBrowser = this.browsers[0];
this.environmentFormGroup?.controls['browser']?.setValue(this.platformBrowser?.id);
if(this.version.workspace.isMobileWeb && this.platformBrowser.isChrome){
this.environmentFormGroup?.controls['browser']?.setValue(Browsers.CHROME);
if (this.version.workspace.isMobileWeb && this.platformBrowser.isChrome) {
this.environmentFormGroup?.controls['browser']?.setValue(WebBrowser.CHROME);
}
}
}
if (this.isPrivateGrid){
if (this.isPrivateGrid) {
if (this.environmentFormGroup?.controls['browser']?.value)
this.platformBrowser = this.browsers.find(browser => browser.name == this.environmentFormGroup?.controls['browser']?.value);
if (!this.platformBrowser || setValue) {
Expand All @@ -179,23 +177,22 @@ export class TestPlanPlatformOsVersionFormComponent implements OnInit {
fetchBrowserVersions(setValue?: Boolean) {
this.platformService.findAllBrowserVersions(this.platform, this.platformOsVersion, this.platformBrowser, this.version.workspace.workspaceType, this.testPlanLabType).subscribe(res => {
this.browserVersions = res;
if ( this.environmentFormGroup?.controls['platformBrowserVersionId']?.value) {
if (this.environmentFormGroup?.controls['platformBrowserVersionId']?.value) {
this.browserVersion = this.browserVersions.find(browserVersion => browserVersion.id === this.environmentFormGroup?.controls['platformBrowserVersionId']?.value)
}
if (setValue || !this.browserVersion) {
if (this.browserVersions.length>0) {
if (this.browserVersions.length > 0) {
this.browserVersion = this.browserVersions[0];
this.environmentFormGroup?.controls['platformBrowserVersionId'].setValue(this.browserVersion.id);
this.environmentFormGroup?.controls['browserVersion']?.setValue(this.browserVersion?.version);
}
else{
} else {
this.browserVersion = null;
this.environmentFormGroup?.controls['platformBrowserVersionId'].setValue(null);
this.environmentFormGroup?.controls['browserVersion']?.disable();
}
}
});
this.isBrowserLoaded=true;
this.isBrowserLoaded = true;
}

setPlatformBrowserVersion(browserVersionId) {
Expand All @@ -220,22 +217,22 @@ export class TestPlanPlatformOsVersionFormComponent implements OnInit {
setAgent(agent: Agent, isEdit?: boolean) {
this.agent = agent;
let rawData = this.environmentFormGroup['controls'];
if (rawData.browser?.value && (isEdit == undefined || isEdit == null))
if (rawData.browser?.value && (isEdit == undefined))
isEdit = true;
let data = {};
if (!isEdit && this.agent && this.version.workspace.isWeb)
this.browser = this.agent.browsers[0];
let osType = this.version.workspace?.isMobileNative ?
((this.version.workspace.isAndroidNative) ? EnumPlatform.Android: EnumPlatform.iOS): this.agent?.osType;
((this.version.workspace.isAndroidNative) ? EnumPlatform.Android : EnumPlatform.iOS) : this.agent?.osType;
data['platform'] = osType;
data['osVersion'] = this.agent?.osVersion
data['browser'] = this.browser?.name?.toUpperCase()
data['browserVersion'] = this.browser?.majorVersion
if (isEdit && this.agent) {
let findBrowser = this.agent.browsers.find(browser => browser.name.toUpperCase() == rawData.browser.value);
let browser: Browser = findBrowser ? findBrowser : this.version.workspace.isWeb? this.agent.browsers[0]: null;
let browser: Browser = findBrowser ? findBrowser : this.version.workspace.isWeb ? this.agent.browsers[0] : null;
data['platform'] = this.agent?.osType == rawData.platform.value ? rawData.platform.value :
(this.agent?.osType? this.agent?.osType : osType);
(this.agent?.osType ? this.agent?.osType : osType);
data['osVersion'] = this.agent?.osVersion == rawData.osVersion.value ? rawData.osVersion.value : this.agent?.osVersion;
data['browser'] = browser?.name?.toUpperCase()
data['browserVersion'] = browser?.majorVersion
Expand All @@ -245,10 +242,9 @@ export class TestPlanPlatformOsVersionFormComponent implements OnInit {
data['browser'] = this.browser?.name?.toUpperCase();
}
});
this.agentsEmpty = true;
setTimeout(()=> {this.agentsEmpty=false}, 10);
this.agentsEmpty = false;
}
this.environmentFormGroup.controls['platform'].setValue((this.version.workspace.isMobileWeb||this.version.workspace.isWeb)?null:data['platform'])
this.environmentFormGroup.controls['platform'].setValue((this.version.workspace.isMobileWeb || this.version.workspace.isWeb) ? null : data['platform'])
this.environmentFormGroup.controls['osVersion'].setValue(data['osVersion']);
this.environmentFormGroup.controls['browser']?.setValue(data['browser']);
this.environmentFormGroup.controls['browserVersion']?.setValue(data['browserVersion']);
Expand All @@ -259,7 +255,7 @@ export class TestPlanPlatformOsVersionFormComponent implements OnInit {
this.browserVersion = null;
this.platformBrowser = null;
this.environmentFormGroup.controls['browserVersion']?.setValue(this.browser?.majorVersion);
if(!this.isHybrid)
if (!this.isHybrid)
this.environmentFormGroup.controls['platformBrowserVersionId']?.setValue(this.browser?.id);
}

Expand Down Expand Up @@ -290,7 +286,7 @@ export class TestPlanPlatformOsVersionFormComponent implements OnInit {
fetchAgents() {
let pageable = new Pageable();
pageable.pageSize = 1;
this.agentService.findAll(null, null,pageable).subscribe(res => this.agentsEmpty = res.empty);
this.agentService.findAll(null, null, pageable).subscribe(res => this.agentsEmpty = res.empty);
}

}
3 changes: 0 additions & 3 deletions ui/src/app/enums/browsers.ts

This file was deleted.

45 changes: 45 additions & 0 deletions ui/src/app/enums/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
export * from './web-browser'
export * from './addon-parameter-type.enum'
export * from './active-environment-form-controls'
export * from './application-path-type.enum'
export * from './element-create-type.enum'
export * from './chrome-recorder-step.enum'
export * from './element-locator-type.enum'
export * from './element-status.enum'
export * from './entity-type.enum'
export * from './execution-type.enum'
export * from './filter.operation.enum'
export * from './filter-time-period.enum'
export * from './get-started-feature-type.enum'
export * from './http-header-names.enum'
export * from './invoice-status.enum'
export * from './mobile-inspection-status.enum'
export * from './on-aborted-action.enum'
export * from './onboarding.enum'
export * from './platform.enum'
export * from './pre-requisite-action.enum'
export * from './re-run-type.enum'
export * from './recover-action.enum'
export * from './registration-medium.enum'
export * from './rest-authorization.enum'
export * from './rest-compare-type.enum'
export * from './rest-method.enum'
export * from './result-constant.enum'
export * from './schedule-status.enum'
export * from './schedule-type.enum'
export * from './screen-orientation.enum'
export * from './screenshot.enum'
export * from './status-constant.enum'
export * from './step-action-type.enum'
export * from './storage-type.enum'
export * from './suggestion-result.enum'
export * from './test-case-status.enum'
export * from './test-data-type.enum'
export * from './test-lab-form-controls'
export * from './test-plan-lab-type.enum'
export * from './test-step-priority.enum'
export * from './test-step-condition-type.enum'
export * from './test-step-type.enum'
export * from './triggered-type.enum'
export * from './user-status.enum'
export * from './workspace-type.enum'
4 changes: 4 additions & 0 deletions ui/src/app/enums/web-browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum WebBrowser {
CHROME = "CHROME",
SAFARI = "SAFARI"
}

0 comments on commit de4d5ec

Please sign in to comment.