Browse Source

Fix remember me.

pull/613/head
Sebastian 5 years ago
parent
commit
7b0f27ebb3
  1. 2
      backend/i18n/frontend_en.json
  2. 2
      backend/i18n/source/frontend_en.json
  3. 57
      frontend/app/framework/services/dialog.service.spec.ts
  4. 10
      frontend/app/framework/services/dialog.service.ts

2
backend/i18n/frontend_en.json

@ -297,7 +297,7 @@
"common.queryOperators.ne": "is not equals to",
"common.queryOperators.startsWith": "starts with",
"common.refresh": "Refresh",
"common.remember": "Remember my decision",
"common.remember": "Don't ask again",
"common.rename": "Rename",
"common.requiredHint": "required",
"common.reset": "Reset",

2
backend/i18n/source/frontend_en.json

@ -297,7 +297,7 @@
"common.queryOperators.ne": "is not equals to",
"common.queryOperators.startsWith": "starts with",
"common.refresh": "Refresh",
"common.remember": "Remember my decision",
"common.remember": "Don't ask again",
"common.rename": "Rename",
"common.requiredHint": "required",
"common.reset": "Reset",

57
frontend/app/framework/services/dialog.service.spec.ts

@ -79,10 +79,13 @@ describe('DialogService', () => {
dialog.complete(confirmed);
});
dialogService.confirm('MyTitle', 'MyText').subscribe(result => {
isNext = result;
}, undefined, () => {
isCompleted = true;
dialogService.confirm('MyTitle', 'MyText').subscribe({
next: result => {
isNext = result;
},
complete: () => {
isCompleted = true;
}
});
expect(isCompleted).toBeTruthy();
@ -93,10 +96,10 @@ describe('DialogService', () => {
});
[
{ confirmed: true, saved: 1 },
{ confirmed: false, saved: 2 }
{ confirmed: true, saved: 1 },
{ confirmed: false, saved: 0 }
].map(({ confirmed, saved }) => {
it(`should confirm dialog with '${confirmed}' and remember when remembered`, () => {
it(`should confirm dialog with '${confirmed}' and remember when remembered and confirmed`, () => {
const dialogService = new DialogService(localStore.object);
let isCompleted = false;
@ -107,47 +110,53 @@ describe('DialogService', () => {
dialog.complete(confirmed);
});
dialogService.confirm('MyTitle', 'MyText', 'MyKey').subscribe(result => {
isNext = result;
}, undefined, () => {
isCompleted = true;
dialogService.confirm('MyTitle', 'MyText', 'MyKey').subscribe({
next: result => {
isNext = result;
},
complete: () => {
isCompleted = true;
}
});
expect(isCompleted).toBeTruthy();
expect(isNext!).toEqual(confirmed);
localStore.verify(x => x.setInt(`dialogs.confirm.MyKey`, saved), Times.once());
localStore.verify(x => x.setBoolean(`dialogs.confirm.MyKey`, It.isAny()), Times.exactly(saved));
});
});
[
{ confirmed: true, saved: 1 },
{ confirmed: false, saved: 2 }
].map(({ confirmed, saved }) => {
{ confirmed: true, saved: true, render: 0 },
{ confirmed: false, saved: false, render: 1 }
].map(({ confirmed, saved, render }) => {
it(`should confirm dialog with '${confirmed}' from local store when saved`, () => {
const dialogService = new DialogService(localStore.object);
localStore.setup(x => x.getInt(`dialogs.confirm.MyKey`))
localStore.setup(x => x.getBoolean(`dialogs.confirm.MyKey`))
.returns(() => saved);
let requestCount = 0;
let isCompleted = false;
let isNext: boolean;
let isNext: boolean | undefined;
dialogService.dialogs.subscribe(_ => {
requestCount++;
});
dialogService.confirm('MyTitle', 'MyText', 'MyKey').subscribe(result => {
isNext = result;
}, undefined, () => {
isCompleted = true;
dialogService.confirm('MyTitle', 'MyText', 'MyKey').subscribe({
next: result => {
isNext = result;
},
complete: () => {
isCompleted = true;
}
});
expect(isCompleted).toBeTruthy();
expect(isNext!).toEqual(confirmed);
expect(requestCount).toEqual(0);
expect(isCompleted).toEqual(confirmed);
expect(isNext).toEqual(confirmed ? true : undefined);
expect(requestCount).toEqual(render);
});
});

10
frontend/app/framework/services/dialog.service.ts

@ -41,18 +41,18 @@ export class DialogRequest {
if (rememberKey) {
this.rememberKey = `dialogs.confirm.${rememberKey}`;
const isConfirmed = this.localStore.getInt(this.rememberKey);
const isConfirmed = this.localStore.getBoolean(this.rememberKey);
if (isConfirmed > 0) {
this.resultStream$.next(isConfirmed === 1);
if (isConfirmed) {
this.resultStream$.next(true);
this.resultStream$.complete();
}
}
}
public complete(confirmed: boolean) {
if (this.rememberKey && this.remember) {
this.localStore.setInt(this.rememberKey, confirmed ? 1 : 2);
if (this.rememberKey && this.remember && confirmed) {
this.localStore.setBoolean(this.rememberKey, true);
}
this.resultStream$.next(confirmed);

Loading…
Cancel
Save