Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render preview for regwall, newsletter and survey prompts #3530

Merged
merged 1 commit into from
Jun 18, 2024
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
43 changes: 40 additions & 3 deletions src/runtime/audience-action-flow-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ describes.realWin('AudienceActionIframeFlow', (env) => {
WINDOW_LOCATION_DOMAIN
)}&configurationId=${
configurationId === undefined ? '' : configurationId
}&isClosable=false&calledManually=false`,
}&isClosable=false&calledManually=false&previewEnabled=false`,
{
_client: 'SwG 0.0.0',
productType: ProductType.SUBSCRIPTION,
Expand Down Expand Up @@ -271,7 +271,7 @@ describes.realWin('AudienceActionIframeFlow', (env) => {
sandbox.match((arg) => arg.tagName == 'IFRAME'),
`https://news.google.com/swg/ui/v1/regwalliframe?_=_&origin=${encodeURIComponent(
WINDOW_LOCATION_DOMAIN
)}&configurationId=configId&isClosable=false&calledManually=false&hl=pt-BR`,
)}&configurationId=configId&isClosable=false&calledManually=false&previewEnabled=false&hl=pt-BR`,
{
_client: 'SwG 0.0.0',
productType: ProductType.SUBSCRIPTION,
Expand Down Expand Up @@ -1527,7 +1527,7 @@ describes.realWin('AudienceActionIframeFlow', (env) => {
sandbox.match((arg) => arg.tagName == 'IFRAME'),
`https://news.google.com/swg/ui/v1/surveyiframe?_=_&origin=${encodeURIComponent(
WINDOW_LOCATION_DOMAIN
)}&configurationId=&isClosable=true&calledManually=false`,
)}&configurationId=&isClosable=true&calledManually=false&previewEnabled=false`,
{
_client: 'SwG 0.0.0',
productType: ProductType.SUBSCRIPTION,
Expand All @@ -1542,4 +1542,41 @@ describes.realWin('AudienceActionIframeFlow', (env) => {
activitiesMock.verify();
expect(onCancelSpy).to.not.be.called;
});

it(`opens an AudienceActionIframeFlow and passes shouldRenderPreview in query param`, async () => {
sandbox.stub(runtime.storage(), 'get').resolves(null);
const audienceActionFlow = new AudienceActionIframeFlow(runtime, {
action: 'TYPE_REWARDED_SURVEY',
configurationId: undefined,
onCancel: onCancelSpy,
autoPromptType: AutoPromptType.SUBSCRIPTION,
isClosable: true,
calledManually: false,
shouldRenderPreview: true,
});
const activityIframeViewMock = sandbox.mock(
audienceActionFlow.activityIframeView_
);
activitiesMock
.expects('openIframe')
.withExactArgs(
sandbox.match((arg) => arg.tagName == 'IFRAME'),
`https://news.google.com/swg/ui/v1/surveyiframe?_=_&origin=${encodeURIComponent(
WINDOW_LOCATION_DOMAIN
)}&configurationId=&isClosable=true&calledManually=false&previewEnabled=true`,
{
_client: 'SwG 0.0.0',
productType: ProductType.SUBSCRIPTION,
supportsEventManager: true,
windowHeight: WINDOW_INNER_HEIGHT,
}
)
.resolves(port);

await audienceActionFlow.start();

activitiesMock.verify();
activityIframeViewMock.expects('getElement').once();
expect(onCancelSpy).to.not.be.called;
});
});
9 changes: 9 additions & 0 deletions src/runtime/audience-action-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {Toast} from '../ui/toast';
import {feArgs, feUrl} from './services';
import {msg} from '../utils/i18n';
import {parseUrl} from '../utils/url';
import {setImportantStyles} from '../utils/style';
import {warn} from '../utils/log';

export interface AudienceActionFlow {
Expand All @@ -64,6 +65,7 @@ export interface AudienceActionIframeParams {
onResult?: (result: InterventionResult) => Promise<boolean> | boolean;
isClosable?: boolean;
calledManually: boolean;
shouldRenderPreview?: boolean;
}

// TODO: mhkawano - replace these consts in the project with these
Expand Down Expand Up @@ -124,6 +126,7 @@ export class AudienceActionIframeFlow implements AudienceActionFlow {
'configurationId': this.params_.configurationId || '',
'isClosable': (!!params_.isClosable).toString(),
'calledManually': params_.calledManually.toString(),
'previewEnabled': (!!params_.shouldRenderPreview).toString(),
};
if (this.clientConfigManager_.shouldForceLangInIframes()) {
iframeParams['hl'] = this.clientConfigManager_.getLanguage();
Expand All @@ -139,6 +142,12 @@ export class AudienceActionIframeFlow implements AudienceActionFlow {
}),
/* shouldFadeBody */ true
);
// Disables interaction with prompt if rendering for preview.
if (!!params_.shouldRenderPreview) {
setImportantStyles(this.activityIframeView_.getElement(), {
'pointer-events': 'none',
});
}
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/runtime/auto-prompt-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,7 @@ describes.realWin('AutoPromptManager', (env) => {
autoPromptType: undefined,
isClosable: true,
calledManually: false,
shouldRenderPreview: true,
});
});

