Skip to content

Commit

Permalink
Embed mode url info (#35680)
Browse files Browse the repository at this point in the history
* Hide Story URL info for embedMode=4.

* Impl code.

* embed-mode doc.

* Store service state.
  • Loading branch information
gmajoulet committed Aug 13, 2021
1 parent 07771ad commit 3f065d1
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 8 deletions.
4 changes: 4 additions & 0 deletions extensions/amp-story/1.0/amp-story-store-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export let InteractiveReactData;
* canShowPaginationButtons: boolean,
* canShowPreviousPageHelp: boolean,
* canShowSharingUis: boolean,
* canShowStoryUrlInfo: boolean,
* canShowSystemLayerButtons: boolean,
* viewerCustomControls: !Array<!Object>,
* accessState: boolean,
Expand Down Expand Up @@ -144,6 +145,7 @@ export const StateProperty = {
CAN_SHOW_PAGINATION_BUTTONS: 'canShowPaginationButtons',
CAN_SHOW_PREVIOUS_PAGE_HELP: 'canShowPreviousPageHelp',
CAN_SHOW_SHARING_UIS: 'canShowSharingUis',
CAN_SHOW_STORY_URL_INFO: 'canShowStoryUrlInfo',
CAN_SHOW_SYSTEM_LAYER_BUTTONS: 'canShowSystemLayerButtons',
VIEWER_CUSTOM_CONTROLS: 'viewerCustomControls',

Expand Down Expand Up @@ -590,6 +592,7 @@ export class AmpStoryStoreService {
[StateProperty.CAN_SHOW_PREVIOUS_PAGE_HELP]: true,
[StateProperty.CAN_SHOW_PAGINATION_BUTTONS]: true,
[StateProperty.CAN_SHOW_SHARING_UIS]: true,
[StateProperty.CAN_SHOW_STORY_URL_INFO]: true,
[StateProperty.CAN_SHOW_SYSTEM_LAYER_BUTTONS]: true,
[StateProperty.VIEWER_CUSTOM_CONTROLS]: [],
[StateProperty.ACCESS_STATE]: false,
Expand Down Expand Up @@ -671,6 +674,7 @@ export class AmpStoryStoreService {
return {
[StateProperty.CAN_SHOW_AUDIO_UI]: false,
[StateProperty.CAN_SHOW_SHARING_UIS]: false,
[StateProperty.CAN_SHOW_STORY_URL_INFO]: false,
};
default:
return {};
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-story/1.0/amp-story-system-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ export class SystemLayer {
? new AmpStoryViewerMessagingHandler(this.win_, this.viewer_)
: null;

if (shouldShowStoryUrlInfo(this.viewer_)) {
if (shouldShowStoryUrlInfo(this.viewer_, this.storeService_)) {
this.systemLayerEl_.classList.add('i-amphtml-embedded');
this.getShadowRoot().setAttribute(HAS_INFO_BUTTON_ATTRIBUTE, '');
} else {
Expand Down
5 changes: 4 additions & 1 deletion extensions/amp-story/1.0/amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,10 @@ export class AmpStory extends AMP.BaseElement {
// Preloads and prerenders the share menu.
this.shareMenu_.build();

const infoDialog = shouldShowStoryUrlInfo(devAssert(this.viewer_))
const infoDialog = shouldShowStoryUrlInfo(
devAssert(this.viewer_),
this.storeService_
)
? new InfoDialog(this.win, this.element)
: null;
if (infoDialog) {
Expand Down
1 change: 1 addition & 0 deletions extensions/amp-story/1.0/embed-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const EmbedMode = {
* This differs from the NOT_EMBEDDED embed mode in the following ways:
* - Removes share icon from system layer
* - Removes audio icon from system layer
* - Removes Story URL info from system layer
*/
NO_SHARING_NOR_AUDIO_UI: 4,
};
Expand Down
41 changes: 36 additions & 5 deletions extensions/amp-story/1.0/test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
* limitations under the License.
*/

import {StateProperty} from '../amp-story-store-service';
import {
getRGBFromCssColorValue,
getTextColorForRGB,
shouldShowStoryUrlInfo,
timeStrToMillis,
} from '../utils';

describes.fakeWin('amp-story utils', {}, () => {
describes.fakeWin('amp-story utils', {}, (env) => {
describe('timeStrToMillis', () => {
it('should return millis for a milliseconds string', () => {
const millis = timeStrToMillis('100ms');
Expand Down Expand Up @@ -109,31 +110,61 @@ describes.fakeWin('amp-story utils', {}, () => {
getParam: () => null,
isEmbedded: () => true,
};
expect(shouldShowStoryUrlInfo(fakeViewer)).to.be.true;
const fakeStoreService = {get: () => true};
expect(shouldShowStoryUrlInfo(fakeViewer, fakeStoreService)).to.be.true;
});

it('should be forced to false when isEmbedded', () => {
const fakeViewer = {
getParam: () => '0',
isEmbedded: () => true,
};
expect(shouldShowStoryUrlInfo(fakeViewer)).to.be.false;
const fakeStoreService = {get: () => true};
expect(shouldShowStoryUrlInfo(fakeViewer, fakeStoreService)).to.be.false;
});

it('should be false when !isEmbedded', () => {
const fakeViewer = {
getParam: () => null,
isEmbedded: () => false,
};
expect(shouldShowStoryUrlInfo(fakeViewer)).to.be.false;
const fakeStoreService = {get: () => true};
expect(shouldShowStoryUrlInfo(fakeViewer, fakeStoreService)).to.be.false;
});

it('should be forced to true when !isEmbedded', () => {
const fakeViewer = {
getParam: () => '1',
isEmbedded: () => false,
};
expect(shouldShowStoryUrlInfo(fakeViewer)).to.be.true;
const fakeStoreService = {get: () => true};
expect(shouldShowStoryUrlInfo(fakeViewer, fakeStoreService)).to.be.true;
});

it('should be false when CAN_SHOW_STORY_URL_INFO is false', () => {
const fakeViewer = {
getParam: () => null,
isEmbedded: () => true,
};
const fakeStoreService = {get: () => {}};
const getStub = env.sandbox.stub(fakeStoreService, 'get').returns(false);
expect(shouldShowStoryUrlInfo(fakeViewer, fakeStoreService)).to.be.false;
expect(getStub).to.be.calledOnceWithExactly(
StateProperty.CAN_SHOW_STORY_URL_INFO
);
});

it('should be true when CAN_SHOW_STORY_URL_INFO is true', () => {
const fakeViewer = {
getParam: () => null,
isEmbedded: () => true,
};
const fakeStoreService = {get: () => {}};
const getStub = env.sandbox.stub(fakeStoreService, 'get').returns(true);
expect(shouldShowStoryUrlInfo(fakeViewer, fakeStoreService)).to.be.true;
expect(getStub).to.be.calledOnceWithExactly(
StateProperty.CAN_SHOW_STORY_URL_INFO
);
});
});
});
7 changes: 6 additions & 1 deletion extensions/amp-story/1.0/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import {Services} from '#service';
import {StateProperty} from './amp-story-store-service';
import {
assertHttpsUrl,
getSourceOrigin,
Expand Down Expand Up @@ -252,9 +253,13 @@ export function resolveImgSrc(win, url) {
/**
* Whether a Story should show the URL info dialog.
* @param {!../../../src/service/viewer-interface.ViewerInterface} viewer
* @param {!./amp-story-store-service.AmpStoryStoreService} storeService
* @return {boolean}
*/
export function shouldShowStoryUrlInfo(viewer) {
export function shouldShowStoryUrlInfo(viewer, storeService) {
if (!storeService.get(StateProperty.CAN_SHOW_STORY_URL_INFO)) {
return false;
}
const showStoryUrlInfo = viewer.getParam('showStoryUrlInfo');
return showStoryUrlInfo ? showStoryUrlInfo !== '0' : viewer.isEmbedded();
}
Expand Down

0 comments on commit 3f065d1

Please sign in to comment.