-
Notifications
You must be signed in to change notification settings - Fork 6
racer-line-view widget #631
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4f3c371
Added a start-line-view widget
gregw d7fbaee
Added a start-line-view widget
gregw c95b6fb
Update src/app/widgets/widget-racer-line-view/widget-racer-line-view.…
gregw 36f8915
Fixes from coderabbit review
gregw c72cd00
Always expose 10 boats lengths of line if possible.
gregw 75be083
Merge remote-tracking branch 'origin/main' into line-visuals
gregw ae33962
Fixes after merge
gregw 8963613
fixed subpath handling of line names
gregw 8255469
Fix VMG unit conversion
gregw 871944a
Fix Start time reset
gregw 4afd3c1
chore(schema): regenerate dashboard schema
mairas 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
122 changes: 122 additions & 0 deletions
122
src/app/core/directives/widget-runtime.directive.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,122 @@ | ||
| import { TestBed } from '@angular/core/testing'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { WidgetRuntimeDirective } from './widget-runtime.directive'; | ||
| import type { IWidgetSvcConfig } from '../interfaces/widgets-interface'; | ||
|
|
||
| /** | ||
| * The merge is what a placed widget actually runs on: its defaults under the config that | ||
| * was saved with it on the dashboard. | ||
| */ | ||
| describe('WidgetRuntimeDirective config merge', () => { | ||
| const build = (base: IWidgetSvcConfig, saved: IWidgetSvcConfig) => | ||
| TestBed.runInInjectionContext(() => { | ||
| const d = new WidgetRuntimeDirective(); | ||
| d.initialize(base, saved); | ||
| return d.options(); | ||
| }); | ||
|
|
||
| it('keeps the saved value for an editable path', () => { | ||
| const merged = build( | ||
| { paths: { p: { description: 'P', path: 'self.a', source: 'default', pathType: 'number', isPathConfigurable: true } } }, | ||
| { paths: { p: { description: 'P', path: 'self.b', source: 'default', pathType: 'number', isPathConfigurable: true } } } | ||
| ); | ||
| expect(merged?.paths?.['p'].path).toBe('self.b'); | ||
| }); | ||
|
|
||
| /** | ||
| * The regression this exists for: a widget placed on a dashboard stored the path its | ||
| * release happened to use, and because the path is fixed — not shown in the options | ||
| * dialog, not editable — a later correction to the widget's defaults could never reach | ||
| * it. The stored value is not a choice, so it does not get to win. | ||
| */ | ||
| it('takes a fixed path back from the defaults', () => { | ||
| const merged = build( | ||
| { paths: { p: { description: 'P', path: 'self.racing.lines', source: 'default', pathType: 'object', isPathConfigurable: false, enableTimeout: false } } }, | ||
| { paths: { p: { description: 'P', path: 'self.racing.lines.lines', source: 'default', pathType: null, isPathConfigurable: false } } } | ||
| ); | ||
| expect(merged?.paths?.['p'].path).toBe('self.racing.lines'); | ||
| expect(merged?.paths?.['p'].pathType).toBe('object'); | ||
| expect(merged?.paths?.['p'].enableTimeout).toBe(false); | ||
| }); | ||
|
|
||
| /** | ||
| * A widget that retires a setting must actually be rid of it: the saved config carries | ||
| * whatever it was when the widget was placed, and the merge lets the saved value win. | ||
| */ | ||
| it('drops a retired widget setting the defaults no longer declare', () => { | ||
| const merged = build( | ||
| { paths: {} }, | ||
| { enableTimeout: true, dataTimeout: 5, paths: {} } | ||
| ); | ||
| expect(merged?.enableTimeout).toBeUndefined(); | ||
| expect(merged?.dataTimeout).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('keeps it for a widget that still declares it', () => { | ||
| const merged = build( | ||
| { enableTimeout: false, paths: {} }, | ||
| { enableTimeout: true, paths: {} } | ||
| ); | ||
| expect(merged?.enableTimeout).toBe(true); | ||
| }); | ||
|
|
||
| it('leaves a fixed path that offers options alone, the stored one being a choice', () => { | ||
| const merged = build( | ||
| { | ||
| paths: { | ||
| p: { | ||
| description: 'P', path: 'self.headingTrue', source: 'default', pathType: 'number', | ||
| isPathConfigurable: false, | ||
| pathOptions: [{ label: 'True', path: 'self.headingTrue' }, { label: 'Magnetic', path: 'self.headingMagnetic' }] | ||
| } | ||
| } | ||
| }, | ||
| { paths: { p: { description: 'P', path: 'self.headingMagnetic', source: 'default', pathType: 'number', isPathConfigurable: false } } } | ||
| ); | ||
| expect(merged?.paths?.['p'].path).toBe('self.headingMagnetic'); | ||
| }); | ||
|
|
||
| it('leaves the editable parts of a fixed path alone', () => { | ||
| const merged = build( | ||
| { paths: { p: { description: 'P', path: 'self.len', source: 'default', pathType: 'number', isPathConfigurable: false, convertUnitTo: 'm' } } }, | ||
| { paths: { p: { description: 'P', path: 'self.len', source: 'n2k', pathType: 'number', isPathConfigurable: false, convertUnitTo: 'feet' } } } | ||
| ); | ||
| expect(merged?.paths?.['p'].convertUnitTo).toBe('feet'); | ||
| expect(merged?.paths?.['p'].source).toBe('n2k'); | ||
| }); | ||
|
|
||
| /** | ||
| * Whether a path keeps the widget's unit or follows the server's preference is the | ||
| * widget's own decision, not a stored choice — a widget corrected to hold metres must | ||
| * not be dragged back to the server's nautical miles by what was saved with it. | ||
| */ | ||
| it('takes a fixed path’s unit policy back from the defaults', () => { | ||
| const merged = build( | ||
| { paths: { p: { description: 'P', path: 'self.len', source: 'default', pathType: 'number', isPathConfigurable: false, convertUnitTo: 'm', showConvertUnitTo: false } } }, | ||
| { paths: { p: { description: 'P', path: 'self.len', source: 'default', pathType: 'number', isPathConfigurable: false, convertUnitTo: 'm', showConvertUnitTo: true } } } | ||
| ); | ||
| expect(merged?.paths?.['p'].showConvertUnitTo).toBe(false); | ||
| }); | ||
|
|
||
| /** | ||
| * And with the policy, the unit it decides: a path the widget does not expose the unit | ||
| * for is converted with its own fixed unit, so the stored one is as stale a snapshot as | ||
| * the path — restoring the policy alone would leave the widget converting to a unit it | ||
| * no longer declares. | ||
| */ | ||
| it('takes a structural fixed path’s unit back from the defaults too', () => { | ||
| const merged = build( | ||
| { paths: { p: { description: 'P', path: 'self.len', source: 'default', pathType: 'number', isPathConfigurable: false, convertUnitTo: 'm', showConvertUnitTo: false } } }, | ||
| { paths: { p: { description: 'P', path: 'self.len', source: 'default', pathType: 'number', isPathConfigurable: false, convertUnitTo: 'nm', showConvertUnitTo: false } } } | ||
| ); | ||
| expect(merged?.paths?.['p'].convertUnitTo).toBe('m'); | ||
| }); | ||
|
|
||
| it('keeps the saved unit where the widget exposes it for editing', () => { | ||
| const merged = build( | ||
| { paths: { p: { description: 'P', path: 'self.len', source: 'default', pathType: 'number', isPathConfigurable: false, convertUnitTo: 'm', showConvertUnitTo: true } } }, | ||
| { paths: { p: { description: 'P', path: 'self.len', source: 'default', pathType: 'number', isPathConfigurable: false, convertUnitTo: 'feet', showConvertUnitTo: true } } } | ||
| ); | ||
| expect(merged?.paths?.['p'].convertUnitTo).toBe('feet'); | ||
| }); | ||
| }); |
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
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.
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.