Expand Down Expand Up @@ -1728,6 +1729,7 @@ describes.realWin('AutoPromptManager', (env) => {
autoPromptType: AutoPromptType.CONTRIBUTION_LARGE,
isClosable: true,
calledManually: false,
shouldRenderPreview: false,
});
});

Expand Down Expand Up @@ -1763,6 +1765,7 @@ describes.realWin('AutoPromptManager', (env) => {
autoPromptType: AutoPromptType.CONTRIBUTION_LARGE,
isClosable: true,
calledManually: false,
shouldRenderPreview: false,
});
});

Expand Down Expand Up @@ -1806,6 +1809,7 @@ describes.realWin('AutoPromptManager', (env) => {
autoPromptType: AutoPromptType.CONTRIBUTION_LARGE,
isClosable: true,
calledManually: false,
shouldRenderPreview: false,
});
});

Expand Down Expand Up @@ -1859,6 +1863,7 @@ describes.realWin('AutoPromptManager', (env) => {
autoPromptType: AutoPromptType.CONTRIBUTION_LARGE,
isClosable: true,
calledManually: false,
shouldRenderPreview: false,
});
});

Expand Down Expand Up @@ -1922,6 +1927,7 @@ describes.realWin('AutoPromptManager', (env) => {
autoPromptType: AutoPromptType.CONTRIBUTION_LARGE,
isClosable: true,
calledManually: false,
shouldRenderPreview: false,
});
});

Expand Down Expand Up @@ -1957,6 +1963,7 @@ describes.realWin('AutoPromptManager', (env) => {
autoPromptType: AutoPromptType.CONTRIBUTION_LARGE,
isClosable: true,
calledManually: false,
shouldRenderPreview: false,
});
});

Expand Down Expand Up @@ -2011,6 +2018,7 @@ describes.realWin('AutoPromptManager', (env) => {
autoPromptType: AutoPromptType.CONTRIBUTION_LARGE,
isClosable: true,
calledManually: false,
shouldRenderPreview: false,
});
});

Expand Down Expand Up @@ -2076,6 +2084,7 @@ describes.realWin('AutoPromptManager', (env) => {
autoPromptType: AutoPromptType.CONTRIBUTION_LARGE,
isClosable: true,
calledManually: false,
shouldRenderPreview: false,
});
});

Expand Down Expand Up @@ -2151,6 +2160,7 @@ describes.realWin('AutoPromptManager', (env) => {
autoPromptType: AutoPromptType.CONTRIBUTION_LARGE,
isClosable: true,
calledManually: false,
shouldRenderPreview: false,
});
});

Expand Down Expand Up @@ -2491,6 +2501,7 @@ describes.realWin('AutoPromptManager', (env) => {
autoPromptType: AutoPromptType.SUBSCRIPTION_LARGE,
isClosable: false,
calledManually: false,
shouldRenderPreview: false,
});
});

Expand Down Expand Up @@ -2548,6 +2559,7 @@ describes.realWin('AutoPromptManager', (env) => {
autoPromptType: AutoPromptType.SUBSCRIPTION_LARGE,
isClosable: true,
calledManually: false,
shouldRenderPreview: false,
});
});

Expand Down Expand Up @@ -2630,6 +2642,7 @@ describes.realWin('AutoPromptManager', (env) => {
autoPromptType: AutoPromptType.CONTRIBUTION_LARGE,
isClosable: true,
calledManually: false,
shouldRenderPreview: false,
});
});
});
Expand Down
1 change: 1 addition & 0 deletions src/runtime/auto-prompt-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ export class AutoPromptManager {
autoPromptType: this.autoPromptType_,
isClosable: this.isClosable_,
calledManually: false,
shouldRenderPreview: !!this.shouldRenderOnsitePreview_,
});
this.setLastAudienceActionFlow(audienceActionFlow);
audienceActionFlow.start();
Expand Down
Loading