-
Notifications
You must be signed in to change notification settings - Fork 17
Feat: Cache "Open" Project #254
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
karyao
wants to merge
8
commits into
main
Choose a base branch
from
feat_219_cache_open_applications
base: main
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
8 commits
Select commit
Hold shift + click to select a range
addb1bd
feat: add tab session storage contract
karyao 2e09853
feat: wire ApplicationService to restore tab bar from localStorage
karyao fea173b
feat: persist open applications across page loads
karyao edd511c
feat: resize tabs based on size and number of tabs
karyao 8158932
fix: closing tabs should go to the recent tabs
karyao e521eba
refactor: optimize layout costraints, loop performance
karyao 7db32fb
style: consistency with font size
karyao 574726d
style: use imported fontawesome icon
karyao 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
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,11 +1,38 @@ | ||
| @for (tab of tabs(); track $index) { | ||
| <div class="tab clickable" [class.focused]="tab.focused"> | ||
| <div class="click-nav" (click)="focusTab(tab)"> | ||
| <div | ||
| class="tab clickable" | ||
| [class.focused]="tab.focused" | ||
| (mouseenter)="showTooltip(tab, $event)" | ||
| (mouseleave)="hideTooltip()" | ||
| [id]="'tab-item-' + tab.id" | ||
| > | ||
| <div | ||
| class="click-nav" | ||
| (click)="focusTab(tab)" | ||
| tabindex="0" | ||
| (keydown.enter)="focusTab(tab)" | ||
| (keydown.space)="focusTab(tab); $event.preventDefault()" | ||
| > | ||
| <div class="icon"></div> | ||
| <div class="label">{{ tab.label }}</div> | ||
| </div> | ||
| <div class="x-container"> | ||
| <button type="button" (click)="closeTab(tab.id)">✕</button> | ||
| <button | ||
| type="button" | ||
| (click)="closeTab(tab.id); $event.stopPropagation()" | ||
| [id]="'tab-close-' + tab.id" | ||
| > | ||
| <fa-icon [icon]="closeIcon"></fa-icon> | ||
| </button> | ||
| </div> | ||
| </div> | ||
| } | ||
|
|
||
| <div | ||
| class="tab-tooltip" | ||
| [class.visible]="tooltipData().visible" | ||
| [style.left.px]="tooltipData().x" | ||
| [style.top.px]="tooltipData().y" | ||
| > | ||
| {{ tooltipData().text }} | ||
| </div> |
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
121 changes: 119 additions & 2 deletions
121
src/app/services/application/application.service.spec.ts
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did the tests require the |
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,16 +1,133 @@ | ||
| import { PLATFORM_ID } from '@angular/core'; | ||
| import { TestBed } from '@angular/core/testing'; | ||
|
|
||
| import { NavigationEnd, Router } from '@angular/router'; | ||
| import { Subject } from 'rxjs'; | ||
| import { vi } from 'vitest'; | ||
| import { TAB_SESSION_STORAGE_KEY } from './tab-session-state'; | ||
| import { ApplicationService } from './application.service'; | ||
|
|
||
| describe('ApplicationService', () => { | ||
| let service: ApplicationService; | ||
| let routerEvents: Subject<NavigationEnd>; | ||
| let navigateSpy: ReturnType<typeof vi.fn>; | ||
| let navigateByUrlSpy: ReturnType<typeof vi.fn>; | ||
|
|
||
| const getStoredApplicationIds = (): number[] => { | ||
| const raw = localStorage.getItem(TAB_SESSION_STORAGE_KEY); | ||
| if (!raw) { | ||
| return []; | ||
| } | ||
|
|
||
| return JSON.parse(raw).applicationIds as number[]; | ||
| }; | ||
|
|
||
| const navigateTo = (url: string): void => { | ||
| routerEvents.next(new NavigationEnd(1, url, url)); | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({}); | ||
| localStorage.clear(); | ||
| routerEvents = new Subject<NavigationEnd>(); | ||
| navigateSpy = vi.fn(); | ||
| navigateByUrlSpy = vi.fn(); | ||
|
|
||
| TestBed.configureTestingModule({ | ||
| providers: [ | ||
| { provide: Router, useValue: { events: routerEvents.asObservable(), navigate: navigateSpy, navigateByUrl: navigateByUrlSpy } }, | ||
| { provide: PLATFORM_ID, useValue: 'browser' } | ||
| ] | ||
| }); | ||
|
|
||
| service = TestBed.inject(ApplicationService); | ||
| }); | ||
|
|
||
| it('should be created', () => { | ||
| expect(service).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should restore valid application IDs from local storage', () => { | ||
| localStorage.setItem( | ||
| TAB_SESSION_STORAGE_KEY, | ||
| JSON.stringify({ version: 1, applicationIds: [0, 1, 999] }) | ||
| ); | ||
|
|
||
| TestBed.resetTestingModule(); | ||
| TestBed.configureTestingModule({ | ||
| providers: [ | ||
| { provide: Router, useValue: { events: routerEvents.asObservable(), navigate: navigateSpy, navigateByUrl: navigateByUrlSpy } }, | ||
| { provide: PLATFORM_ID, useValue: 'browser' } | ||
| ] | ||
| }); | ||
| service = TestBed.inject(ApplicationService); | ||
|
|
||
| expect([...service.runningApplications().keys()]).toEqual([0, 1]); | ||
| }); | ||
|
|
||
| it('should persist when a new application is opened', () => { | ||
| navigateTo('/readme'); | ||
|
|
||
| expect(getStoredApplicationIds()).toEqual([0]); | ||
| }); | ||
|
|
||
| it('should not persist when switching focus between open applications', () => { | ||
| navigateTo('/readme'); | ||
| navigateTo('/officers'); | ||
| const persistedAfterBothOpen = localStorage.getItem(TAB_SESSION_STORAGE_KEY); | ||
|
|
||
| navigateTo('/readme'); | ||
|
|
||
| expect(localStorage.getItem(TAB_SESSION_STORAGE_KEY)).toBe(persistedAfterBothOpen); | ||
| expect([...service.runningApplications().keys()]).toEqual([0, 1]); | ||
| }); | ||
|
|
||
| it('should persist when an application is closed', () => { | ||
| navigateTo('/readme'); | ||
| navigateTo('/officers'); | ||
|
|
||
| service.closeApplication(0); | ||
|
|
||
| expect(getStoredApplicationIds()).toEqual([1]); | ||
| }); | ||
|
|
||
| it('should persist an empty tab session when the last application is closed', () => { | ||
| navigateTo('/readme'); | ||
|
|
||
| service.closeApplication(0); | ||
|
|
||
| expect(getStoredApplicationIds()).toEqual([]); | ||
| expect(navigateSpy).toHaveBeenCalledWith(['/']); | ||
| }); | ||
|
|
||
| it('should navigate to the left neighbor when closing a focused tab', () => { | ||
| navigateTo('/readme'); | ||
| navigateTo('/officers'); | ||
| navigateTo('/committees'); | ||
|
|
||
| service.closeApplication(2); | ||
|
|
||
| expect(navigateByUrlSpy).toHaveBeenCalledWith('/officers'); | ||
| }); | ||
|
|
||
| it('should navigate to the right neighbor when there is no left neighbor', () => { | ||
| navigateTo('/readme'); | ||
| navigateTo('/officers'); | ||
|
|
||
| // Focus the leftmost tab so it has no left neighbor. | ||
| navigateTo('/readme'); | ||
|
|
||
| service.closeApplication(0); | ||
|
|
||
| expect(navigateByUrlSpy).toHaveBeenCalledWith('/officers'); | ||
| }); | ||
|
|
||
| it('should not navigate when closing a background tab', () => { | ||
| navigateTo('/readme'); | ||
| navigateTo('/officers'); | ||
|
|
||
| service.closeApplication(0); | ||
|
|
||
| expect(navigateByUrlSpy).not.toHaveBeenCalled(); | ||
| expect(navigateSpy).not.toHaveBeenCalled(); | ||
| expect(service.focusedApplication()?.id).toBe(1); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there an issue with using
auto? Iirc, this would fill any empty space, which I can't remember if I wanted or not.