forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 8
93 static pages and not found behavior #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
amadulhaxxani
wants to merge
7
commits into
clarin-v7
Choose a base branch
from
93-static-pages-and-not-found-behavior
base: clarin-v7
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6d9f6d7
Show 404 error for missing static pages
amadulhaxxani 1ceae7f
Improve static page loading and error handling
amadulhaxxani 196a125
Use any-cast for changeDetector spies
amadulhaxxani 6385430
Merge branch 'clarin-v7' into current branch - resolve i18n conflicts
amadulhaxxani 1428048
Make cache-bust deterministic & refactor tests
amadulhaxxani d1a76ac
Add loading indicator and error logging
amadulhaxxani 501500e
Use hourly cache-busting query param
amadulhaxxani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,93 @@ | ||
| import { TestBed } from '@angular/core/testing'; | ||
| import { HttpClient, HttpResponse } from '@angular/common/http'; | ||
| import { of } from 'rxjs'; | ||
| import { HtmlContentService } from './html-content.service'; | ||
| import { LocaleService } from '../core/locale/locale.service'; | ||
|
|
||
| describe('HtmlContentService', () => { | ||
| let service: HtmlContentService; | ||
| let httpClient: jasmine.SpyObj<HttpClient>; | ||
| let localeService: jasmine.SpyObj<LocaleService>; | ||
|
|
||
| beforeEach(() => { | ||
| const httpSpy = jasmine.createSpyObj('HttpClient', ['get']); | ||
| const localeSpy = jasmine.createSpyObj('LocaleService', ['getCurrentLanguageCode']); | ||
|
|
||
| TestBed.configureTestingModule({ | ||
| providers: [ | ||
| HtmlContentService, | ||
| { provide: HttpClient, useValue: httpSpy }, | ||
| { provide: LocaleService, useValue: localeSpy } | ||
| ] | ||
| }); | ||
|
|
||
| service = TestBed.inject(HtmlContentService); | ||
| httpClient = TestBed.inject(HttpClient) as jasmine.SpyObj<HttpClient>; | ||
| localeService = TestBed.inject(LocaleService) as jasmine.SpyObj<LocaleService>; | ||
| }); | ||
|
|
||
| it('should be created', () => { | ||
| expect(service).toBeTruthy(); | ||
| }); | ||
|
|
||
| describe('getHmtlContentByPathAndLocale - fallback mechanism', () => { | ||
| it('should return English fallback when Czech translation not found (404)', async () => { | ||
| localeService.getCurrentLanguageCode.and.returnValue('cs'); | ||
|
|
||
| const czechContent404 = new HttpResponse({ status: 404, body: '' }); | ||
| const englishContent200 = new HttpResponse({ status: 200, body: '<div>English Content</div>' }); | ||
|
|
||
| httpClient.get.and.returnValues( | ||
| of(czechContent404), | ||
| of(czechContent404), | ||
| of(englishContent200) | ||
| ); | ||
|
|
||
| const result = await service.getHmtlContentByPathAndLocale('license'); | ||
|
|
||
| expect(result).toBe('<div>English Content</div>'); | ||
| expect(httpClient.get).toHaveBeenCalledTimes(3); | ||
| }); | ||
|
|
||
| it('should return localized content when translation exists (200)', async () => { | ||
| localeService.getCurrentLanguageCode.and.returnValue('cs'); | ||
|
|
||
| const czechContent200 = new HttpResponse({ status: 200, body: '<div>Czech Content</div>' }); | ||
|
|
||
| httpClient.get.and.returnValue(of(czechContent200)); | ||
|
|
||
| const result = await service.getHmtlContentByPathAndLocale('license'); | ||
|
|
||
| expect(result).toBe('<div>Czech Content</div>'); | ||
| expect(httpClient.get).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('should return English content directly when language is "en"', async () => { | ||
| localeService.getCurrentLanguageCode.and.returnValue('en'); | ||
|
|
||
| const englishContent200 = new HttpResponse({ status: 200, body: '<div>English Content</div>' }); | ||
|
|
||
| httpClient.get.and.returnValue(of(englishContent200)); | ||
|
|
||
| const result = await service.getHmtlContentByPathAndLocale('license'); | ||
|
|
||
| expect(result).toBe('<div>English Content</div>'); | ||
| expect(httpClient.get).toHaveBeenCalledTimes(1); | ||
| expect(httpClient.get.calls.mostRecent().args[0]).toContain('static-files/license.html'); | ||
| expect(httpClient.get.calls.mostRecent().args[0]).not.toContain('/cs/'); | ||
| }); | ||
|
|
||
| it('should return undefined when both Czech and English files not found', async () => { | ||
| localeService.getCurrentLanguageCode.and.returnValue('cs'); | ||
|
|
||
| const content404 = new HttpResponse({ status: 404, body: '' }); | ||
|
|
||
| httpClient.get.and.returnValue(of(content404)); | ||
|
|
||
| const result = await service.getHmtlContentByPathAndLocale('nonexistent'); | ||
|
|
||
| expect(result).toBeUndefined(); | ||
| expect(httpClient.get).toHaveBeenCalledTimes(4); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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,3 +1,20 @@ | ||
| <div class="container" > | ||
| <div class="container text-center my-5" *ngIf="contentState === 'loading'"> | ||
| <ds-themed-loading [spinner]="true" [showMessage]="false"></ds-themed-loading> | ||
| </div> | ||
|
|
||
| <!-- Show static page content when found --> | ||
| <div class="container" *ngIf="contentState === 'found'"> | ||
| <div [innerHTML]="(htmlContent | async) | dsSafeHtml" (click)="processLinks($event)"></div> | ||
| </div> | ||
|
|
||
| <!-- Show 404 error when content not found (matches PageNotFoundComponent design) --> | ||
| <div class="container page-not-found" *ngIf="contentState === 'not-found'"> | ||
| <h1>404</h1> | ||
| <h2><small>{{"static-page.404.page-not-found" | translate}}</small></h2> | ||
| <br/> | ||
| <p>{{"static-page.404.help" | translate}}</p> | ||
| <br/> | ||
| <p class="text-center"> | ||
| <a routerLink="/home" class="btn btn-primary">{{"static-page.404.link.home-page" | translate}}</a> | ||
| </p> | ||
| </div> | ||
amadulhaxxani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.