Skip to content
Prev Previous commit
Next Next commit
Removed console.log, new test
  • Loading branch information
mszylkowski committed Dec 13, 2021
commit 89d197bd76f88f684ee8eaeac926563836cee953
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ export class ShareMenu {
* @private
*/
close_() {
console.log('close');
this.storeService_.dispatch(Action.TOGGLE_SHARE_MENU, false);
}

Expand Down
29 changes: 28 additions & 1 deletion extensions/amp-story/1.0/test/test-amp-story-share-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {
VISIBLE_CLASS,
} from '../../../amp-story-share-menu/0.1/amp-story-share-menu';
import {ShareWidget} from '../amp-story-share';
import {registerServiceBuilder} from '../../../../src/service-helpers';
import {
getAmpdoc,
registerServiceBuilder,
} from '../../../../src/service-helpers';

describes.realWin('amp-story-share-menu', {amp: true}, (env) => {
let isSystemShareSupported;
Expand Down Expand Up @@ -162,6 +165,7 @@ describes.realWin('amp-story-share-menu', {amp: true}, (env) => {
it('should close back the share menu right away if system share', () => {
isSystemShareSupported = true;

// Simulate native sharing.
win.navigator.share = () => Promise.resolve();

shareMenu.build();
Expand All @@ -170,4 +174,27 @@ describes.realWin('amp-story-share-menu', {amp: true}, (env) => {

expect(storeService.get(StateProperty.SHARE_MENU_STATE)).to.be.false;
});

it('should share natively if available with the canonical url and window title', () => {
isSystemShareSupported = true;

// Simulate native sharing.
win.navigator.share = () => Promise.resolve();
const shareSpy = env.sandbox.spy(win.navigator, 'share');

// Set canonicalUrl and window title for sharing.
env.sandbox
.stub(Services, 'documentInfoForDoc')
.returns({canonicalUrl: 'https://amp.dev'});
win.document.title = 'AMP';

shareMenu.build();

storeService.dispatch(Action.TOGGLE_SHARE_MENU, true);

expect(shareSpy).to.be.calledWith({
url: 'https://amp.dev',
text: 'AMP',
});
});
});