Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
ntqdinh-axonivy committed Dec 17, 2024
1 parent ec32a56 commit c523f9e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 37 deletions.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {
HttpInterceptorFn
} from '@angular/common/http';
import { environment } from '../../../environments/environment';
import { LoadingService } from '../services/loading/loading.service';
import { inject } from '@angular/core';
import { catchError, EMPTY, finalize } from 'rxjs';
import { Router } from '@angular/router';
import { ERROR_CODES, ERROR_PAGE_PATH } from '../../shared/constants/common.constant';
import { LoadingService } from '../services/loading/loading.service';

export const REQUEST_BY = 'X-Requested-By';
export const IVY = 'marketplace-website';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ProductDetailActionType } from '../../../../shared/enums/product-detail
import { MATOMO_TRACKING_ENVIRONMENT } from '../../../../shared/constants/matomo.constant';

class MockElementRef implements ElementRef {
nativeElement = {
nativeElement = {
contains: jasmine.createSpy('contains')
};
}
Expand Down Expand Up @@ -292,64 +292,44 @@ describe('ProductDetailVersionActionComponent', () => {
component.versions.set(['1.0', '1.1']);
fixture.detectChanges();
component.getVersionInDesigner();
expect(
productServiceMock.sendRequestToGetProductVersionsForDesigner
).not.toHaveBeenCalled();
expect(productServiceMock.sendRequestToGetProductVersionsForDesigner).not.toHaveBeenCalled();
});

it('should call productService and update versions if versions are empty', () => {
const productId = '123';
component.versions.set([]);
const mockVersions = [{ version: '1.0' }, { version: '2.0' }];
productServiceMock.sendRequestToGetProductVersionsForDesigner.and.returnValue(
of(mockVersions)
);
productServiceMock.sendRequestToGetProductVersionsForDesigner.and.returnValue(of(mockVersions));

// Act
component.getVersionInDesigner();

// Assert
expect(
productServiceMock.sendRequestToGetProductVersionsForDesigner
).toHaveBeenCalledWith(productId);
expect(productServiceMock.sendRequestToGetProductVersionsForDesigner).toHaveBeenCalledWith(productId);
expect(component.versions()).toEqual(['Version 1.0', 'Version 2.0']);
});

it('should handle empty response from productService', () => {
component.versions.set([]);
productServiceMock.sendRequestToGetProductVersionsForDesigner.and.returnValue(
of([])
);
productServiceMock.sendRequestToGetProductVersionsForDesigner.and.returnValue(of([]));

// Act
component.getVersionInDesigner();

// Assert
expect(
productServiceMock.sendRequestToGetProductVersionsForDesigner
).toHaveBeenCalledWith(productId);
expect(productServiceMock.sendRequestToGetProductVersionsForDesigner).toHaveBeenCalledWith(productId);
expect(component.versions()).toEqual([]);
});

it('should return the correct tracking environment based on the action type', () => {
const testCases = [
{
actionType: ProductDetailActionType.STANDARD,
expected: MATOMO_TRACKING_ENVIRONMENT.standard
},
{
actionType: ProductDetailActionType.DESIGNER_ENV,
expected: MATOMO_TRACKING_ENVIRONMENT.designerEnv
},
{
actionType: ProductDetailActionType.CUSTOM_SOLUTION,
expected: MATOMO_TRACKING_ENVIRONMENT.customSolution
}
{ actionType: ProductDetailActionType.STANDARD, expected: MATOMO_TRACKING_ENVIRONMENT.standard },
{ actionType: ProductDetailActionType.DESIGNER_ENV, expected: MATOMO_TRACKING_ENVIRONMENT.designerEnv },
{ actionType: ProductDetailActionType.CUSTOM_SOLUTION, expected: MATOMO_TRACKING_ENVIRONMENT.customSolution }
];

testCases.forEach(({ actionType, expected }) => {
component.actionType = actionType;

const result = component.getTrackingEnvironmentBasedOnActionType();
expect(result).toBe(expected);
});
Expand Down
8 changes: 1 addition & 7 deletions marketplace-ui/src/app/shared/mocks/mock-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,4 @@ export const MOCK_FEEDBACK_API_RESPONSE: FeedbackApiResponse = {
totalPages: 1,
number: 0
}
};

export const MOCK_RATING_STAR: StarRatingCounting[] = [
{ starRating: 0 },
{ starRating: 4 },
{ starRating: 3 }
];
};

0 comments on commit c523f9e

Please sign in to comment.