Repository navigation
[ENG-12722] Feature/redirect landing page #1107
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
futa-ikeda
wants to merge
1
commit into
CenterForOpenScience:feature/redirect-links
Choose a base branch
from
futa-ikeda:feature/redirect-landing-page
base: feature/redirect-links
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
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
26 changes: 26 additions & 0 deletions
26
src/app/core/components/redirect-page/redirect-page.component.html
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,26 @@ | ||
| <section | ||
| class="container flex flex-column flex-1 my-7 mx-3 p-3 align-items-center md:p-4 md:flex-row md:justify-content-between" | ||
| > | ||
| <img | ||
| class="redirect-image w-8 md:w-6" | ||
| ngSrc="assets/images/laptop-books.png" | ||
| width="500" | ||
| height="346" | ||
| priority | ||
| [alt]="'redirectPage.altText' | translate" | ||
| /> | ||
|
|
||
| <div class="flex flex-column align-items-center m-4 md:align-items-start"> | ||
| <h2>{{ 'redirectPage.header' | translate }}</h2> | ||
| <p class="mt-4">{{ 'redirectPage.message' | translate }}</p> | ||
|
|
||
| <div class="flex flex-column mt-4 gap-4 md:flex-row md:justify-content-start"> | ||
| <a class="p-button font-bold no-underline" [href]="redirectDestination()"> | ||
| {{ 'common.buttons.continue' | translate }} | ||
| </a> | ||
| <p-button severity="info" (onClick)="goBack()"> | ||
| {{ 'common.buttons.goBack' | translate }} | ||
| </p-button> | ||
| </div> | ||
| </div> | ||
| </section> | ||
19 changes: 19 additions & 0 deletions
19
src/app/core/components/redirect-page/redirect-page.component.scss
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,19 @@ | ||
| @use "styles/mixins" as mix; | ||
|
|
||
| :host { | ||
| @include mix.flex-center; | ||
| flex: 1; | ||
| background: var(--gradient-3); | ||
| } | ||
|
|
||
| .container { | ||
| background: var(--white); | ||
| border-radius: 0.75rem; | ||
| box-shadow: 0 2px 4px var(--grey-outline); | ||
| color: var(--dark-blue-1); | ||
| } | ||
|
|
||
| .redirect-image { | ||
| height: auto; | ||
| object-fit: contain; | ||
| } |
105 changes: 105 additions & 0 deletions
105
src/app/core/components/redirect-page/redirect-page.component.spec.ts
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,105 @@ | ||
| import { MockProvider } from 'ng-mocks'; | ||
|
|
||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
|
||
| import { WINDOW } from '@core/provider/window.provider'; | ||
| import { CurrentResourceSelectors } from '@osf/shared/stores/current-resource/current-resource.selectors'; | ||
|
|
||
| import { provideOSFCore } from '@testing/osf.testing.provider'; | ||
| import { provideMockStore } from '@testing/providers/store-provider.mock'; | ||
|
|
||
| import { RedirectPageComponent } from './redirect-page.component'; | ||
|
|
||
| const mockResource = { | ||
| id: 'mock-resource-id', | ||
| type: 'mock-resource-type', | ||
| redirectUrl: 'https://example.com', | ||
| permissions: [], | ||
| redirectAutomatically: false, | ||
| }; | ||
|
|
||
| describe('RedirectPageComponent', () => { | ||
| let component: RedirectPageComponent; | ||
| let fixture: ComponentFixture<RedirectPageComponent>; | ||
| let windowMock: any; | ||
|
|
||
| afterEach(() => { | ||
| vi.useRealTimers(); | ||
| }); | ||
|
|
||
| const setup = (override?: Partial<typeof mockResource>) => { | ||
| const resource = { ...mockResource, ...override }; | ||
| const historyMock = { back: vi.fn() }; | ||
| windowMock = { history: historyMock, location: { href: '', set: vi.fn() } }; | ||
| TestBed.configureTestingModule({ | ||
| imports: [RedirectPageComponent], | ||
| providers: [ | ||
| provideOSFCore(), | ||
| MockProvider(WINDOW, windowMock), | ||
| provideMockStore({ | ||
| signals: [{ selector: CurrentResourceSelectors.getCurrentResource, value: resource }], | ||
| }), | ||
| ], | ||
| }); | ||
|
|
||
| fixture = TestBed.createComponent(RedirectPageComponent); | ||
| component = fixture.componentInstance; | ||
| fixture.detectChanges(); | ||
| }; | ||
|
|
||
| it('should create', () => { | ||
| setup(); | ||
| expect(component).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should have redirectDestination when resource has redirect URL', () => { | ||
| setup(); | ||
| expect(component.redirectDestination()).toBe(mockResource.redirectUrl); | ||
| }); | ||
|
|
||
| it('should not have redirectDestination when resource has no redirect URL', () => { | ||
| setup({ redirectUrl: undefined }); | ||
| expect(component.redirectDestination()).toBe(''); | ||
| }); | ||
|
|
||
| it('should render continue link and go back button', () => { | ||
| setup(); | ||
| const continueLink = fixture.nativeElement.querySelector('a') as HTMLAnchorElement; | ||
| expect(continueLink.getAttribute('href')).toBe(component.redirectDestination()); | ||
| const backButton = fixture.nativeElement.querySelector('button') as HTMLButtonElement; | ||
| expect(backButton).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should call goBack when go back button is clicked', () => { | ||
| setup(); | ||
| const goBackSpy = vi.spyOn(windowMock.history, 'back'); | ||
| const button = fixture.nativeElement.querySelector('button') as HTMLButtonElement; | ||
| button.click(); | ||
| expect(goBackSpy).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should not redirect when redirectDestination is empty', () => { | ||
| vi.useFakeTimers(); | ||
| setup({ redirectUrl: undefined }); | ||
| const redirectSpy = vi.spyOn(windowMock.location, 'href', 'set'); | ||
| vi.advanceTimersByTime(component.redirectDelay); | ||
| expect(redirectSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should automatically redirect after redirectDelay amount of time', () => { | ||
| vi.useFakeTimers(); | ||
| setup(); | ||
| const redirectSpy = vi.spyOn(windowMock.location, 'href', 'set'); | ||
| vi.advanceTimersByTime(component.redirectDelay); | ||
| expect(redirectSpy).toHaveBeenCalledWith(component.redirectDestination()); | ||
| }); | ||
|
|
||
| it('should not redirect if component is destroyed before redirectDelay', () => { | ||
| vi.useFakeTimers(); | ||
| setup(); | ||
| const redirectSpy = vi.spyOn(windowMock.location, 'href', 'set'); | ||
| fixture.destroy(); | ||
| vi.advanceTimersByTime(component.redirectDelay); | ||
| expect(redirectSpy).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
47 changes: 47 additions & 0 deletions
47
src/app/core/components/redirect-page/redirect-page.component.ts
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,47 @@ | ||
| import { select } from '@ngxs/store'; | ||
|
|
||
| import { TranslatePipe } from '@ngx-translate/core'; | ||
|
|
||
| import { Button } from 'primeng/button'; | ||
|
|
||
| import { timer } from 'rxjs'; | ||
|
|
||
| import { NgOptimizedImage } from '@angular/common'; | ||
| import { afterNextRender, ChangeDetectionStrategy, Component, computed, DestroyRef, inject } from '@angular/core'; | ||
| import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; | ||
|
|
||
| import { WINDOW } from '@core/provider/window.provider'; | ||
| import { CurrentResourceSelectors } from '@osf/shared/stores/current-resource/current-resource.selectors'; | ||
|
|
||
| @Component({ | ||
| selector: 'osf-redirect-page', | ||
| imports: [Button, NgOptimizedImage, TranslatePipe], | ||
| templateUrl: './redirect-page.component.html', | ||
| styleUrl: './redirect-page.component.scss', | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| }) | ||
| export class RedirectPageComponent { | ||
| private readonly currentResource = select(CurrentResourceSelectors.getCurrentResource); | ||
| private readonly window = inject(WINDOW); | ||
| private readonly destroyRef = inject(DestroyRef); | ||
| readonly redirectDelay = 5000; | ||
| readonly redirectDestination = computed(() => this.currentResource()?.redirectUrl ?? ''); | ||
|
|
||
| constructor() { | ||
| afterNextRender(() => { | ||
| const redirectUrl = this.redirectDestination(); | ||
| if (!redirectUrl) { | ||
| return; | ||
| } | ||
| timer(this.redirectDelay) | ||
| .pipe(takeUntilDestroyed(this.destroyRef)) | ||
| .subscribe(() => { | ||
| this.window.location.href = this.redirectDestination(); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| goBack() { | ||
| this.window.history.back(); | ||
| } | ||
| } | ||
|
futa-ikeda marked this conversation as resolved.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.