Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/docker/onecx/docker-spa-base-1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryT-CG authored Aug 28, 2024
2 parents 7fcebaa + 08eb7a7 commit cd56649
Show file tree
Hide file tree
Showing 13 changed files with 619 additions and 259 deletions.
7 changes: 7 additions & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ app:
technology: WEBCOMPONENTMODULE
remoteName: onecx-announcement
tagName: ocx-announcement-banner-component
announcement-list-active:
exposedModule: "./OneCXAnnouncementListActiveComponent"
description: "Announcement list active component"
type: COMPONENT
technology: WEBCOMPONENTMODULE
remoteName: onecx-announcement
tagName: ocx-announcement-list-active-component
# Permission
permission:
enabled: true
Expand Down
491 changes: 251 additions & 240 deletions package-lock.json

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@
"@ngrx/router-store": "^18.0.1",
"@ngx-translate/core": "^15.0.0",
"@ngx-translate/http-loader": "^8.0.0",
"@onecx/accelerator": "^5.3.1",
"@onecx/angular-accelerator": "^5.3.1",
"@onecx/angular-auth": "^5.3.1",
"@onecx/angular-integration-interface": "^5.3.1",
"@onecx/angular-remote-components": "^5.3.1",
"@onecx/angular-testing": "^5.3.1",
"@onecx/angular-webcomponents": "^5.3.1",
"@onecx/integration-interface": "^5.3.1",
"@onecx/keycloak-auth": "^5.3.1",
"@onecx/portal-integration-angular": "^5.3.1",
"@onecx/portal-layout-styles": "^5.3.1",
"@onecx/accelerator": "^5.9.0",
"@onecx/angular-accelerator": "^5.9.0",
"@onecx/angular-auth": "^5.9.0",
"@onecx/angular-integration-interface": "^5.9.0",
"@onecx/angular-remote-components": "^5.9.0",
"@onecx/angular-testing": "^5.9.0",
"@onecx/angular-webcomponents": "^5.9.0",
"@onecx/integration-interface": "^5.9.0",
"@onecx/keycloak-auth": "^5.9.0",
"@onecx/portal-integration-angular": "^5.9.0",
"@onecx/portal-layout-styles": "^5.9.0",
"@webcomponents/webcomponentsjs": "^2.8.0",
"file-saver": "^2.0.5",
"keycloak-angular": "^16.0.1",
Expand Down Expand Up @@ -93,7 +93,7 @@
"@svgr/webpack": "^8.1.0",
"@swc-node/register": "^1.10.9",
"@types/jasmine": "~5.1.4",
"@types/node": "~22.2.0",
"@types/node": "~22.5.0",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"css-loader": "^7.1.2",
Expand All @@ -110,16 +110,16 @@
"karma-jasmine": "^5.1.0",
"karma-jasmine-html-reporter": "^2.1.0",
"karma-sonarqube-unit-reporter": "^0.0.23",
"ng-packagr": "18.1.0",
"ng-packagr": "18.2.1",
"ngx-build-plus": "^18.0.0",
"ngx-translate-testing": "^7.0.0",
"postcss": "8.4.41",
"postcss-import": "~16.1.0",
"postcss-preset-env": "~10.0.0",
"postcss-preset-env": "~10.0.2",
"postcss-url": "~10.1.3",
"prettier": "^3.3.3",
"sonar-scanner": "^3.1.0",
"sonarqube-scanner": "^4.0.1",
"sonarqube-scanner": "^4.2.1",
"style-loader": "^4.0.0",
"ts-node": "10.9.2",
"typescript": "5.5",
Expand Down
6 changes: 6 additions & 0 deletions src/app/announcement/announcement.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ import { SharedModule } from '../shared/shared.module'
import { AnnouncementSearchComponent } from './announcement-search/announcement-search.component'
import { AnnouncementCriteriaComponent } from './announcement-search/announcement-criteria/announcement-criteria.component'
import { AnnouncementDetailComponent } from './announcement-detail/announcement-detail.component'
import { OneCXAnnouncementListActiveComponent } from '../remotes/announcement-list-active/announcement-list-active.component'

