Skip to content

Commit

Permalink
Return void from undoPrehide()
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrej.frei committed Jan 7, 2025
1 parent db3cd9e commit 9660283
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
8 changes: 3 additions & 5 deletions lib/dom-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,11 @@ export class DomActions implements DomActionsProvider {
return hideElements(styleEl, selector, 'opacity');
}

undoPrehide(): boolean {
undoPrehide(): void {
const existingElement = getStyleElement('autoconsent-prehide');
this.autoconsentInstance.config.logs.lifecycle && console.log('[undoprehide]', existingElement, location.href);
if (existingElement) {
existingElement.remove();
}
return !!existingElement;

existingElement.remove();
}

async createOrUpdateStyleSheet(cssText: string, styleSheet?: CSSStyleSheet) {
Expand Down
2 changes: 1 addition & 1 deletion lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface DomActionsProvider {
wait(ms: number): Promise<true>;
hide(selector: string, method: HideMethod): boolean;
prehide(selector: string): boolean;
undoPrehide(): boolean;
undoPrehide(): void;
querySingleReplySelector(selector: string, parent?: any): HTMLElement[];
querySelectorChain(selectors: string[]): HTMLElement[];
elementSelector(selector: ElementSelector): HTMLElement[];
Expand Down
4 changes: 2 additions & 2 deletions lib/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,9 @@ export default class AutoConsent {
return this.domActions.prehide(selectors.join(','));
}

undoPrehide(): boolean {
undoPrehide(): void {
this.updateState({ prehideOn: false });
return this.domActions.undoPrehide();
this.domActions.undoPrehide();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ describe('undoPrehide', () => {
domActions = instantiateDomActions();
});

it('returns false when element does not exist', () => {
it('creates style element if it did not previously exist and immediately removes it', () => {
// Given
expect(document.querySelector('style#autoconsent-prehide')).to.be.null; // check that style element does not yet exist

// When
const result = domActions.undoPrehide();
domActions.undoPrehide();

// Then
expect(result).to.be.false;
expect(document.querySelector('style#autoconsent-prehide')).to.be.null; // check that style element again does not exist (in fact, it was created for a bit and then removed immediately)
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ describe('undoPrehide', () => {
domActions = instantiateDomActions();
});

it('returns true when style element not exist', () => {
it('removes preexisting style element', () => {
// Given
expect(document.querySelector('style#autoconsent-prehide')).to.not.be.null; // check that style element already exists

// When
const result = domActions.undoPrehide();
domActions.undoPrehide();

// Then
expect(result).to.be.true;
expect(document.querySelector('style#autoconsent-prehide')).to.be.null; // check that style element was removed
});
});

0 comments on commit 9660283

Please sign in to comment.