Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/core/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export const show = (createModal) => {
return;

if (!_state._consentModalExists) {
if (createModal) {
if (createModal || _state._invalidConsent) {
createConsentModal(miniAPI, createMainContainer);
} else {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/core/modals/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const createMainContainer = () => {
export const generateHtml = (api) => {
addDataButtonListeners(null, api, createPreferencesModal, createMainContainer);

if (globalObj._state._invalidConsent)
if (globalObj._state._invalidConsent && !globalObj._config.lazyHtmlGeneration)
createConsentModal(api, createMainContainer);

if (!globalObj._config.lazyHtmlGeneration)
Expand Down
24 changes: 24 additions & 0 deletions tests/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,30 @@ describe("Check modals' html generation under different settings", () => {
expect(htmlHasClass('show--consent')).toBe(false);
})

it('Should not generate consent modal markup when autoShow=false and lazyHtmlGeneration=true', async () => {
const prevAutoShow = testConfig.autoShow;
const prevLazyHtmlGeneration = testConfig.lazyHtmlGeneration;

try {
api.eraseCookies('cc_cookie');
testConfig.autoShow = false;
testConfig.lazyHtmlGeneration = true;
await api.run(testConfig);

expect(api.validConsent()).toBe(false);
expect(htmlHasClass('show--consent')).toBe(false);
expect(document.querySelector('#cc-main .cm')).toBeNull();

api.show();

expect(document.querySelector('#cc-main .cm')).toBeInstanceOf(HTMLElement);
expect(htmlHasClass('show--consent')).toBe(true);
} finally {
testConfig.autoShow = prevAutoShow;
testConfig.lazyHtmlGeneration = prevLazyHtmlGeneration;
}
})

it('Plugin should stop if bot is detected', async () => {
setUserAgent(botUserAgent);
testConfig.hideFromBots = true;
Expand Down