const routes: Routes = [
{
path: '',
component: AnnouncementSearchComponent,
pathMatch: 'full'
},
{
path: 'list-active',
component: OneCXAnnouncementListActiveComponent,
pathMatch: 'full'
}
]
@NgModule({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from 'src/app/shared/generated'

class MockAppStateService {
currentPortal$ = {
currentWorkspace$ = {
asObservable: () =>
of({
workspaceName: 'wsName'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class OneCXAnnouncementBannerComponent implements ocxRemoteComponent, ocx
this.userService.lang$.subscribe((lang) => this.translateService.use(lang))
combineLatest([
this.baseUrl.asObservable(),
this.appStateService.currentPortal$.asObservable(),
this.appStateService.currentWorkspace$.asObservable(),
this.appStateService.currentMfe$.asObservable()
])
.pipe(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'
import { importProvidersFrom } from '@angular/core'
import { OneCXAnnouncementListActiveComponent } from './announcement-list-active.component'
import { bootstrapRemoteComponent } from '@onecx/angular-webcomponents'
import { AngularAuthModule } from '@onecx/angular-auth'
import { environment } from 'src/environments/environment'

bootstrapRemoteComponent(
OneCXAnnouncementListActiveComponent,
'ocx-announcement-list-active-component',
environment.production,
[provideHttpClient(withInterceptorsFromDi()), importProvidersFrom(AngularAuthModule)]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<ng-container *ngIf="announcements$ | async as announcements">
<p-dataView
#table
id="am_announcement_list_active_dataview"
[value]="announcements"
[rows]="10"
[layout]="'list'"
[emptyMessage]="'ACTIONS.SEARCH.NO_DATA' | translate"
>
<ng-template let-announcements let-row="rowIndex" pTemplate="listItem">
<div
*ngFor="let announcement of announcements"
class="flex flex-row flex-nowrap justify-content-start align-items-center column-gap-3 py-1 px-3 hover:bg-gray-200 cursor-pointer"
>
<div
[id]="'am_announcement_list_active_data_row_' + row + '_title'"
class="p-0 col-8 sm:col-6 md:col-6 lg:col-5 xl:col-3 sm:font-bold text-base sm:text-md md:text-lg"
[pTooltip]="'ANNOUNCEMENT.TOOLTIPS.TITLE' | translate"
tooltipPosition="top"
tooltipEvent="hover"
>
{{ limitText(announcement.title, 60) }}
</div>
<div
[id]="'am_announcement_list_active_data_row_' + row + '_content'"
class="p-0 hidden md:block col-2"
[pTooltip]="'ANNOUNCEMENT.TOOLTIPS.CONTENT' | translate"
tooltipPosition="top"
tooltipEvent="hover"
>
{{ limitText(announcement.content, 40) }}
</div>
<div
[id]="'am_announcement_list_active_data_row_' + row + '_type'"
class="p-0 hidden xl:block col-2"
[pTooltip]="'ANNOUNCEMENT.TOOLTIPS.TYPE' | translate"
tooltipPosition="top"
tooltipEvent="hover"
>
{{ limitText(announcement.type, 50) }}
</div>
<div
[id]="'am_announcement_list_active_data_row_' + row + '_priority'"
class="p-0 hidden xl:block col-2"
[pTooltip]="'ANNOUNCEMENT.TOOLTIPS.PRIORITY' | translate"
tooltipPosition="top"
tooltipEvent="hover"
>
{{ limitText(announcement.priority, 50) }}
</div>
<div
[id]="'am_announcement_list_active_data_row_' + row + '_workspace'"
class="p-0 hidden xl:block col-2"
[pTooltip]="'ANNOUNCEMENT.TOOLTIPS.WORKSPACE' | translate"
tooltipPosition="top"
tooltipEvent="hover"
>
{{ limitText(announcement.workspaceName, 50) }}
</div>
</div>
</ng-template>
</p-dataView>
</ng-container>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'

import { ReplaySubject, of, throwError } from 'rxjs'
import { TranslateTestingModule } from 'ngx-translate-testing'
import { provideHttpClient } from '@angular/common/http'
import { provideHttpClientTesting } from '@angular/common/http/testing'
import { CarouselModule } from 'primeng/carousel'
import { TagModule } from 'primeng/tag'

import { BASE_URL, RemoteComponentConfig } from '@onecx/angular-remote-components'
import { AppConfigService, AppStateService } from '@onecx/portal-integration-angular'
import { OneCXAnnouncementListActiveComponent } from './announcement-list-active.component'
import {
Announcement,
AnnouncementInternalAPIService,
AnnouncementPriorityType,
AnnouncementStatus
} from 'src/app/shared/generated'

class MockAppStateService {
currentWorkspace$ = {
asObservable: () =>
of({
workspaceName: 'wsName'
})
}
currentMfe$ = {
asObservable: () =>
of({
productName: 'productName'
})
}
}

const importantAnnouncement: Announcement = {
id: 'importantAnncmtId',
priority: AnnouncementPriorityType.Important,
status: AnnouncementStatus.Active
}
const normalAnnouncement: Announcement = {
priority: AnnouncementPriorityType.Normal,
status: AnnouncementStatus.Active
}
const lowPrioAnnouncement: Announcement = {
priority: AnnouncementPriorityType.Low
}

describe('AnnouncementListActiveComponent', () => {
let component: OneCXAnnouncementListActiveComponent
let fixture: ComponentFixture<OneCXAnnouncementListActiveComponent>
let mockAppStateService: MockAppStateService

const apiServiceSpy = {
searchAnnouncementBanners: jasmine
.createSpy('searchAnnouncementBanners')
.and.returnValue(of({ stream: [normalAnnouncement] }))
}

let baseUrlSubject: ReplaySubject<any>
beforeEach(() => {
mockAppStateService = new MockAppStateService()
baseUrlSubject = new ReplaySubject<any>(1)

TestBed.configureTestingModule({
declarations: [],
imports: [
TranslateTestingModule.withTranslations({
en: require('../../../assets/i18n/en.json')
}).withDefaultLanguage('en')
],
providers: [
{ provide: AppStateService, useValue: mockAppStateService },
provideHttpClient(),
provideHttpClientTesting(),
{
provide: BASE_URL,
useValue: baseUrlSubject
}
]
})
.overrideComponent(OneCXAnnouncementListActiveComponent, {
set: {
imports: [TranslateTestingModule, CarouselModule, TagModule],
providers: [
{ provide: AnnouncementInternalAPIService, useValue: apiServiceSpy },
{ provide: AppConfigService },
{ provide: AppStateService, useValue: mockAppStateService }
]
}
})
.compileComponents()

baseUrlSubject.next('base_url_mock')

apiServiceSpy.searchAnnouncementBanners.calls.reset()
})

function initializeComponent() {
fixture = TestBed.createComponent(OneCXAnnouncementListActiveComponent)
component = fixture.componentInstance
fixture.detectChanges()
}

it('should create', () => {
initializeComponent()
expect(component).toBeTruthy()
})

it('should load announcements when the component starts', () => {
apiServiceSpy.searchAnnouncementBanners.and.returnValue(
of({ stream: [normalAnnouncement, importantAnnouncement, lowPrioAnnouncement] })
)

initializeComponent()

expect(component).toBeTruthy()
component['announcementsSubject'].subscribe((anncmts) => {
expect(anncmts).toEqual([normalAnnouncement, importantAnnouncement, lowPrioAnnouncement])
})
})

it('should catch an error if loading announcements fails', () => {
apiServiceSpy.searchAnnouncementBanners.and.returnValue(throwError(() => new Error()))

initializeComponent()

expect(component).toBeTruthy()
component['announcementsSubject'].subscribe((anncmts) => {
expect(anncmts).toEqual([])
})
})

describe('RemoteComponent initialization', () => {
it('should call ocxInitRemoteComponent with the correct config', () => {
const mockConfig: RemoteComponentConfig = {
appId: 'appId',
productName: 'prodName',
permissions: ['permission'],
baseUrl: 'base'
}
spyOn(component, 'ocxInitRemoteComponent')

component.ocxRemoteComponentConfig = mockConfig

expect(component.ocxInitRemoteComponent).toHaveBeenCalledWith(mockConfig)
})

it('should initialize the remote component', (done: DoneFn) => {
initializeComponent()

component.ocxInitRemoteComponent({
baseUrl: 'base_url'
} as RemoteComponentConfig)

baseUrlSubject.asObservable().subscribe((item) => {
expect(item).toEqual('base_url')
done()
})
})
})
})
Loading

0 comments on commit cd56649

Please sign in to comment.