Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/app/home/home.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
(keyup.enter)="hideKeyboard()"
></ion-input>
</ion-item>
<p class="help">
<ion-icon name="information-circle-outline"></ion-icon>
Which site or app are you logging into? e.g. <em>when.fm</em>
</p>
@if (show_home_help) {
<p class="help">
<ion-icon name="information-circle-outline"></ion-icon>
Which site or app are you logging into? e.g. <em>when.fm</em>
</p>
}
<ion-item>
<ion-input
appAutofill
Expand All @@ -35,11 +37,13 @@
(keyup.enter)="hideKeyboard()"
></ion-input>
</ion-item>
<p class="help">
<ion-icon name="information-circle-outline"></ion-icon>
Think of it as your digital skeleton key &ndash; a super secret, memorable password, that will enable you
to generate and recall separate login details for each service you use
</p>
@if (show_home_help) {
<p class="help">
<ion-icon name="information-circle-outline"></ion-icon>
Think of it as your digital skeleton key &ndash; a super secret, memorable password, that will enable you
to generate and recall separate login details for each service you use
</p>
}

@if (non_domain_warning) {
<p class="warning">
Expand Down
32 changes: 32 additions & 0 deletions src/app/home/home.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { IonicStorageModule } from '@ionic/storage-angular';

import { CapacitorSqliteDriverService } from '../capacitor-sqlite-driver.service';
import { HomePageComponent } from './home.page';
import { SettingsService } from '../settings.service';
import { SettingsSimple } from '../../models/SettingsSimple';

declare global {
interface Window {
Expand Down Expand Up @@ -41,4 +43,34 @@ describe('HomePageComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});

it('should show help paragraphs when show_home_help is true', async () => {
const settingsService = TestBed.inject(SettingsService);
const settings = new SettingsSimple();
settings.show_home_help = true;
vi.spyOn(settingsService, 'settings').mockReturnValue(settings);
vi.spyOn(settingsService, 'getCurrentSettings').mockResolvedValue(settings);

await component.update();
fixture.detectChanges();

const compiled = fixture.nativeElement as HTMLElement;
const helpParagraphs = compiled.querySelectorAll('p.help');
expect(helpParagraphs.length).toBe(2);
});

it('should hide help paragraphs when show_home_help is false', async () => {
const settingsService = TestBed.inject(SettingsService);
const settings = new SettingsSimple();
settings.show_home_help = false;
vi.spyOn(settingsService, 'settings').mockReturnValue(settings);
vi.spyOn(settingsService, 'getCurrentSettings').mockResolvedValue(settings);

await component.update();
fixture.detectChanges();

const compiled = fixture.nativeElement as HTMLElement;
const helpParagraphs = compiled.querySelectorAll('p.help');
expect(helpParagraphs.length).toBe(0);
});
});
4 changes: 4 additions & 0 deletions src/app/home/home.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export class HomePageComponent implements OnInit {
: false;
}

get show_home_help(): boolean {
return this.settings?.show_home_help ?? true;
}

async update() {
let settings: Settings;
try {
Expand Down
76 changes: 76 additions & 0 deletions src/app/settings.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,80 @@ describe("SettingsService", () => {
expect(service).toBeTruthy();
}
));

it("should hydrate legacy SettingsSimple without show_home_help with default true", inject(
[SettingsService],
(service: SettingsService) => {
const legacyRaw = {
class: "SettingsSimple",
added_number_on: false,
added_number: 0,
algorithm: "hmac-sha256",
domain_only: true,
output_character_set: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
output_length: 15,
remember_minutes: 5,
master_password_hash: false,
};

const hydrated = service.hydrateSettings(legacyRaw);
expect(hydrated instanceof SettingsSimple).toBe(true);
expect(hydrated.show_home_help).toBe(true);
}
));

it("should hydrate legacy SettingsAdvanced without show_home_help with default true", inject(
[SettingsService],
(service: SettingsService) => {
const legacyRaw = {
class: "SettingsAdvanced",
active_profile_id: 1,
remember_minutes: 5,
master_password_hash: false,
profiles: [
{
profile_id: 1,
name: "Default",
algorithm: "hmac-sha256",
domain_only: true,
leet_level: 0,
leet_location: "none",
modifier: "",
output_character_set_custom: "",
output_character_set_preset: "alphanumeric",
output_length: 15,
password_hash: "",
post_processing_suffix: "",
prefix: "",
suffix: "",
url_patterns: [],
},
],
};

const hydrated = service.hydrateSettings(legacyRaw);
expect(hydrated.show_home_help).toBe(true);
}
));

it("should hydrate Settings with show_home_help set to false", inject(
[SettingsService],
(service: SettingsService) => {
const rawSimple = {
class: "SettingsSimple",
show_home_help: false,
};
const hydratedSimple = service.hydrateSettings(rawSimple);
expect(hydratedSimple.show_home_help).toBe(false);

const rawAdvanced = {
class: "SettingsAdvanced",
show_home_help: false,
active_profile_id: 1,
profiles: [{ profile_id: 1, name: "Default" }],
};
const hydratedAdvanced = service.hydrateSettings(rawAdvanced);
expect(hydratedAdvanced.show_home_help).toBe(false);
}
));
});
10 changes: 10 additions & 0 deletions src/app/settings/settings.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@
Whether to display a 3 character hash of your master password when you enter it, to help you confirm you've typed it correctly.
</p>

<ion-item>
<ion-toggle
name="show_home_help"
formControlName="show_home_help"
[checked]="settingsForm.get('show_home_help')?.value ?? true"
color="primary"
enable-on-off-labels="true"
>Show usage hints</ion-toggle>
</ion-item>

@if (settingsForm.invalid) {
<p class="warning">
<ion-icon name="warning"></ion-icon>
Expand Down
16 changes: 16 additions & 0 deletions src/app/settings/settings.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ describe("SettingsPageComponent", () => {
expect(settingsService.save).toHaveBeenCalled();
});

it("should auto-save settings when show_home_help is toggled", async () => {
const mockSettings = new SettingsSimple();
vi.spyOn(settingsService, "settings").mockReturnValue(mockSettings);
vi.spyOn(settingsService, "getCurrentSettings").mockResolvedValue(mockSettings);
vi.spyOn(settingsService, "save").mockResolvedValue(undefined);

await component.ngOnInit();

// Toggle show_home_help
component.settingsForm.patchValue({ show_home_help: false });

expect(settingsService.save).toHaveBeenCalledWith(
expect.objectContaining({ show_home_help: false })
);
});

it("should not auto-save when form is invalid", async () => {
const mockSettings = new SettingsSimple();
vi.spyOn(settingsService, "getCurrentSettings").mockResolvedValue(
Expand Down
1 change: 1 addition & 0 deletions src/app/settings/settings.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class SettingsPageComponent implements OnInit, OnDestroy {
remember_minutes: [5, Validators.required],
added_number_on: [false],
added_number: [0],
show_home_help: [true],
});
addIcons({
addCircleOutline,
Expand Down
5 changes: 3 additions & 2 deletions src/models/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ export abstract class Settings {

master_password_hash = false;
remember_minutes = 5;
show_home_help = true;

/**
* Properties that are defined directly on the Settings base class (excluding 'class' which is for serialization).
* Update this list whenever new properties are added to the Settings class.
*/
private static readonly COMMON_SETTINGS_PROPERTIES = ['master_password_hash', 'remember_minutes'] as const;
private static readonly COMMON_SETTINGS_PROPERTIES = ['master_password_hash', 'remember_minutes', 'show_home_help'] as const;

abstract getAlgorithm(): 'hmac-sha256' | 'sha256' | 'hmac-sha1' | 'sha1' | 'hmac-md5' | 'md5' | 'hmac-ripemd160' | 'ripemd160';
abstract getLeetLocation(): 'none' | 'before-hashing' | 'after-hashing' | 'both';
Expand All @@ -25,7 +26,7 @@ export abstract class Settings {
abstract getSuffix(): string;
abstract isDomainOnly(): boolean;

getCommonSettingsProperties(): readonly ('master_password_hash' | 'remember_minutes')[] {
getCommonSettingsProperties(): readonly ('master_password_hash' | 'remember_minutes' | 'show_home_help')[] {
return Settings.COMMON_SETTINGS_PROPERTIES;
}
}
3 changes: 3 additions & 0 deletions src/models/SettingsAdvanced.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('SettingsAdvanced', () => {
settingsSimple.output_character_set = '0123456789';
settingsSimple.output_length = 13;
settingsSimple.remember_minutes = 3;
settingsSimple.show_home_help = false;

// This constructor should set up the first profile with ID 1 and set that to be active.
const settingsAdvanced = new SettingsAdvanced(settingsSimple);
Expand All @@ -25,6 +26,7 @@ describe('SettingsAdvanced', () => {
expect(settingsAdvanced.getOutputLength()).toBe(13);
expect(settingsAdvanced.getPostProcessingSuffix()).toBe('4');
expect(settingsAdvanced.remember_minutes).toBe(3);
expect(settingsAdvanced.show_home_help).toBe(false);

// ...and check defaults are as expected
expect(settingsAdvanced.getLeetLevel()).toBe(0);
Expand All @@ -48,6 +50,7 @@ describe('SettingsAdvanced', () => {
expect(settings.getPostProcessingSuffix()).toBe('');
expect(settings.getPrefix()).toBe('');
expect(settings.remember_minutes).toBe(5);
expect(settings.show_home_help).toBe(true);
expect(settings.getSuffix()).toBe('');
expect(settings.isDomainOnly()).toBe(true);
});
Expand Down
1 change: 1 addition & 0 deletions src/models/SettingsSimple.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('SettingsSimple', () => {
expect(settings.getPostProcessingSuffix()).toBe('');
expect(settings.getPrefix()).toBe('');
expect(settings.remember_minutes).toBe(5);
expect(settings.show_home_help).toBe(true);
expect(settings.getSuffix()).toBe('');
expect(settings.isDomainOnly()).toBe(true);
});
Expand Down
Loading