Skip to content

Commit

Permalink
feat(context-menu): remove open preview option (#118)
Browse files Browse the repository at this point in the history
* feat(context-menu): remove open preview option

* chore: empty action bar shouldn't collapse (#115)

* feat: reuse auth token within the same org (#114)

* chore(release): 1.17.0 [skip ci]

# [1.17.0](v1.16.0...v1.17.0) (2024-04-18)

### Features

* reuse auth token within the same org ([#114](#114)) ([a5cae3c](a5cae3c))

* feat: RUM data collection for context menu items (#85)

* chore(release): 1.18.0 [skip ci]

# [1.18.0](v1.17.0...v1.18.0) (2024-04-18)

### Features

* RUM data collection for context menu items ([#85](#85)) ([ed446be](ed446be))

* feat: move sharepoint edit info call from service worker to tab (#116)

* chore(release): 1.19.0 [skip ci]

# [1.19.0](v1.18.0...v1.19.0) (2024-04-18)

### Features

* move sharepoint edit info call from service worker to tab ([#116](#116)) ([d342faf](d342faf))

* chore: remove test again

* chore: use different action

---------

Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
Co-authored-by: Astha Bhargava <asthabhargava001@gmail.com>
  • Loading branch information
3 people authored Apr 18, 2024
1 parent 19e5c11 commit 3464ec1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 48 deletions.
15 changes: 0 additions & 15 deletions src/extension/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
toggleProject,
deleteProject,
isValidProject,
getGitHubSettings,
getProject,
} from './project.js';

Expand Down Expand Up @@ -79,19 +78,6 @@ async function enableDisableProject(tab) {
}
}

/**
* Opens the preview URL of a project based on a GitHub URL
* @param {chrome.tabs.Tab} tab The tab
*/
async function openPreview({ url }) {
const { owner, repo, ref } = getGitHubSettings(url);
if (owner && repo) {
await chrome.tabs.create({
url: `https://${ref}--${repo}--${owner}.hlx.page/`,
});
}
}

/**
* Opens the view document source popup.
* @param {chrome.tabs.Tab} tab The tab
Expand Down Expand Up @@ -132,7 +118,6 @@ export async function checkViewDocSource(id) {
export const internalActions = {
addRemoveProject,
enableDisableProject,
openPreview,
openViewDocSource,
};

Expand Down
11 changes: 1 addition & 10 deletions src/extension/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export async function updateContextMenu({
// clear context menu
await chrome.contextMenus.removeAll();

if (isValidProject(config)) {
if (isValidProject(config) && !url.startsWith(GH_URL)) {
const { owner, repo } = config;
const project = await getProject(`${owner}/${repo}`);
// add/remove project config
Expand All @@ -140,15 +140,6 @@ export async function updateContextMenu({
'action',
],
});
// open preview url
await chrome.contextMenus.create({
id: 'openPreview',
title: chrome.i18n.getMessage('open_preview'),
contexts: [
'action',
],
visible: url.startsWith(GH_URL),
});
}
// open view doc source
if (await guessAEMSite(id)) {
Expand Down
16 changes: 0 additions & 16 deletions test/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,6 @@ describe('Test actions', () => {
expect(set.notCalled).to.be.true;
});

it('internal: openPreview', async () => {
const create = sandbox.spy(chrome.tabs, 'create');
await internalActions.openPreview(mockTab('https://github.com/adobe/blog', {
id: 1,
}));
expect(create.calledWith({
url: 'https://main--blog--adobe.hlx.page/',
})).to.be.true;
// open preview with unsupported url
create.resetHistory();
await internalActions.openPreview(mockTab('https://www.example.com', {
id: 1,
}));
expect(create.called).to.be.false;
});

it('internal: openViewDocSource', async () => {
const { openViewDocSource } = internalActions;
const createSpy = sandbox.spy(chrome.windows, 'create');
Expand Down
30 changes: 23 additions & 7 deletions test/ui.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import sinon from 'sinon';
import chromeMock from './mocks/chrome.js';
import { addProject, getProject, updateProject } from '../src/extension/project.js';
import { setDisplay } from '../src/extension/display.js';
import { internalActions } from '../src/extension/actions.js';
import { error } from './test-utils.js';
import { mockFetchEnvJSONSuccess } from './mocks/helix-admin.js';

Expand Down Expand Up @@ -71,7 +72,14 @@ describe('Test UI: updateContextMenu', () => {
});

it('click listener invokes action', async () => {
expect(clickListener).to.be.a('function');
const openViewDocSourceStub = sinon.stub(internalActions, 'openViewDocSource');
clickListener({
menuItemId: 'openViewDocSource',
}, {
id: 1,
url: 'https://main--blog--adobe.hlx.page/',
});
expect(openViewDocSourceStub.called).to.be.true;
});

it('updateContextMenu: project not added yet', async () => {
Expand All @@ -93,9 +101,8 @@ describe('Test UI: updateContextMenu', () => {
config,
});
expect(removeAllSpy.callCount).to.equal(1);
expect(createSpy.callCount).to.equal(4);
expect(createSpy.callCount).to.equal(3);
expect(createSpy.calledWithMatch({ id: 'enableDisableProject' })).to.be.true;
expect(createSpy.calledWithMatch({ id: 'openPreview' })).to.be.true;
});

it('updateContextMenu: project added and disabled', async () => {
Expand All @@ -106,7 +113,7 @@ describe('Test UI: updateContextMenu', () => {
config,
});
expect(removeAllSpy.callCount).to.equal(1);
expect(createSpy.callCount).to.equal(4);
expect(createSpy.callCount).to.equal(3);
});

it('updateContextMenu: no matching config', async () => {
Expand Down Expand Up @@ -138,7 +145,7 @@ describe('Test UI: updateContextMenu', () => {
config,
});
expect(removeAllSpy.callCount).to.equal(1);
expect(createSpy.callCount).to.equal(3);
expect(createSpy.callCount).to.equal(2);
expect(createSpy.calledWithMatch({ id: 'openViewDocSource' })).to.be.false;
});

Expand All @@ -150,9 +157,18 @@ describe('Test UI: updateContextMenu', () => {
config,
});
expect(removeAllSpy.callCount).to.equal(1);
expect(createSpy.callCount).to.equal(3);
expect(createSpy.callCount).to.equal(2);
expect(createSpy.calledWithMatch({ id: 'openViewDocSource' })).to.be.false;
});

it('updateContextMenu: ignore github url', async () => {
await updateContextMenu({
url: 'https://github.com/foo/bar/',
config,
});
expect(removeAllSpy.callCount).to.equal(1);
expect(createSpy.callCount).to.equal(0);
});
});

describe('Test UI: updateIcon', () => {
Expand Down Expand Up @@ -246,7 +262,7 @@ describe('Test UI: RUM collection when clicked', () => {
it('does nothing without tab url', async () => {
const logs = logSpy.callCount;
clickListener({
menuItemId: 'openPreview',
menuItemId: 'openViewDocSource',
}, {});
await aTimeout(500);
expect(logSpy.callCount).to.equal(logs);
Expand Down

0 comments on commit 3464ec1

Please sign in to comment.