Skip to content

Commit

Permalink
Fix #25375: Template Builder Reduce Autosave to 5 Seconds (#25511)
Browse files Browse the repository at this point in the history
* reduce 10 seconds to 5

* add constant

* add backticks to show dynamic debounce time
  • Loading branch information
zJaaal authored and manuelrojas committed Jul 20, 2023
1 parent 683db06 commit 062be66
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Expand Up @@ -29,7 +29,7 @@ import {
processedContainers
} from '@dotcms/utils-testing';

import { DotEditLayoutComponent } from './dot-edit-layout.component';
import { DEBOUNCE_TIME, DotEditLayoutComponent } from './dot-edit-layout.component';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
Expand Down Expand Up @@ -239,7 +239,7 @@ describe('DotEditLayoutComponent', () => {
expect(component.pageState).toEqual(new DotPageRender(mockDotRenderedPage()));
});

it('should save the layout after 10000', fakeAsync(() => {
it(`should save the layout after ${DEBOUNCE_TIME}`, fakeAsync(() => {
const res: DotPageRender = new DotPageRender(mockDotRenderedPage());
spyOn(dotPageLayoutService, 'save').and.returnValue(of(res));

Expand All @@ -249,7 +249,7 @@ describe('DotEditLayoutComponent', () => {
title: null
});

tick(10000);
tick(DEBOUNCE_TIME);
expect(dotGlobalMessageService.loading).toHaveBeenCalledWith('Saving');
expect(dotGlobalMessageService.success).toHaveBeenCalledWith('Saved');
expect(dotGlobalMessageService.error).not.toHaveBeenCalled();
Expand Down Expand Up @@ -307,7 +307,7 @@ describe('DotEditLayoutComponent', () => {
// Destroy the observable
component.destroy$.next(true);
component.destroy$.complete();
tick(10000);
tick(DEBOUNCE_TIME);

expect(dotPageLayoutService.save).not.toHaveBeenCalled();
}));
Expand Down
Expand Up @@ -26,6 +26,8 @@ import {
FeaturedFlags
} from '@dotcms/dotcms-models';

export const DEBOUNCE_TIME = 5000;

@Component({
selector: 'dot-edit-layout',
templateUrl: './dot-edit-layout.component.html',
Expand Down Expand Up @@ -145,7 +147,7 @@ export class DotEditLayoutComponent implements OnInit, OnDestroy {
.pipe(
// debounceTime should be before takeUntil to avoid calling the observable after unsubscribe.
// More information: https://stackoverflow.com/questions/58974320/how-is-it-possible-to-stop-a-debounced-rxjs-observable
debounceTime(10000),
debounceTime(DEBOUNCE_TIME),
takeUntil(this.destroy$),
switchMap((layout: DotTemplateDesigner) => {
this.dotGlobalMessageService.loading(
Expand Down

0 comments on commit 062be66

Please sign in to comment.