This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Audit widget * Audit widget
- Loading branch information
Showing
15 changed files
with
307 additions
and
67 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
79 changes: 79 additions & 0 deletions
79
projects/angular-sdk/src/lib/components/audit-management/audit-management.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,79 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { AuditManagementComponent } from './audit-management.component'; | ||
import createSdk from '@descope/web-js-sdk'; | ||
import { DescopeAuthConfig } from '../../types/types'; | ||
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; | ||
import mocked = jest.mocked; | ||
|
||
jest.mock('@descope/web-js-sdk'); | ||
//Mock DescopeAuditManagementWidget | ||
jest.mock('@descope/audit-management-widget', () => { | ||
return jest.fn(() => { | ||
// Create a mock DOM element | ||
return document.createElement('descope-audit-management-widget'); | ||
}); | ||
}); | ||
|
||
describe('DescopeAuditManagementComponent', () => { | ||
let component: AuditManagementComponent; | ||
let fixture: ComponentFixture<AuditManagementComponent>; | ||
let mockedCreateSdk: jest.Mock; | ||
const onSessionTokenChangeSpy = jest.fn(); | ||
const onAuditChangeSpy = jest.fn(); | ||
const afterRequestHooksSpy = jest.fn(); | ||
const mockConfig: DescopeAuthConfig = { | ||
projectId: 'someProject' | ||
}; | ||
|
||
beforeEach(() => { | ||
mockedCreateSdk = mocked(createSdk); | ||
|
||
mockedCreateSdk.mockReturnValue({ | ||
onSessionTokenChange: onSessionTokenChangeSpy, | ||
onAuditChange: onAuditChangeSpy, | ||
httpClient: { | ||
hooks: { | ||
afterRequest: afterRequestHooksSpy | ||
} | ||
} | ||
}); | ||
|
||
TestBed.configureTestingModule({ | ||
schemas: [CUSTOM_ELEMENTS_SCHEMA], | ||
providers: [ | ||
DescopeAuthConfig, | ||
{ provide: DescopeAuthConfig, useValue: mockConfig } | ||
] | ||
}); | ||
|
||
fixture = TestBed.createComponent(AuditManagementComponent); | ||
component = fixture.componentInstance; | ||
component.projectId = '123'; | ||
component.tenant = 'tenant-1'; | ||
component.widgetId = 'widget-1'; | ||
component.logger = { info: jest.fn(), error: jest.fn(), warn: jest.fn() }; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
const html: HTMLElement = fixture.nativeElement; | ||
const webComponentHtml = html.querySelector( | ||
'descope-audit-management-widget' | ||
); | ||
expect(webComponentHtml).toBeDefined(); | ||
}); | ||
|
||
it('should correctly setup attributes based on inputs', () => { | ||
const html: HTMLElement = fixture.nativeElement; | ||
const webComponentHtml = html.querySelector( | ||
'descope-audit-management-widget' | ||
)!; | ||
expect(webComponentHtml.getAttribute('project-id')).toStrictEqual('123'); | ||
expect(webComponentHtml.getAttribute('tenant')).toStrictEqual('tenant-1'); | ||
expect(webComponentHtml.getAttribute('widget-id')).toStrictEqual( | ||
'widget-1' | ||
); | ||
expect(webComponentHtml.getAttribute('logger')).toBeDefined(); | ||
}); | ||
}); |
58 changes: 58 additions & 0 deletions
58
projects/angular-sdk/src/lib/components/audit-management/audit-management.component.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,58 @@ | ||
import { Component, ElementRef, Input, OnChanges, OnInit } from '@angular/core'; | ||
import DescopeAuditManagementWidget from '@descope/audit-management-widget'; | ||
import { ILogger } from '@descope/web-component'; | ||
import { DescopeAuthConfig } from '../../types/types'; | ||
|
||
@Component({ | ||
selector: 'audit-management[tenant]', | ||
standalone: true, | ||
template: '' | ||
}) | ||
export class AuditManagementComponent implements OnInit, OnChanges { | ||
projectId: string; | ||
baseUrl?: string; | ||
@Input() tenant: string; | ||
@Input() widgetId: string; | ||
|
||
@Input() theme: 'light' | 'dark' | 'os'; | ||
@Input() debug: boolean; | ||
@Input() logger: ILogger; | ||
|
||
private readonly webComponent = new DescopeAuditManagementWidget(); | ||
|
||
constructor( | ||
private elementRef: ElementRef, | ||
descopeConfig: DescopeAuthConfig | ||
) { | ||
this.projectId = descopeConfig.projectId; | ||
this.baseUrl = descopeConfig.baseUrl; | ||
} | ||
|
||
ngOnInit() { | ||
this.setupWebComponent(); | ||
this.elementRef.nativeElement.appendChild(this.webComponent); | ||
} | ||
|
||
ngOnChanges(): void { | ||
this.setupWebComponent(); | ||
} | ||
|
||
private setupWebComponent() { | ||
this.webComponent.setAttribute('project-id', this.projectId); | ||
this.webComponent.setAttribute('tenant', this.tenant); | ||
this.webComponent.setAttribute('widget-id', this.widgetId); | ||
if (this.baseUrl) { | ||
this.webComponent.setAttribute('base-url', this.baseUrl); | ||
} | ||
if (this.theme) { | ||
this.webComponent.setAttribute('theme', this.theme); | ||
} | ||
if (this.debug) { | ||
this.webComponent.setAttribute('debug', this.debug.toString()); | ||
} | ||
|
||
if (this.logger) { | ||
(this.webComponent as any).logger = this.logger; | ||
} | ||
} | ||
} |
Oops, something went wrong.