Skip to content

Commit

Permalink
fix: adjust test config, fix translations for import
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryT-CG committed Jan 9, 2024
1 parent 9140fe3 commit 01d0d07
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 38 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"node_modules/**",
"src/app/generated/**",
"src/app/api/*",
"src/app/model/*"
"src/app/model/*",
"src/**/*.ico",
"src/**/*.svg"
],
"overrides": [
{
Expand Down
14 changes: 2 additions & 12 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module.exports = function (config) {
require('karma-coverage'),
require('karma-jasmine'),
require('karma-jasmine-html-reporter'),
require('karma-junit-reporter'),
require('karma-sonarqube-unit-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
Expand All @@ -27,15 +26,6 @@ module.exports = function (config) {
jasmineHtmlReporter: {
suppressAll: true // removes the duplicated traces
},
junitReporter: {
outputDir: 'reports/unit-test-results', // results will be saved as $outputDir/$browserName.xml
outputFile: 'results-junit-tests.xml', // if included, results will be saved as $outputDir/$browserName/$outputFile
suite: 'models', // suite will become the package name attribute in xml testsuite element
useBrowserName: false, // add browser name to report and classes names
nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element
classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element
properties: {} // key value pair of properties to add to the <properties> section of the report
},
sonarqubeReporter: {
basePath: 'src/app', // test files folder
filePattern: '**/*.spec.ts', // test files glob pattern
Expand All @@ -55,9 +45,9 @@ module.exports = function (config) {
includeAllSources: true,
dir: 'reports',
subdir: 'coverage',
reporters: [{ type: 'html' }, { type: 'text-summary' }, { type: 'lcov' }]
reporters: [{ type: 'html' }, { type: 'text-summary' }]
},
reporters: ['progress', 'kjhtml', 'coverage', 'sonarqubeUnit', 'junit'],
reporters: ['progress', 'kjhtml', 'coverage', 'sonarqubeUnit'],
preprocessors: { 'src/**/*.js': ['coverage'] },
port: 9876,
colors: true,
Expand Down
8 changes: 3 additions & 5 deletions sonar-local-project.properties
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# sonar.verbose=true
sonar.host.url=http://localhost:9000
#sonar.token=<local-created-token>
sonar.token=sqp_4f516f122209fad902530dc69bf59664457ab48e
# sonar.host.url=http://localhost:9000
# sonar.token=<local-created-token>
# remote
#sonar.host.url=https://sonarcloud.io
sonar.host.url=https://sonarcloud.io
sonar.organization=onecx
sonar.projectKey=onecx-theme-ui
sonar.projectName=onecx-theme-ui
sonar.javascript.coveragePlugin=lcov
sonar.javascript.lcov.reportPaths=reports/coverage/lcov.info
sonar.testExecutionReportPaths=reports/sonarqube_report.xml
#sonar.eslint.reportPaths=eslint_report
sonar.sourceEncoding=UTF-8
sonar.sources=src/app
sonar.working.directory=dist/sonar
Expand Down
4 changes: 3 additions & 1 deletion src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export const basePathProvider = (mfeInfo: MfeInfo) => {
}

export function HttpLoaderFactory(http: HttpClient, mfeInfo: MfeInfo) {
console.log(`Configuring translation loader ${mfeInfo?.remoteBaseUrl}`)
if (mfeInfo) {
console.log(`Configuring translation loader ${mfeInfo?.remoteBaseUrl}`)
}
// if running standalone then load the app assets directly from remote base URL
const appAssetPrefix = mfeInfo && mfeInfo.remoteBaseUrl ? mfeInfo.remoteBaseUrl : './'
return new TranslateCombinedLoader(
Expand Down
42 changes: 23 additions & 19 deletions src/app/theme/theme-import/theme-import.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TranslateService } from '@ngx-translate/core'
import { ActivatedRoute, Router } from '@angular/router'

import { ThemesAPIService } from './../../generated/api/themes.service'
import { CreateThemeDTO, ThemeDTO } from '../../generated'
import { Theme, ThemeSnapshot } from '../../generated'
import { PortalMessageService } from '@onecx/portal-integration-angular'

@Component({
Expand All @@ -17,11 +17,11 @@ export class ThemeImportComponent implements OnInit {
@Output() public displayThemeImportChange = new EventEmitter<boolean>()
@Output() public uploadEmitter = new EventEmitter()

private themes!: ThemeDTO[]
private themes!: Theme[]
public themeName = ''
public themeNameExists = false
public themeImportError = false
public themeImportRequestDTO: ThemeDTO | null = null
public themeSnapshot: ThemeSnapshot | null = null
public httpHeaders!: HttpHeaders
public properties: any = null

Expand All @@ -41,13 +41,15 @@ export class ThemeImportComponent implements OnInit {

public onImportThemeSelect(event: { files: FileList }): void {
event.files[0].text().then((text) => {
this.themeImportRequestDTO = null
this.themeSnapshot = null
try {
const themeImportRequestDTO = JSON.parse(text)
if (this.isThemeImportRequestDTO(themeImportRequestDTO)) {
this.themeImportRequestDTO = themeImportRequestDTO
const themeSnapshot = JSON.parse(text)
if (this.isThemeImportRequestDTO(themeSnapshot)) {
this.themeSnapshot = themeSnapshot
this.themeImportError = false
this.properties = themeImportRequestDTO.properties
if (themeSnapshot.themes !== undefined) {
this.properties = themeSnapshot?.themes[0].properties
}
this.checkThemeExistence()
} else {
console.error('Theme Import Error: not valid data ')
Expand All @@ -62,7 +64,7 @@ export class ThemeImportComponent implements OnInit {
public checkThemeExistence() {
this.themeNameExists = false
for (const { name } of this.themes) {
if (name === this.themeImportRequestDTO?.name) {
if (name === this.themeSnapshot?.themes) {
this.themeNameExists = true
}
}
Expand All @@ -72,36 +74,38 @@ export class ThemeImportComponent implements OnInit {
this.displayThemeImportChange.emit(false)
}
public onImportThemeClear(): void {
this.themeImportRequestDTO = null
this.themeSnapshot = null
this.themeImportError = false
}
public onThemeUpload(): void {
this.themeApi
.createNewTheme({
createThemeDTO: this.themeImportRequestDTO as CreateThemeDTO
.importThemes({
themeSnapshot: this.themeSnapshot as ThemeSnapshot
})
.subscribe({
next: (data) => {
this.msgService.success({ summaryKey: 'PORTAL_IMPORT.IMPORT_THEME_SUCCESS' })
this.msgService.success({ summaryKey: 'THEME.IMPORT.IMPORT_THEME_SUCCESS' })
this.onImportThemeClear()
this.displayThemeImport = false
this.uploadEmitter.emit()
this.router.navigate([`./${data.id}`], { relativeTo: this.route })
},
error: () => {
this.msgService.error({ summaryKey: 'PORTAL_IMPORT.IMPORT_THEME_FAIL' })
this.msgService.error({ summaryKey: 'THEME.IMPORT.IMPORT_THEME_FAIL' })
}
})
}

private isThemeImportRequestDTO(obj: unknown): obj is ThemeDTO {
const dto = obj as ThemeDTO
return !!(typeof dto === 'object' && dto && dto.name)
private isThemeImportRequestDTO(obj: unknown): obj is ThemeSnapshot {
const dto = obj as ThemeSnapshot
return !!(typeof dto === 'object' && dto)
}

private getThemes(emit: boolean): void {
this.themeApi.getThemes().subscribe((themes) => {
this.themes = themes
this.themeApi.getThemes({}).subscribe((themes) => {
if (themes.stream) {
this.themes = themes.stream
}
if (emit) this.uploadEmitter.emit()
})
}
Expand Down

0 comments on commit 01d0d07

Please sign in to comment.