-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:truenas/webui into NAS-132720
- Loading branch information
Showing
199 changed files
with
2,095 additions
and
627 deletions.
There are no files selected for viewing
42 changes: 5 additions & 37 deletions
42
src/app/directives/navigate-and-interact/navigate-and-interact.directive.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 |
---|---|---|
@@ -1,54 +1,22 @@ | ||
import { Router } from '@angular/router'; | ||
import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/jest'; | ||
import { MockProvider } from 'ng-mocks'; | ||
import { createDirectiveFactory, mockProvider, SpectatorDirective } from '@ngneat/spectator/jest'; | ||
import { NavigateAndInteractService } from 'app/directives/navigate-and-interact/navigate-and-interact.service'; | ||
import { NavigateAndInteractDirective } from './navigate-and-interact.directive'; | ||
|
||
describe('NavigateAndInteractDirective', () => { | ||
let spectator: SpectatorDirective<NavigateAndInteractDirective>; | ||
let mockRouter: Router; | ||
const createDirective = createDirectiveFactory({ | ||
directive: NavigateAndInteractDirective, | ||
providers: [ | ||
MockProvider(Router, { | ||
navigate: jest.fn(() => Promise.resolve(true)), | ||
}), | ||
mockProvider(NavigateAndInteractService), | ||
], | ||
}); | ||
|
||
beforeEach(() => { | ||
spectator = createDirective('<div ixNavigateAndInteract [navigateRoute]="[\'/some-path\']" navigateHash="testHash"></div>'); | ||
mockRouter = spectator.inject(Router); | ||
}); | ||
|
||
it('should create an instance', () => { | ||
expect(spectator.directive).toBeTruthy(); | ||
}); | ||
|
||
it('should call router.navigate with correct parameters on click', () => { | ||
spectator.dispatchMouseEvent(spectator.element, 'click'); | ||
expect(mockRouter.navigate).toHaveBeenCalledWith(['/some-path'], { fragment: 'testHash' }); | ||
}); | ||
|
||
it('should scroll to and highlight the element with the given ID', () => { | ||
const scrollIntoViewMock = jest.fn(); | ||
HTMLElement.prototype.scrollIntoView = scrollIntoViewMock; | ||
|
||
const mockElement = document.createElement('div'); | ||
mockElement.id = 'testHash'; | ||
document.body.appendChild(mockElement); | ||
|
||
const clickSpy = jest.spyOn(HTMLElement.prototype, 'click'); | ||
|
||
it('calls NavigateAndInteractService.navigateAndInteract when element is clicked', () => { | ||
spectator.dispatchMouseEvent(spectator.element, 'click'); | ||
|
||
setTimeout(() => { | ||
expect(scrollIntoViewMock).toHaveBeenCalled(); | ||
expect(clickSpy).toHaveBeenCalled(); | ||
|
||
// Clean up | ||
document.body.removeChild(mockElement); | ||
// Restore original scrollIntoView | ||
delete HTMLElement.prototype.scrollIntoView; | ||
}, 0); | ||
expect(spectator.inject(NavigateAndInteractService).navigateAndInteract).toHaveBeenCalledWith(['/some-path'], 'testHash'); | ||
}); | ||
}); |
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
51 changes: 51 additions & 0 deletions
51
src/app/directives/navigate-and-interact/navigate-and-interact.service.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,51 @@ | ||
import { Router } from '@angular/router'; | ||
import { | ||
createServiceFactory, | ||
SpectatorService, | ||
} from '@ngneat/spectator/jest'; | ||
import { MockProvider } from 'ng-mocks'; | ||
import { NavigateAndInteractService } from 'app/directives/navigate-and-interact/navigate-and-interact.service'; | ||
|
||
describe('NavigateAndInteractService', () => { | ||
let spectator: SpectatorService<NavigateAndInteractService>; | ||
const createComponent = createServiceFactory({ | ||
service: NavigateAndInteractService, | ||
providers: [ | ||
MockProvider(Router, { | ||
navigate: jest.fn(() => Promise.resolve(true)), | ||
}), | ||
], | ||
}); | ||
|
||
beforeEach(() => { | ||
spectator = createComponent(); | ||
}); | ||
|
||
it('should call router.navigate with correct parameters on click', () => { | ||
spectator.service.navigateAndInteract(['/some-path'], 'testHash'); | ||
expect(spectator.inject(Router).navigate).toHaveBeenCalledWith(['/some-path'], { fragment: 'testHash' }); | ||
}); | ||
|
||
it('should scroll to and highlight the element with the given ID', () => { | ||
const scrollIntoViewMock = jest.fn(); | ||
HTMLElement.prototype.scrollIntoView = scrollIntoViewMock; | ||
|
||
const mockElement = document.createElement('div'); | ||
mockElement.id = 'testHash'; | ||
document.body.appendChild(mockElement); | ||
|
||
const clickSpy = jest.spyOn(HTMLElement.prototype, 'click'); | ||
|
||
spectator.service.navigateAndInteract(['/some-path'], 'testHash'); | ||
|
||
setTimeout(() => { | ||
expect(scrollIntoViewMock).toHaveBeenCalled(); | ||
expect(clickSpy).toHaveBeenCalled(); | ||
|
||
// Clean up | ||
document.body.removeChild(mockElement); | ||
// Restore original scrollIntoView | ||
delete HTMLElement.prototype.scrollIntoView; | ||
}, 0); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
src/app/directives/navigate-and-interact/navigate-and-interact.service.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,32 @@ | ||
import { Inject, Injectable } from '@angular/core'; | ||
import { Router } from '@angular/router'; | ||
import { WINDOW } from 'app/helpers/window.helper'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class NavigateAndInteractService { | ||
constructor( | ||
private router: Router, | ||
@Inject(WINDOW) private window: Window, | ||
) {} | ||
|
||
navigateAndInteract(route: string[], hash: string): void { | ||
this.router.navigate(route, { fragment: hash }).then(() => { | ||
setTimeout(() => { | ||
const htmlElement = this.window.document.getElementById(hash); | ||
if (htmlElement) { | ||
this.handleHashScrollIntoView(htmlElement); | ||
} | ||
}, 150); | ||
}); | ||
} | ||
|
||
private handleHashScrollIntoView(htmlElement: HTMLElement): void { | ||
const highlightedClass = 'highlighted-element'; | ||
htmlElement.scrollIntoView({ block: 'center' }); | ||
htmlElement.classList.add(highlightedClass); | ||
htmlElement.click(); | ||
setTimeout(() => htmlElement.classList.remove(highlightedClass), 2150); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export interface FibreChannelPort { | ||
id: number; | ||
port: string; | ||
wwpn: string | null; | ||
wwpn_b: string | null; | ||
target: unknown; // TODO: Probably IscsiTarget | ||
} | ||
|
||
export interface FibreChannelPortUpdate { | ||
port: string; | ||
target_id: number; | ||
} | ||
|
||
export type FibreChannelPortChoices = Record<string, { | ||
wwpn: string; | ||
wwpn_b: string; | ||
}>; |
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
1 change: 1 addition & 0 deletions
1
src/app/modules/forms/ix-forms/components/ix-checkbox/ix-checkbox.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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<mat-checkbox | ||
ixRegisteredControl | ||
color="primary" | ||
[checked]="value" | ||
[required]="required" | ||
|
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
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
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
Oops, something went wrong.