-
Notifications
You must be signed in to change notification settings - Fork 467
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 issue-28510-remove-bundle-name-column
- Loading branch information
Showing
20 changed files
with
520 additions
and
36 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
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
37 changes: 37 additions & 0 deletions
37
core-web/libs/data-access/src/lib/dot-analytics-search/dot-analytics-search.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,37 @@ | ||
import { createHttpFactory, HttpMethod, SpectatorHttp } from '@ngneat/spectator/jest'; | ||
|
||
import { DotAnalyticsSearchService } from '@dotcms/data-access'; | ||
import { AnalyticsQueryType } from '@dotcms/dotcms-models'; | ||
|
||
describe('DotAnalyticsSearchService', () => { | ||
let spectator: SpectatorHttp<DotAnalyticsSearchService>; | ||
const createHttp = createHttpFactory(DotAnalyticsSearchService); | ||
const mockResponse = { entity: [{ id: '1', name: 'result1' }] }; | ||
const query = { measures: ['request.count'], orders: 'request.count DESC' }; | ||
|
||
beforeEach(() => (spectator = createHttp())); | ||
|
||
it('should perform a POST request to the base URL and return results', (done) => { | ||
spectator.service.get(query).subscribe((results) => { | ||
expect(results).toEqual(mockResponse.entity); | ||
done(); | ||
}); | ||
|
||
const req = spectator.expectOne('/api/v1/analytics/content/_query', HttpMethod.POST); | ||
req.flush(mockResponse); | ||
|
||
expect(req.request.body).toEqual({ ...query }); | ||
}); | ||
|
||
it('should perform a POST request to the cube URL and return results', (done) => { | ||
spectator.service.get(query, AnalyticsQueryType.CUBE).subscribe((results) => { | ||
expect(results).toEqual(mockResponse.entity); | ||
done(); | ||
}); | ||
|
||
const req = spectator.expectOne('/api/v1/analytics/content/_query/cube', HttpMethod.POST); | ||
req.flush(mockResponse); | ||
|
||
expect(req.request.body).toEqual({ ...query }); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
core-web/libs/data-access/src/lib/dot-analytics-search/dot-analytics-search.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,43 @@ | ||
import { JsonObject } from '@angular-devkit/core'; | ||
import { Observable } from 'rxjs'; | ||
|
||
import { HttpClient } from '@angular/common/http'; | ||
import { Injectable, inject } from '@angular/core'; | ||
|
||
import { pluck } from 'rxjs/operators'; | ||
|
||
import { AnalyticsQueryType } from '@dotcms/dotcms-models'; | ||
|
||
/** | ||
* Service for performing analytics search operations. | ||
*/ | ||
@Injectable() | ||
export class DotAnalyticsSearchService { | ||
/** | ||
* URL for analytics content search with DotCMS standards. | ||
* @private | ||
*/ | ||
readonly #BASE_URL = '/api/v1/analytics/content/_query'; | ||
/** | ||
* URL for analytics content search with the cube query standards. | ||
* @private | ||
*/ | ||
readonly #CUBE_URL = '/api/v1/analytics/content/_query/cube'; | ||
|
||
readonly #http = inject(HttpClient); | ||
|
||
/** | ||
* Performs a POST request to the base URL with the provided query. | ||
* @param {Record<string, unknown>} query - The query object to be sent in the request body. | ||
* @param {AnalyticsQueryType} [type=AnalyticsQueryType.DEFAULT] - The type of analytics query to be performed. | ||
* @returns {Observable<JsonObject[]>} - An observable containing the response from the server. | ||
*/ | ||
get( | ||
query: Record<string, unknown>, | ||
type: AnalyticsQueryType = AnalyticsQueryType.DEFAULT | ||
): Observable<JsonObject[]> { | ||
return this.#http | ||
.post(type == AnalyticsQueryType.DEFAULT ? this.#BASE_URL : this.#CUBE_URL, query) | ||
.pipe(pluck('entity')); | ||
} | ||
} |
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
4 changes: 4 additions & 0 deletions
4
core-web/libs/dotcms-models/src/lib/dot-content-analytics.model.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,4 @@ | ||
export enum AnalyticsQueryType { | ||
DEFAULT = 'DEFAULT', | ||
CUBE = 'CUBE' | ||
} |
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
28 changes: 27 additions & 1 deletion
28
...analytics-search/portlet/src/lib/dot-analytics-search/dot-analytics-search.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 +1,27 @@ | ||
<p>dot-analytics-search works!</p> | ||
<section class="content-analytics__query"> | ||
<div class="content-analytics__header"> | ||
<h4>{{ 'analytics.search.query' | dm }}</h4> | ||
<div class="content-analytics__actions"> | ||
<button | ||
pButton | ||
(click)="handleRequest()" | ||
[label]="'analytics.search.run.query' | dm" | ||
icon="pi pi-arrow-right" | ||
iconPos="right" | ||
data-testId="run-query"></button> | ||
</div> | ||
</div> | ||
<ngx-monaco-editor | ||
[(ngModel)]="queryEditor" | ||
[options]="ANALYTICS_MONACO_EDITOR_OPTIONS" | ||
data-testId="query-editor"></ngx-monaco-editor> | ||
</section> | ||
<section class="content-analytics__results"> | ||
<div class="content-analytics__header"> | ||
<h4>{{ 'analytics.search.results' | dm }}</h4> | ||
</div> | ||
<ngx-monaco-editor | ||
[ngModel]="results$()" | ||
[options]="ANALYTICS__RESULTS_MONACO_EDITOR_OPTIONS" | ||
data-testId="results-editor"></ngx-monaco-editor> | ||
</section> |
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
75 changes: 63 additions & 12 deletions
75
...lytics-search/portlet/src/lib/dot-analytics-search/dot-analytics-search.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 |
---|---|---|
@@ -1,22 +1,73 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { MonacoEditorModule } from '@materia-ui/ngx-monaco-editor'; | ||
import { byTestId, createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator/jest'; | ||
import { MockModule } from 'ng-mocks'; | ||
|
||
import { provideHttpClient } from '@angular/common/http'; | ||
import { provideHttpClientTesting } from '@angular/common/http/testing'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
|
||
import { DotAnalyticsSearchService, DotHttpErrorManagerService } from '@dotcms/data-access'; | ||
|
||
import { DotAnalyticsSearchComponent } from './dot-analytics-search.component'; | ||
|
||
import { DotAnalyticsSearchStore } from '../store/dot-analytics-search.store'; | ||
|
||
describe('DotAnalyticsSearchComponent', () => { | ||
let component: DotAnalyticsSearchComponent; | ||
let fixture: ComponentFixture<DotAnalyticsSearchComponent>; | ||
let spectator: Spectator<DotAnalyticsSearchComponent>; | ||
let store: InstanceType<typeof DotAnalyticsSearchStore>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [DotAnalyticsSearchComponent] | ||
}).compileComponents(); | ||
const createComponent = createComponentFactory({ | ||
component: DotAnalyticsSearchComponent, | ||
imports: [MockModule(MonacoEditorModule)], | ||
componentProviders: [DotAnalyticsSearchStore, DotAnalyticsSearchService], | ||
declarations: [], | ||
mocks: [], | ||
providers: [ | ||
provideHttpClient(), | ||
provideHttpClientTesting(), | ||
{ | ||
provide: ActivatedRoute, | ||
useValue: { | ||
snapshot: { | ||
data: { | ||
isEnterprise: true | ||
} | ||
} | ||
} | ||
}, | ||
mockProvider(DotHttpErrorManagerService) | ||
] | ||
}); | ||
|
||
fixture = TestBed.createComponent(DotAnalyticsSearchComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
beforeEach(() => { | ||
spectator = createComponent(); | ||
store = spectator.inject(DotAnalyticsSearchStore, true); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
it('should initialize store with enterprise state on init', () => { | ||
const initLoadSpy = jest.spyOn(store, 'initLoad'); | ||
spectator.component.ngOnInit(); | ||
|
||
expect(initLoadSpy).toHaveBeenCalledWith(true); | ||
}); | ||
|
||
it('should call getResults with valid JSON', () => { | ||
const getResultsSpy = jest.spyOn(store, 'getResults'); | ||
spectator.component.queryEditor = '{"measures": ["request.count"]}'; | ||
spectator.detectChanges(); | ||
const button = spectator.query(byTestId('run-query')) as HTMLButtonElement; | ||
spectator.click(button); | ||
|
||
expect(getResultsSpy).toHaveBeenCalledWith({ measures: ['request.count'] }); | ||
}); | ||
|
||
it('should not call getResults with invalid JSON', () => { | ||
const getResultsSpy = jest.spyOn(store, 'getResults'); | ||
spectator.component.queryEditor = 'invalid json'; | ||
spectator.detectChanges(); | ||
const button = spectator.query(byTestId('run-query')) as HTMLButtonElement; | ||
spectator.click(button); | ||
|
||
expect(getResultsSpy).not.toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.