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.
- Loading branch information
Showing
25 changed files
with
559 additions
and
48 deletions.
There are no files selected for viewing
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
...ular-sdk/src/lib/components/access-key-management/access-key-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 { AccessKeyManagementComponent } from './access-key-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 DescopeAccessKeyManagementWidget | ||
jest.mock('@descope/access-key-management-widget', () => { | ||
return jest.fn(() => { | ||
// Create a mock DOM element | ||
return document.createElement('descope-access-key-management-widget'); | ||
}); | ||
}); | ||
|
||
describe('DescopeAccessKeyManagementComponent', () => { | ||
let component: AccessKeyManagementComponent; | ||
let fixture: ComponentFixture<AccessKeyManagementComponent>; | ||
let mockedCreateSdk: jest.Mock; | ||
const onSessionTokenChangeSpy = jest.fn(); | ||
const onAccessKeyChangeSpy = jest.fn(); | ||
const afterRequestHooksSpy = jest.fn(); | ||
const mockConfig: DescopeAuthConfig = { | ||
projectId: 'someProject' | ||
}; | ||
|
||
beforeEach(() => { | ||
mockedCreateSdk = mocked(createSdk); | ||
|
||
mockedCreateSdk.mockReturnValue({ | ||
onSessionTokenChange: onSessionTokenChangeSpy, | ||
onAccessKeyChange: onAccessKeyChangeSpy, | ||
httpClient: { | ||
hooks: { | ||
afterRequest: afterRequestHooksSpy | ||
} | ||
} | ||
}); | ||
|
||
TestBed.configureTestingModule({ | ||
schemas: [CUSTOM_ELEMENTS_SCHEMA], | ||
providers: [ | ||
DescopeAuthConfig, | ||
{ provide: DescopeAuthConfig, useValue: mockConfig } | ||
] | ||
}); | ||
|
||
fixture = TestBed.createComponent(AccessKeyManagementComponent); | ||
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-access-key-management-widget' | ||
); | ||
expect(webComponentHtml).toBeDefined(); | ||
}); | ||
|
||
it('should correctly setup attributes based on inputs', () => { | ||
const html: HTMLElement = fixture.nativeElement; | ||
const webComponentHtml = html.querySelector( | ||
'descope-access-key-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
...s/angular-sdk/src/lib/components/access-key-management/access-key-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 DescopeAccessKeyManagementWidget from '@descope/access-key-management-widget'; | ||
import { ILogger } from '@descope/web-component'; | ||
import { DescopeAuthConfig } from '../../types/types'; | ||
|
||
@Component({ | ||
selector: 'access-key-management[tenant]', | ||
standalone: true, | ||
template: '' | ||
}) | ||
export class AccessKeyManagementComponent 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 DescopeAccessKeyManagementWidget(); | ||
|
||
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; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.