-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/docker/onecx/docker-spa-base-1.6.0
- Loading branch information
Showing
13 changed files
with
619 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/app/remotes/announcement-list-active/announcement-list-active.component.bootstrap.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] | ||
) |
63 changes: 63 additions & 0 deletions
63
src/app/remotes/announcement-list-active/announcement-list-active.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
161 changes: 161 additions & 0 deletions
161
src/app/remotes/announcement-list-active/announcement-list-active.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.