Bug 1557874 - Convert link menu strings in New Tab to use fluent (#5104)
* Bug 1557874 - Convert link menu strings in New Tab to use fluent * Bug 1557874 - Updating fluent strings for pocket cards * Bug 1557874 - Context Menu platform strings migrated to fluent * Bug 1557874 - Pocket brand name added to fluent strings * Bug 1557874 - Fluent changes related to the section menu and area. * Reverting some changes to resolve screen reader changes made in PR #5099 * Bug 1557874 - Updated SectionMenu and LinkMenu test cases * Minor fixes to clean PR * Bug 1557874 - Fixed mochi tests and .py linting errors * Parsing fix.... * Resolving feedback related to condensing data-l10n-id usage * Fixed failed test case reading intlID instead of fluentID
This commit is contained in:
Родитель
b2a197b8c4
Коммит
87be373122
|
@ -4,10 +4,10 @@
|
|||
# http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
from __future__ import absolute_import
|
||||
# import fluent.syntax.ast as FTL
|
||||
import fluent.syntax.ast as FTL
|
||||
from fluent.migrate.helpers import transforms_from
|
||||
# from fluent.migrate.helpers import MESSAGE_REFERENCE, TERM_REFERENCE
|
||||
# from fluent.migrate import COPY, CONCAT, REPLACE
|
||||
from fluent.migrate.helpers import TERM_REFERENCE, VARIABLE_REFERENCE
|
||||
from fluent.migrate import REPLACE
|
||||
|
||||
TARGET_FILE = 'browser/browser/newtab/newtab.ftl'
|
||||
SOURCE_FILE = TARGET_FILE
|
||||
|
@ -83,13 +83,13 @@ newtab-topsites-url-label = { COPY(from_path, "topsites_form_url_label") }
|
|||
newtab-topsites-url-input =
|
||||
.placeholder = { COPY(from_path, "topsites_form_url_placeholder") }
|
||||
newtab-topsites-url-validation = { COPY(from_path, "topsites_form_url_validation") }
|
||||
newtab-topsites-delete-history-button = { COPY(from_path, "menu_action_delete") }
|
||||
|
||||
newtab-topsites-image-url-label = { COPY(from_path, "topsites_form_image_url_label") }
|
||||
newtab-topsites-use-image-link = { COPY(from_path, "topsites_form_use_image_link") }
|
||||
newtab-topsites-image-validation = { COPY(from_path, "topsites_form_image_validation") }
|
||||
|
||||
newtab-topsites-cancel-button = { COPY(from_path, "topsites_form_cancel_button") }
|
||||
newtab-topsites-delete-history-button = { COPY(from_path, "menu_action_delete") }
|
||||
newtab-topsites-save-button = { COPY(from_path, "topsites_form_save_button") }
|
||||
newtab-topsites-preview-button = { COPY(from_path, "topsites_form_preview_button") }
|
||||
newtab-topsites-add-button = { COPY(from_path, "topsites_form_add_button") }
|
||||
|
@ -98,6 +98,110 @@ newtab-confirm-delete-history-p1 = { COPY(from_path, "confirm_history_delete_p1"
|
|||
newtab-confirm-delete-history-p2 = { COPY(from_path, "confirm_history_delete_notice_p2") }
|
||||
|
||||
newtab-topsites-add-search-engine = { COPY(from_path, "section_menu_action_add_search_engine") }
|
||||
newtab-topsites-tooltip =
|
||||
.title = { COPY(from_path, "context_menu_title") }
|
||||
newtab-topsites-placeholder-tooltip =
|
||||
.title = { COPY(from_path, "edit_topsites_edit_button") }
|
||||
|
||||
newtab-menu-edit-topsites = { COPY(from_path, "edit_topsites_button_text") }
|
||||
newtab-menu-open-new-window = { COPY(from_path, "menu_action_open_new_window") }
|
||||
newtab-menu-open-new-private-window = { COPY(from_path, "menu_action_open_private_window") }
|
||||
newtab-menu-dismiss = { COPY(from_path, "menu_action_dismiss") }
|
||||
newtab-menu-pin = { COPY(from_path, "menu_action_pin") }
|
||||
newtab-menu-unpin = { COPY(from_path, "menu_action_unpin") }
|
||||
newtab-menu-delete-history = { COPY(from_path, "menu_action_delete") }
|
||||
newtab-menu-remove-bookmark = { COPY(from_path, "menu_action_remove_bookmark") }
|
||||
newtab-menu-bookmark = { COPY(from_path, "menu_action_bookmark") }
|
||||
|
||||
newtab-menu-copy-download-link = { COPY(from_path, "menu_action_copy_download_link") }
|
||||
newtab-menu-go-to-download-page = { COPY(from_path, "menu_action_go_to_download_page") }
|
||||
newtab-menu-remove-download = { COPY(from_path, "menu_action_remove_download") }
|
||||
|
||||
|
||||
newtab-menu-show-file =
|
||||
{ PLATFORM() ->
|
||||
[macos] { COPY(from_path, "menu_action_show_file_mac_os") }
|
||||
[windows] { COPY(from_path, "menu_action_show_file_windows") }
|
||||
[linux] { COPY(from_path, "menu_action_show_file_linux") }
|
||||
*[other] { COPY(from_path, "menu_action_show_file_default") }
|
||||
}
|
||||
newtab-menu-open-file = { COPY(from_path, "menu_action_open_file") }
|
||||
|
||||
newtab-card-tooltip =
|
||||
.title = { COPY(from_path, "context_menu_title") }
|
||||
newtab-label-visited = { COPY(from_path, "type_label_visited") }
|
||||
newtab-label-bookmarked = { COPY(from_path, "type_label_bookmarked") }
|
||||
newtab-label-recommended = { COPY(from_path, "type_label_recommended") }
|
||||
newtab-label-download = { COPY(from_path, "type_label_downloaded") }
|
||||
|
||||
newtab-section-menu-remove-section = { COPY(from_path, "section_menu_action_remove_section") }
|
||||
newtab-section-menu-collapse-section = { COPY(from_path, "section_menu_action_collapse_section") }
|
||||
newtab-section-menu-expand-section = { COPY(from_path, "section_menu_action_expand_section") }
|
||||
newtab-section-menu-manage-section = { COPY(from_path, "section_menu_action_manage_section") }
|
||||
newtab-section-menu-manage-webext = { COPY(from_path, "section_menu_action_manage_webext") }
|
||||
newtab-section-menu-add-topsite = { COPY(from_path, "section_menu_action_add_topsite") }
|
||||
newtab-section-menu-add-search-engine =
|
||||
{ COPY(from_path, "section_menu_action_add_search_engine") }
|
||||
newtab-section-menu-move-up = { COPY(from_path, "section_menu_action_move_up") }
|
||||
newtab-section-menu-move-down = { COPY(from_path, "section_menu_action_move_down") }
|
||||
newtab-section-menu-privacy-notice = { COPY(from_path, "section_menu_action_privacy_notice") }
|
||||
newtab-empty-section-highlights = { COPY(from_path, "highlights_empty_state") }
|
||||
|
||||
""", from_path='browser/chrome/browser/activity-stream/newtab.properties')
|
||||
),
|
||||
ctx.add_transforms(
|
||||
TARGET_FILE,
|
||||
SOURCE_FILE,
|
||||
[
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("newtab-menu-save-to-pocket"),
|
||||
value=REPLACE(
|
||||
"browser/chrome/browser/activity-stream/newtab.properties",
|
||||
"menu_action_save_to_pocket",
|
||||
{
|
||||
"Pocket": TERM_REFERENCE("pocket-brand-name")
|
||||
},
|
||||
)
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("newtab-menu-archive-pocket"),
|
||||
value=REPLACE(
|
||||
"browser/chrome/browser/activity-stream/newtab.properties",
|
||||
"menu_action_archive_pocket",
|
||||
{
|
||||
"Pocket": TERM_REFERENCE("pocket-brand-name")
|
||||
},
|
||||
)
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("newtab-menu-delete-pocket"),
|
||||
value=REPLACE(
|
||||
"browser/chrome/browser/activity-stream/newtab.properties",
|
||||
"menu_action_delete_pocket",
|
||||
{
|
||||
"Pocket": TERM_REFERENCE("pocket-brand-name")
|
||||
},
|
||||
)
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("newtab-label-saved"),
|
||||
value=REPLACE(
|
||||
"browser/chrome/browser/activity-stream/newtab.properties",
|
||||
"type_label_pocket",
|
||||
{
|
||||
"Pocket": TERM_REFERENCE("pocket-brand-name")
|
||||
},
|
||||
)
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("newtab-empty-section-topstories"),
|
||||
value=REPLACE(
|
||||
"browser/chrome/browser/activity-stream/newtab.properties",
|
||||
"topstories_empty_state",
|
||||
{
|
||||
"{provider}": VARIABLE_REFERENCE("provider")
|
||||
},
|
||||
)
|
||||
),
|
||||
]
|
||||
)
|
||||
|
|
|
@ -88,6 +88,7 @@ function templateHTML(options) {
|
|||
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; object-src 'none'; script-src resource: chrome:; connect-src https:; img-src https: data: blob:; style-src 'unsafe-inline';">
|
||||
<title data-l10n-id="newtab-page-title"></title>
|
||||
<link rel="icon" type="image/png" href="chrome://branding/content/icon32.png"/>
|
||||
<link rel="localization" href="browser/branding/brandings.ftl" />
|
||||
<link rel="localization" href="browser/newtab/newtab.ftl" />
|
||||
<link rel="stylesheet" href="chrome://browser/content/contentSearchUI.css" />
|
||||
<link rel="stylesheet" href="${options.baseUrl}css/activity-stream.css" />
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import {actionCreators as ac, actionTypes as at} from "common/Actions.jsm";
|
||||
import {FormattedMessage, injectIntl} from "react-intl";
|
||||
import {cardContextTypes} from "./types";
|
||||
import {connect} from "react-redux";
|
||||
import {GetPlatformString} from "content-src/lib/link-menu-options";
|
||||
import {injectIntl} from "react-intl";
|
||||
import {LinkMenu} from "content-src/components/LinkMenu/LinkMenu";
|
||||
import React from "react";
|
||||
import {ScreenshotUtils} from "content-src/lib/screenshot-utils";
|
||||
|
@ -203,7 +202,7 @@ export class _Card extends React.PureComponent {
|
|||
const title = link.title || link.hostname;
|
||||
const isContextMenuOpen = this.state.showContextMenu && this.state.activeCard === index;
|
||||
// Display "now" as "trending" until we have new strings #3402
|
||||
const {icon, intlID} = cardContextTypes[link.type === "now" ? "trending" : link.type] || {};
|
||||
const {icon, fluentID} = cardContextTypes[link.type === "now" ? "trending" : link.type] || {};
|
||||
const hasImage = this.state.cardImage || link.hasImage;
|
||||
const imageStyle = {backgroundImage: this.state.cardImage ? `url(${this.state.cardImage.url})` : "none"};
|
||||
const outerClassName = [
|
||||
|
@ -222,7 +221,7 @@ export class _Card extends React.PureComponent {
|
|||
}
|
||||
</div>
|
||||
<div className="card-details">
|
||||
{link.type === "download" && <div className="card-host-name alternate"><FormattedMessage id={GetPlatformString(this.props.platform)} /></div>}
|
||||
{link.type === "download" && <div className="card-host-name alternate" data-l10n-id="newtab-menu-show-file" />}
|
||||
{link.hostname &&
|
||||
<div className="card-host-name">
|
||||
{link.hostname.slice(0, 100)}{link.type === "download" && ` \u2014 ${link.description}`}
|
||||
|
@ -240,7 +239,7 @@ export class _Card extends React.PureComponent {
|
|||
<div className="card-context">
|
||||
{icon && !link.context && <span aria-haspopup="true" className={`card-context-icon icon icon-${icon}`} />}
|
||||
{link.icon && link.context && <span aria-haspopup="true" className="card-context-icon icon" style={{backgroundImage: `url('${link.icon}')`}} />}
|
||||
{intlID && !link.context && <div className="card-context-label"><FormattedMessage id={intlID} defaultMessage="Visited" /></div>}
|
||||
{fluentID && !link.context && <div className="card-context-label" data-l10n-id={fluentID} />}
|
||||
{link.context && <div className="card-context-label">{link.context}</div>}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,26 +1,22 @@
|
|||
export const cardContextTypes = {
|
||||
history: {
|
||||
intlID: "type_label_visited",
|
||||
fluentID: "newtab-label-visited",
|
||||
icon: "history-item",
|
||||
},
|
||||
bookmark: {
|
||||
intlID: "type_label_bookmarked",
|
||||
fluentID: "newtab-label-bookmarked",
|
||||
icon: "bookmark-added",
|
||||
},
|
||||
trending: {
|
||||
intlID: "type_label_recommended",
|
||||
fluentID: "newtab-label-recommended",
|
||||
icon: "trending",
|
||||
},
|
||||
now: {
|
||||
intlID: "type_label_now",
|
||||
icon: "now",
|
||||
},
|
||||
pocket: {
|
||||
intlID: "type_label_pocket",
|
||||
fluentID: "newtab-label-saved",
|
||||
icon: "pocket",
|
||||
},
|
||||
download: {
|
||||
intlID: "type_label_downloaded",
|
||||
fluentID: "newtab-label-download",
|
||||
icon: "download",
|
||||
},
|
||||
};
|
||||
|
|
|
@ -116,7 +116,7 @@ export class ContextMenuItem extends React.PureComponent {
|
|||
<li role="menuitem" className="context-menu-item" >
|
||||
<button className={option.disabled ? "disabled" : ""} tabIndex="0" onClick={this.onClick} onKeyDown={this.onKeyDown} ref={option.first ? this.focusFirst : null}>
|
||||
{option.icon && <span className={`icon icon-spacer icon-${option.icon}`} />}
|
||||
{option.label}
|
||||
<span data-l10n-id={option.string_id || option.id} />
|
||||
</button>
|
||||
</li>);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import {actionCreators as ac} from "common/Actions.jsm";
|
||||
import {connect} from "react-redux";
|
||||
import {ContextMenu} from "content-src/components/ContextMenu/ContextMenu";
|
||||
import {injectIntl} from "react-intl";
|
||||
import {LinkMenuOptions} from "content-src/lib/link-menu-options";
|
||||
import React from "react";
|
||||
|
||||
|
@ -16,9 +15,8 @@ export class _LinkMenu extends React.PureComponent {
|
|||
const propOptions = (!site.isDefault || site.searchTopSite) ? props.options : DEFAULT_SITE_MENU_OPTIONS;
|
||||
|
||||
const options = propOptions.map(o => LinkMenuOptions[o](site, index, source, isPrivateBrowsingEnabled, siteInfo, platform)).map(option => {
|
||||
const {action, impression, id, string_id, type, userEvent} = option;
|
||||
const {action, impression, id, type, userEvent} = option;
|
||||
if (!type && id) {
|
||||
option.label = props.intl.formatMessage({id: string_id || id});
|
||||
option.onClick = () => {
|
||||
props.dispatch(action);
|
||||
if (userEvent) {
|
||||
|
@ -54,4 +52,4 @@ export class _LinkMenu extends React.PureComponent {
|
|||
}
|
||||
|
||||
const getState = state => ({isPrivateBrowsingEnabled: state.Prefs.values.isPrivateBrowsingEnabled, platform: state.Prefs.values.platform});
|
||||
export const LinkMenu = connect(getState)(injectIntl(_LinkMenu));
|
||||
export const LinkMenu = connect(getState)(_LinkMenu);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import {actionCreators as ac} from "common/Actions.jsm";
|
||||
import {ContextMenu} from "content-src/components/ContextMenu/ContextMenu";
|
||||
import {injectIntl} from "react-intl";
|
||||
import React from "react";
|
||||
import {SectionMenuOptions} from "content-src/lib/section-menu-options";
|
||||
|
||||
|
@ -28,7 +27,6 @@ export class _SectionMenu extends React.PureComponent {
|
|||
const options = propOptions.map(o => SectionMenuOptions[o](props)).map(option => {
|
||||
const {action, id, type, userEvent} = option;
|
||||
if (!type && id) {
|
||||
option.label = props.intl.formatMessage({id});
|
||||
option.onClick = () => {
|
||||
props.dispatch(action);
|
||||
if (userEvent) {
|
||||
|
@ -57,4 +55,4 @@ export class _SectionMenu extends React.PureComponent {
|
|||
}
|
||||
}
|
||||
|
||||
export const SectionMenu = injectIntl(_SectionMenu);
|
||||
export const SectionMenu = _SectionMenu;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import {actionCreators as ac, actionTypes as at} from "common/Actions.jsm";
|
||||
import {Card, PlaceholderCard} from "content-src/components/Card/Card";
|
||||
import {FormattedMessage, injectIntl} from "react-intl";
|
||||
import {CollapsibleSection} from "content-src/components/CollapsibleSection/CollapsibleSection";
|
||||
import {ComponentPerfTimer} from "content-src/components/ComponentPerfTimer/ComponentPerfTimer";
|
||||
import {connect} from "react-redux";
|
||||
|
@ -16,7 +15,15 @@ const CARDS_PER_ROW_DEFAULT = 3;
|
|||
const CARDS_PER_ROW_COMPACT_WIDE = 4;
|
||||
|
||||
function getFormattedMessage(message) {
|
||||
return typeof message === "string" ? <span>{message}</span> : <FormattedMessage {...message} />;
|
||||
return typeof message === "string" ? (
|
||||
<span>{message}</span>
|
||||
) : (
|
||||
<span
|
||||
data-l10n-id={message.id}
|
||||
data-l10n-args={
|
||||
!message.values ? "{}" : `{ "provider": "${message.values.provider}" }`
|
||||
} />
|
||||
);
|
||||
}
|
||||
|
||||
export class Section extends React.PureComponent {
|
||||
|
@ -279,7 +286,7 @@ Section.defaultProps = {
|
|||
title: "",
|
||||
};
|
||||
|
||||
export const SectionIntl = connect(state => ({Prefs: state.Prefs, Pocket: state.Pocket}))(injectIntl(Section));
|
||||
export const SectionIntl = connect(state => ({Prefs: state.Prefs, Pocket: state.Pocket}))(Section);
|
||||
|
||||
export class _Sections extends React.PureComponent {
|
||||
renderSections() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {actionCreators as ac, actionTypes as at} from "common/Actions.jsm";
|
||||
|
||||
const _OpenInPrivateWindow = site => ({
|
||||
id: "menu_action_open_private_window",
|
||||
id: "newtab-menu-open-new-private-window",
|
||||
icon: "new-window-private",
|
||||
action: ac.OnlyToMain({
|
||||
type: at.OPEN_PRIVATE_WINDOW,
|
||||
|
@ -10,19 +10,6 @@ const _OpenInPrivateWindow = site => ({
|
|||
userEvent: "OPEN_PRIVATE_WINDOW",
|
||||
});
|
||||
|
||||
export const GetPlatformString = platform => {
|
||||
switch (platform) {
|
||||
case "win":
|
||||
return "menu_action_show_file_windows";
|
||||
case "macosx":
|
||||
return "menu_action_show_file_mac_os";
|
||||
case "linux":
|
||||
return "menu_action_show_file_linux";
|
||||
default:
|
||||
return "menu_action_show_file_default";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* List of functions that return items that can be included as menu options in a
|
||||
* LinkMenu. All functions take the site as the first parameter, and optionally
|
||||
|
@ -32,7 +19,7 @@ export const LinkMenuOptions = {
|
|||
Separator: () => ({type: "separator"}),
|
||||
EmptyItem: () => ({type: "empty"}),
|
||||
RemoveBookmark: site => ({
|
||||
id: "menu_action_remove_bookmark",
|
||||
id: "newtab-menu-remove-bookmark",
|
||||
icon: "bookmark-added",
|
||||
action: ac.AlsoToMain({
|
||||
type: at.DELETE_BOOKMARK_BY_ID,
|
||||
|
@ -41,7 +28,7 @@ export const LinkMenuOptions = {
|
|||
userEvent: "BOOKMARK_DELETE",
|
||||
}),
|
||||
AddBookmark: site => ({
|
||||
id: "menu_action_bookmark",
|
||||
id: "newtab-menu-bookmark",
|
||||
icon: "bookmark-hollow",
|
||||
action: ac.AlsoToMain({
|
||||
type: at.BOOKMARK_URL,
|
||||
|
@ -50,7 +37,7 @@ export const LinkMenuOptions = {
|
|||
userEvent: "BOOKMARK_ADD",
|
||||
}),
|
||||
OpenInNewWindow: site => ({
|
||||
id: "menu_action_open_new_window",
|
||||
id: "newtab-menu-open-new-window",
|
||||
icon: "new-window",
|
||||
action: ac.AlsoToMain({
|
||||
type: at.OPEN_NEW_WINDOW,
|
||||
|
@ -63,7 +50,7 @@ export const LinkMenuOptions = {
|
|||
userEvent: "OPEN_NEW_WINDOW",
|
||||
}),
|
||||
BlockUrl: (site, index, eventSource) => ({
|
||||
id: "menu_action_dismiss",
|
||||
id: "newtab-menu-dismiss",
|
||||
icon: "dismiss",
|
||||
action: ac.AlsoToMain({
|
||||
type: at.BLOCK_URL,
|
||||
|
@ -85,7 +72,7 @@ export const LinkMenuOptions = {
|
|||
// memory and notify the web extenion, rather than using the built-in block list.
|
||||
WebExtDismiss: (site, index, eventSource) => ({
|
||||
id: "menu_action_webext_dismiss",
|
||||
string_id: "menu_action_dismiss",
|
||||
string_id: "newtab-menu-dismiss",
|
||||
icon: "dismiss",
|
||||
action: ac.WebExtEvent(at.WEBEXT_DISMISS, {
|
||||
source: eventSource,
|
||||
|
@ -94,7 +81,7 @@ export const LinkMenuOptions = {
|
|||
}),
|
||||
}),
|
||||
DeleteUrl: (site, index, eventSource, isEnabled, siteInfo) => ({
|
||||
id: "menu_action_delete",
|
||||
id: "newtab-menu-delete-history",
|
||||
icon: "delete",
|
||||
action: {
|
||||
type: at.DIALOG_OPEN,
|
||||
|
@ -112,8 +99,8 @@ export const LinkMenuOptions = {
|
|||
},
|
||||
userEvent: "DIALOG_OPEN",
|
||||
}),
|
||||
ShowFile: (site, index, eventSource, isEnabled, siteInfo, platform) => ({
|
||||
id: GetPlatformString(platform),
|
||||
ShowFile: site => ({
|
||||
id: "newtab-menu-show-file",
|
||||
icon: "search",
|
||||
action: ac.OnlyToMain({
|
||||
type: at.SHOW_DOWNLOAD_FILE,
|
||||
|
@ -121,7 +108,7 @@ export const LinkMenuOptions = {
|
|||
}),
|
||||
}),
|
||||
OpenFile: site => ({
|
||||
id: "menu_action_open_file",
|
||||
id: "newtab-menu-open-file",
|
||||
icon: "open-file",
|
||||
action: ac.OnlyToMain({
|
||||
type: at.OPEN_DOWNLOAD_FILE,
|
||||
|
@ -129,7 +116,7 @@ export const LinkMenuOptions = {
|
|||
}),
|
||||
}),
|
||||
CopyDownloadLink: site => ({
|
||||
id: "menu_action_copy_download_link",
|
||||
id: "newtab-menu-copy-download-link",
|
||||
icon: "copy",
|
||||
action: ac.OnlyToMain({
|
||||
type: at.COPY_DOWNLOAD_LINK,
|
||||
|
@ -137,7 +124,7 @@ export const LinkMenuOptions = {
|
|||
}),
|
||||
}),
|
||||
GoToDownloadPage: site => ({
|
||||
id: "menu_action_go_to_download_page",
|
||||
id: "newtab-menu-go-to-download-page",
|
||||
icon: "download",
|
||||
action: ac.OnlyToMain({
|
||||
type: at.OPEN_LINK,
|
||||
|
@ -146,7 +133,7 @@ export const LinkMenuOptions = {
|
|||
disabled: !site.referrer,
|
||||
}),
|
||||
RemoveDownload: site => ({
|
||||
id: "menu_action_remove_download",
|
||||
id: "newtab-menu-remove-download",
|
||||
icon: "delete",
|
||||
action: ac.OnlyToMain({
|
||||
type: at.REMOVE_DOWNLOAD_FILE,
|
||||
|
@ -154,7 +141,7 @@ export const LinkMenuOptions = {
|
|||
}),
|
||||
}),
|
||||
PinTopSite: ({url, searchTopSite, label}, index) => ({
|
||||
id: "menu_action_pin",
|
||||
id: "newtab-menu-pin",
|
||||
icon: "pin",
|
||||
action: ac.AlsoToMain({
|
||||
type: at.TOP_SITES_PIN,
|
||||
|
@ -169,7 +156,7 @@ export const LinkMenuOptions = {
|
|||
userEvent: "PIN",
|
||||
}),
|
||||
UnpinTopSite: site => ({
|
||||
id: "menu_action_unpin",
|
||||
id: "newtab-menu-unpin",
|
||||
icon: "unpin",
|
||||
action: ac.AlsoToMain({
|
||||
type: at.TOP_SITES_UNPIN,
|
||||
|
@ -178,7 +165,7 @@ export const LinkMenuOptions = {
|
|||
userEvent: "UNPIN",
|
||||
}),
|
||||
SaveToPocket: (site, index, eventSource) => ({
|
||||
id: "menu_action_save_to_pocket",
|
||||
id: "newtab-menu-save-to-pocket",
|
||||
icon: "pocket-save",
|
||||
action: ac.AlsoToMain({
|
||||
type: at.SAVE_TO_POCKET,
|
||||
|
@ -196,7 +183,7 @@ export const LinkMenuOptions = {
|
|||
userEvent: "SAVE_TO_POCKET",
|
||||
}),
|
||||
DeleteFromPocket: site => ({
|
||||
id: "menu_action_delete_pocket",
|
||||
id: "newtab-menu-delete-pocket",
|
||||
icon: "pocket-delete",
|
||||
action: ac.AlsoToMain({
|
||||
type: at.DELETE_FROM_POCKET,
|
||||
|
@ -205,7 +192,7 @@ export const LinkMenuOptions = {
|
|||
userEvent: "DELETE_FROM_POCKET",
|
||||
}),
|
||||
ArchiveFromPocket: site => ({
|
||||
id: "menu_action_archive_pocket",
|
||||
id: "newtab-menu-archive-pocket",
|
||||
icon: "pocket-archive",
|
||||
action: ac.AlsoToMain({
|
||||
type: at.ARCHIVE_FROM_POCKET,
|
||||
|
@ -214,7 +201,7 @@ export const LinkMenuOptions = {
|
|||
userEvent: "ARCHIVE_FROM_POCKET",
|
||||
}),
|
||||
EditTopSite: (site, index) => ({
|
||||
id: "edit_topsites_button_text",
|
||||
id: "newtab-menu-edit-topsites",
|
||||
icon: "edit",
|
||||
action: {
|
||||
type: at.TOP_SITES_EDIT,
|
||||
|
|
|
@ -7,7 +7,7 @@ import {actionCreators as ac, actionTypes as at} from "common/Actions.jsm";
|
|||
export const SectionMenuOptions = {
|
||||
Separator: () => ({type: "separator"}),
|
||||
MoveUp: section => ({
|
||||
id: "section_menu_action_move_up",
|
||||
id: "newtab-section-menu-move-up",
|
||||
icon: "arrowhead-up",
|
||||
action: ac.OnlyToMain({
|
||||
type: at.SECTION_MOVE,
|
||||
|
@ -17,7 +17,7 @@ export const SectionMenuOptions = {
|
|||
disabled: !!section.isFirst,
|
||||
}),
|
||||
MoveDown: section => ({
|
||||
id: "section_menu_action_move_down",
|
||||
id: "newtab-section-menu-move-down",
|
||||
icon: "arrowhead-down",
|
||||
action: ac.OnlyToMain({
|
||||
type: at.SECTION_MOVE,
|
||||
|
@ -27,48 +27,48 @@ export const SectionMenuOptions = {
|
|||
disabled: !!section.isLast,
|
||||
}),
|
||||
RemoveSection: section => ({
|
||||
id: "section_menu_action_remove_section",
|
||||
id: "newtab-section-menu-remove-section",
|
||||
icon: "dismiss",
|
||||
action: ac.SetPref(section.showPrefName, false),
|
||||
userEvent: "MENU_REMOVE",
|
||||
}),
|
||||
CollapseSection: section => ({
|
||||
id: "section_menu_action_collapse_section",
|
||||
id: "newtab-section-menu-collapse-section",
|
||||
icon: "minimize",
|
||||
action: ac.OnlyToMain({type: at.UPDATE_SECTION_PREFS, data: {id: section.id, value: {collapsed: true}}}),
|
||||
userEvent: "MENU_COLLAPSE",
|
||||
}),
|
||||
ExpandSection: section => ({
|
||||
id: "section_menu_action_expand_section",
|
||||
id: "newtab-section-menu-expand-section",
|
||||
icon: "maximize",
|
||||
action: ac.OnlyToMain({type: at.UPDATE_SECTION_PREFS, data: {id: section.id, value: {collapsed: false}}}),
|
||||
userEvent: "MENU_EXPAND",
|
||||
}),
|
||||
ManageSection: section => ({
|
||||
id: "section_menu_action_manage_section",
|
||||
id: "newtab-section-menu-manage-section",
|
||||
icon: "settings",
|
||||
action: ac.OnlyToMain({type: at.SETTINGS_OPEN}),
|
||||
userEvent: "MENU_MANAGE",
|
||||
}),
|
||||
ManageWebExtension: section => ({
|
||||
id: "section_menu_action_manage_webext",
|
||||
id: "newtab-section-menu-manage-webext",
|
||||
icon: "settings",
|
||||
action: ac.OnlyToMain({type: at.OPEN_WEBEXT_SETTINGS, data: section.id}),
|
||||
}),
|
||||
AddTopSite: section => ({
|
||||
id: "section_menu_action_add_topsite",
|
||||
id: "newtab-section-menu-add-topsite",
|
||||
icon: "add",
|
||||
action: {type: at.TOP_SITES_EDIT, data: {index: -1}},
|
||||
userEvent: "MENU_ADD_TOPSITE",
|
||||
}),
|
||||
AddSearchShortcut: section => ({
|
||||
id: "section_menu_action_add_search_engine",
|
||||
id: "newtab-section-menu-add-search-engine",
|
||||
icon: "search",
|
||||
action: {type: at.TOP_SITES_OPEN_SEARCH_SHORTCUTS_MODAL},
|
||||
userEvent: "MENU_ADD_SEARCH",
|
||||
}),
|
||||
PrivacyNotice: section => ({
|
||||
id: "section_menu_action_privacy_notice",
|
||||
id: "newtab-section-menu-privacy-notice",
|
||||
icon: "info",
|
||||
action: ac.OnlyToMain({
|
||||
type: at.OPEN_LINK,
|
||||
|
|
|
@ -43,7 +43,7 @@ const BUILT_IN_SECTIONS = {
|
|||
maxRows: 4,
|
||||
availableLinkMenuOptions: ["CheckBookmarkOrArchive", "CheckSavedToPocket", "Separator", "OpenInNewWindow", "OpenInPrivateWindow", "Separator", "BlockUrl"],
|
||||
emptyState: {
|
||||
message: {id: "topstories_empty_state", values: {provider: options.provider_name}},
|
||||
message: {id: "newtab-empty-section-topstories", values: {provider: options.provider_name}},
|
||||
icon: "check",
|
||||
},
|
||||
shouldSendImpressionStats: true,
|
||||
|
@ -76,7 +76,7 @@ const BUILT_IN_SECTIONS = {
|
|||
rowsPref: "section.highlights.rows",
|
||||
maxRows: 4,
|
||||
emptyState: {
|
||||
message: {id: "highlights_empty_state"},
|
||||
message: {id: "newtab-empty-section-highlights"},
|
||||
icon: "highlights",
|
||||
},
|
||||
shouldSendImpressionStats: false,
|
||||
|
|
|
@ -13,48 +13,6 @@ context_menu_button_sr=Open context menu for {title}
|
|||
# the section edit context menu button is focused/active.
|
||||
section_context_menu_button_sr=Open the section context menu
|
||||
|
||||
# LOCALIZATION NOTE (type_label_*): These labels are associated to pages to give
|
||||
# context on how the element is related to the user, e.g. type indicates that
|
||||
# the page is bookmarked, or is currently open on another device
|
||||
type_label_visited=Visited
|
||||
type_label_bookmarked=Bookmarked
|
||||
type_label_recommended=Trending
|
||||
type_label_pocket=Saved to Pocket
|
||||
type_label_downloaded=Downloaded
|
||||
|
||||
# LOCALIZATION NOTE (menu_action_*): These strings are displayed in a context
|
||||
# menu and are meant as a call to action for a given page.
|
||||
# LOCALIZATION NOTE (menu_action_bookmark): Bookmark is a verb, as in "Add to
|
||||
# bookmarks"
|
||||
menu_action_bookmark=Bookmark
|
||||
menu_action_remove_bookmark=Remove Bookmark
|
||||
menu_action_open_new_window=Open in a New Window
|
||||
menu_action_open_private_window=Open in a New Private Window
|
||||
menu_action_dismiss=Dismiss
|
||||
menu_action_delete=Delete from History
|
||||
menu_action_pin=Pin
|
||||
menu_action_unpin=Unpin
|
||||
menu_action_save_to_pocket=Save to Pocket
|
||||
menu_action_delete_pocket=Delete from Pocket
|
||||
menu_action_archive_pocket=Archive in Pocket
|
||||
|
||||
# LOCALIZATION NOTE (menu_action_show_file_*): These are platform specific strings
|
||||
# found in the context menu of an item that has been downloaded. The intention behind
|
||||
# "this action" is that it will show where the downloaded file exists on the file system
|
||||
# for each operating system.
|
||||
menu_action_show_file_mac_os=Show in Finder
|
||||
menu_action_show_file_windows=Open Containing Folder
|
||||
menu_action_show_file_linux=Open Containing Folder
|
||||
menu_action_show_file_default=Show File
|
||||
menu_action_open_file=Open File
|
||||
|
||||
# LOCALIZATION NOTE (menu_action_copy_download_link, menu_action_go_to_download_page):
|
||||
# "Download" here, in both cases, is not a verb, it is a noun. As in, "Copy the
|
||||
# link that belongs to this downloaded item"
|
||||
menu_action_copy_download_link=Copy Download Link
|
||||
menu_action_go_to_download_page=Go to Download Page
|
||||
menu_action_remove_download=Remove from History
|
||||
|
||||
# LOCALIZATION NOTE (section_disclaimer_topstories): This is shown below
|
||||
# the topstories section title to provide additional information about
|
||||
# how the stories are selected.
|
||||
|
@ -113,30 +71,11 @@ pocket_how_it_works=How it works
|
|||
pocket_cta_button=Get Pocket
|
||||
pocket_cta_text=Save the stories you love in Pocket, and fuel your mind with fascinating reads.
|
||||
|
||||
highlights_empty_state=Start browsing, and we’ll show some of the great articles, videos, and other pages you’ve recently visited or bookmarked here.
|
||||
# LOCALIZATION NOTE (topstories_empty_state): When there are no recommendations,
|
||||
# in the space that would have shown a few stories, this is shown instead.
|
||||
# {provider} is replaced by the name of the content provider for this section.
|
||||
topstories_empty_state=You’ve caught up. Check back later for more top stories from {provider}. Can’t wait? Select a popular topic to find more great stories from around the web.
|
||||
|
||||
# LOCALIZATION NOTE (error_fallback_default_*): This message and suggested
|
||||
# action link are shown in each section of UI that fails to render
|
||||
error_fallback_default_info=Oops, something went wrong loading this content.
|
||||
error_fallback_default_refresh_suggestion=Refresh page to try again.
|
||||
|
||||
# LOCALIZATION NOTE (section_menu_action_*). These strings are displayed in the section
|
||||
# context menu and are meant as a call to action for the given section.
|
||||
section_menu_action_remove_section=Remove Section
|
||||
section_menu_action_collapse_section=Collapse Section
|
||||
section_menu_action_expand_section=Expand Section
|
||||
section_menu_action_manage_section=Manage Section
|
||||
section_menu_action_manage_webext=Manage Extension
|
||||
section_menu_action_add_topsite=Add Top Site
|
||||
section_menu_action_add_search_engine=Add Search Engine
|
||||
section_menu_action_move_up=Move Up
|
||||
section_menu_action_move_down=Move Down
|
||||
section_menu_action_privacy_notice=Privacy Notice
|
||||
|
||||
# LOCALIZATION NOTE (firstrun_*). These strings are displayed only once, on the
|
||||
# firstrun of the browser, they give an introduction to Firefox and Sync.
|
||||
firstrun_title=Take Firefox with You
|
||||
|
|
|
@ -33,7 +33,6 @@ newtab-topsites-url-label = URL
|
|||
newtab-topsites-url-input =
|
||||
.placeholder = Type or paste a URL
|
||||
newtab-topsites-url-validation = Valid URL required
|
||||
newtab-topsites-delete-history-button = Delete from History
|
||||
|
||||
newtab-topsites-image-url-label = Custom Image URL
|
||||
newtab-topsites-use-image-link = Use a custom image…
|
||||
|
@ -41,6 +40,7 @@ newtab-topsites-image-validation = Image failed to load. Try a different URL.
|
|||
|
||||
## Top Sites - General form dialog buttons. These are verbs/actions
|
||||
newtab-topsites-cancel-button = Cancel
|
||||
newtab-topsites-delete-history-button = Delete from History
|
||||
newtab-topsites-save-button = Save
|
||||
newtab-topsites-preview-button = Preview
|
||||
newtab-topsites-add-button = Add
|
||||
|
@ -52,3 +52,79 @@ newtab-confirm-delete-history-p1 = Are you sure you want to delete every instanc
|
|||
newtab-confirm-delete-history-p2 = This action cannot be undone.
|
||||
|
||||
newtab-topsites-add-search-engine = Add Search Engine
|
||||
|
||||
## Top Site - Action Tooltips.
|
||||
# Tooltip to open the context menu for a given top site.
|
||||
newtab-topsites-tooltip =
|
||||
.title = Open menu
|
||||
# Tooltip on an empty topsite box to open the New Top Site dialog.
|
||||
newtab-topsites-placeholder-tooltip =
|
||||
.title = Edit this site
|
||||
|
||||
## Context Menu: These strings are displayed in a context menu and are meant as a call to action for a given page.
|
||||
newtab-menu-edit-topsites = Edit
|
||||
newtab-menu-open-new-window = Open in a New Window
|
||||
newtab-menu-open-new-private-window = Open in a New Private Window
|
||||
newtab-menu-dismiss = Dismiss
|
||||
newtab-menu-pin = Pin
|
||||
newtab-menu-unpin = Unpin
|
||||
newtab-menu-delete-history = Delete from History
|
||||
newtab-menu-save-to-pocket = Save to { -pocket-brand-name }
|
||||
newtab-menu-delete-pocket = Delete from { -pocket-brand-name }
|
||||
newtab-menu-archive-pocket = Archive in { -pocket-brand-name }
|
||||
|
||||
# Note: Bookmark is a noun in this case, "Remove bookmark".
|
||||
newtab-menu-remove-bookmark = Remove Bookmark
|
||||
# Note: Bookmark is a verb here.
|
||||
newtab-menu-bookmark = Bookmark
|
||||
|
||||
## Context Menu - Downloaded Menu: In (newtab-menu-copy-download-link, newtab-menu-go-to-download-page),
|
||||
## "Download" in these cases is not a verb, it is a noun. As in, "Copy the link that belongs to this downloaded item".
|
||||
newtab-menu-copy-download-link = Copy Download Link
|
||||
newtab-menu-go-to-download-page = Go to Download Page
|
||||
newtab-menu-remove-download = Remove from History
|
||||
|
||||
## Context Menu - Download Menu: These are platform specific strings found in the context menu of an item that has
|
||||
## been downloaded. The intention behind "this action" is that it will show where the downloaded file exists on the file
|
||||
## system for each operating system.
|
||||
newtab-menu-show-file =
|
||||
{ PLATFORM() ->
|
||||
[macos] Show in Finder
|
||||
[windows] Open Containing Folder
|
||||
[linux] Open Containing Folder
|
||||
*[other] Show File
|
||||
}
|
||||
newtab-menu-open-file = Open File
|
||||
|
||||
## Card Tooltip: Action tooltip to open a context menu
|
||||
newtab-card-tooltip =
|
||||
.title = Open menu
|
||||
|
||||
## Card Labels: These labels are associated to pages to give
|
||||
## context on how the element is related to the user, e.g. type indicates that
|
||||
## the page is bookmarked, or is currently open on another device
|
||||
newtab-label-visited = Visited
|
||||
newtab-label-bookmarked = Bookmarked
|
||||
newtab-label-recommended = Trending
|
||||
newtab-label-saved = Saved to { -pocket-brand-name }
|
||||
newtab-label-download = Downloaded
|
||||
|
||||
## Section Menu: These strings are displayed in the section context menu and are
|
||||
## meant as a call to action for the given section.
|
||||
newtab-section-menu-remove-section = Remove Section
|
||||
newtab-section-menu-collapse-section = Collapse Section
|
||||
newtab-section-menu-expand-section = Expand Section
|
||||
newtab-section-menu-manage-section = Manage Section
|
||||
newtab-section-menu-manage-webext = Manage Extension
|
||||
newtab-section-menu-add-topsite = Add Top Site
|
||||
newtab-section-menu-add-search-engine = Add Search Engine
|
||||
newtab-section-menu-move-up = Move Up
|
||||
newtab-section-menu-move-down = Move Down
|
||||
newtab-section-menu-privacy-notice = Privacy Notice
|
||||
|
||||
## Empty Section States: These show when there are no more items in a section.
|
||||
newtab-empty-section-highlights = Start browsing, and we’ll show some of the great articles, videos, and other pages you’ve recently visited or bookmarked here.
|
||||
# Ex. When there are no more Pocket story recommendations, in the space where there would have been stories, this is shown instead.
|
||||
# Variables:
|
||||
# $provider (String): Name of the content provider for this section, e.g "Pocket".
|
||||
newtab-empty-section-topstories = You’ve caught up. Check back later for more top stories from { $provider }. Can’t wait? Select a popular topic to find more great stories from around the web.
|
||||
|
|
|
@ -12,14 +12,15 @@ test_newtab({
|
|||
await ContentTaskUtils.waitForCondition(() => content.document.querySelector(siteSelector),
|
||||
"Topsite tippytop icon not found");
|
||||
|
||||
const contextMenuItems = content.openContextMenuAndGetOptions(siteSelector).map(v => v.textContent);
|
||||
const contextMenuItems = await content.openContextMenuAndGetOptions(siteSelector);
|
||||
const contextMenuItemsText = contextMenuItems.map(v => v.textContent);
|
||||
|
||||
Assert.equal(contextMenuItems.length, 5, "Number of options is correct");
|
||||
Assert.equal(contextMenuItemsText.length, 5, "Number of options is correct");
|
||||
|
||||
const expectedItemsText = ["Pin", "Edit", "Open in a New Window", "Open in a New Private Window", "Dismiss"];
|
||||
|
||||
for (let i = 0; i < contextMenuItems.length; i++) {
|
||||
Assert.equal(contextMenuItems[i], expectedItemsText[i], "Name option is correct");
|
||||
for (let i = 0; i < contextMenuItemsText.length; i++) {
|
||||
Assert.equal(contextMenuItemsText[i], expectedItemsText[i], "Name option is correct");
|
||||
}
|
||||
},
|
||||
});
|
||||
|
@ -39,7 +40,7 @@ test_newtab({
|
|||
// Skip the search topsites select the second default topsite
|
||||
const secondTopSite = content.document.querySelectorAll(siteSelector)[1].getAttribute("href");
|
||||
|
||||
const contextMenuItems = content.openContextMenuAndGetOptions(siteSelector);
|
||||
const contextMenuItems = await content.openContextMenuAndGetOptions(siteSelector);
|
||||
Assert.equal(contextMenuItems[4].textContent, "Dismiss", "'Dismiss' is the 5th item in the context menu list");
|
||||
|
||||
contextMenuItems[4].querySelector("button").click();
|
||||
|
@ -62,7 +63,7 @@ test_newtab({
|
|||
await ContentTaskUtils.waitForCondition(() => content.document.querySelectorAll(siteSelector).length === 1,
|
||||
"1 search topsites is loaded by default");
|
||||
|
||||
const contextMenuItems = content.openContextMenuAndGetOptions(siteSelector);
|
||||
const contextMenuItems = await content.openContextMenuAndGetOptions(siteSelector);
|
||||
is(contextMenuItems.length, 2, "Search TopSites should only have Unpin and Dismiss");
|
||||
|
||||
// Unpin
|
||||
|
|
|
@ -86,10 +86,12 @@ function addContentHelpers() {
|
|||
* @param selector {String} Selector to get an item (e.g., top site, card)
|
||||
* @return {Array} The nodes for the options.
|
||||
*/
|
||||
openContextMenuAndGetOptions(selector) {
|
||||
async openContextMenuAndGetOptions(selector) {
|
||||
const item = document.querySelector(selector);
|
||||
const contextButton = item.querySelector(".context-menu-button");
|
||||
contextButton.click();
|
||||
// Gives fluent-dom the time to render strings
|
||||
await new Promise(r => content.requestAnimationFrame(r));
|
||||
|
||||
const contextMenu = item.querySelector(".context-menu");
|
||||
const contextMenuList = contextMenu.querySelector(".context-menu-list");
|
||||
|
|
|
@ -91,10 +91,10 @@ describe("<Card>", () => {
|
|||
it("should have a context based on type", () => {
|
||||
wrapper = shallow(<Card {...DEFAULT_PROPS} />);
|
||||
const context = wrapper.find(".card-context");
|
||||
const {icon, intlID} = cardContextTypes[DEFAULT_PROPS.link.type];
|
||||
const {icon, fluentID} = cardContextTypes[DEFAULT_PROPS.link.type];
|
||||
assert.isTrue(context.childAt(0).hasClass(`icon-${icon}`));
|
||||
assert.isTrue(context.childAt(1).hasClass("card-context-label"));
|
||||
assert.equal(context.childAt(1).props().children.props.id, intlID);
|
||||
assert.equal(context.childAt(1).prop("data-l10n-id"), fluentID);
|
||||
});
|
||||
it("should support setting custom context", () => {
|
||||
const linkWithCustomContext = {
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
import {ContextMenu} from "content-src/components/ContextMenu/ContextMenu";
|
||||
import {IntlProvider} from "react-intl";
|
||||
import {_LinkMenu as LinkMenu} from "content-src/components/LinkMenu/LinkMenu";
|
||||
import React from "react";
|
||||
import {shallow} from "enzyme";
|
||||
import {shallowWithIntl} from "test/unit/utils";
|
||||
|
||||
const messages = require("data/locales.json")["en-US"]; // eslint-disable-line import/no-commonjs
|
||||
|
||||
describe("<LinkMenu>", () => {
|
||||
let wrapper;
|
||||
beforeEach(() => {
|
||||
wrapper = shallowWithIntl(<LinkMenu site={{url: ""}} options={["CheckPinTopSite", "CheckBookmark", "OpenInNewWindow"]} dispatch={() => {}} />);
|
||||
wrapper = shallow(<LinkMenu site={{url: ""}} options={["CheckPinTopSite", "CheckBookmark", "OpenInNewWindow"]} dispatch={() => {}} />);
|
||||
});
|
||||
it("should render a ContextMenu element", () => {
|
||||
assert.ok(wrapper.find(ContextMenu).exists());
|
||||
|
@ -39,140 +35,108 @@ describe("<LinkMenu>", () => {
|
|||
}
|
||||
});
|
||||
it("should show the correct options for default sites", () => {
|
||||
wrapper = shallowWithIntl(<LinkMenu site={{url: "", isDefault: true}} options={["CheckBookmark"]} source={"TOP_SITES"} isPrivateBrowsingEnabled={true} dispatch={() => {}} />);
|
||||
wrapper = shallow(<LinkMenu site={{url: "", isDefault: true}} options={["CheckBookmark"]} source={"TOP_SITES"} isPrivateBrowsingEnabled={true} dispatch={() => {}} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
let i = 0;
|
||||
assert.propertyVal(options[i++], "id", "menu_action_pin");
|
||||
assert.propertyVal(options[i++], "id", "edit_topsites_button_text");
|
||||
assert.propertyVal(options[i++], "id", "newtab-menu-pin");
|
||||
assert.propertyVal(options[i++], "id", "newtab-menu-edit-topsites");
|
||||
assert.propertyVal(options[i++], "type", "separator");
|
||||
assert.propertyVal(options[i++], "id", "menu_action_open_new_window");
|
||||
assert.propertyVal(options[i++], "id", "menu_action_open_private_window");
|
||||
assert.propertyVal(options[i++], "id", "newtab-menu-open-new-window");
|
||||
assert.propertyVal(options[i++], "id", "newtab-menu-open-new-private-window");
|
||||
assert.propertyVal(options[i++], "type", "separator");
|
||||
assert.propertyVal(options[i++], "id", "menu_action_dismiss");
|
||||
assert.propertyVal(options[i++], "id", "newtab-menu-dismiss");
|
||||
assert.propertyVal(options, "length", i);
|
||||
// Double check that delete options are not included for default top sites
|
||||
options.filter(o => o.type !== "separator").forEach(o => {
|
||||
assert.notInclude(["menu_action_delete"], o.id);
|
||||
assert.notInclude(["newtab-menu-delete-history"], o.id);
|
||||
});
|
||||
});
|
||||
it("should show Unpin option for a pinned site if CheckPinTopSite in options list", () => {
|
||||
wrapper = shallowWithIntl(<LinkMenu site={{url: "", isPinned: true}} source={"TOP_SITES"} options={["CheckPinTopSite"]} dispatch={() => {}} />);
|
||||
wrapper = shallow(<LinkMenu site={{url: "", isPinned: true}} source={"TOP_SITES"} options={["CheckPinTopSite"]} dispatch={() => {}} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "menu_action_unpin")));
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "newtab-menu-unpin")));
|
||||
});
|
||||
it("should show Pin option for an unpinned site if CheckPinTopSite in options list", () => {
|
||||
wrapper = shallowWithIntl(<LinkMenu site={{url: "", isPinned: false}} source={"TOP_SITES"} options={["CheckPinTopSite"]} dispatch={() => {}} />);
|
||||
wrapper = shallow(<LinkMenu site={{url: "", isPinned: false}} source={"TOP_SITES"} options={["CheckPinTopSite"]} dispatch={() => {}} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "menu_action_pin")));
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "newtab-menu-pin")));
|
||||
});
|
||||
it("should show Unbookmark option for a bookmarked site if CheckBookmark in options list", () => {
|
||||
wrapper = shallowWithIntl(<LinkMenu site={{url: "", bookmarkGuid: 1234}} source={"TOP_SITES"} options={["CheckBookmark"]} dispatch={() => {}} />);
|
||||
wrapper = shallow(<LinkMenu site={{url: "", bookmarkGuid: 1234}} source={"TOP_SITES"} options={["CheckBookmark"]} dispatch={() => {}} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "menu_action_remove_bookmark")));
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "newtab-menu-remove-bookmark")));
|
||||
});
|
||||
it("should show Bookmark option for an unbookmarked site if CheckBookmark in options list", () => {
|
||||
wrapper = shallowWithIntl(<LinkMenu site={{url: "", bookmarkGuid: 0}} source={"TOP_SITES"} options={["CheckBookmark"]} dispatch={() => {}} />);
|
||||
wrapper = shallow(<LinkMenu site={{url: "", bookmarkGuid: 0}} source={"TOP_SITES"} options={["CheckBookmark"]} dispatch={() => {}} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "menu_action_bookmark")));
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "newtab-menu-bookmark")));
|
||||
});
|
||||
it("should show Save to Pocket option for an unsaved Pocket item if CheckSavedToPocket in options list", () => {
|
||||
wrapper = shallowWithIntl(<LinkMenu site={{url: "", bookmarkGuid: 0}} source={"HIGHLIGHTS"} options={["CheckSavedToPocket"]} dispatch={() => {}} />);
|
||||
wrapper = shallow(<LinkMenu site={{url: "", bookmarkGuid: 0}} source={"HIGHLIGHTS"} options={["CheckSavedToPocket"]} dispatch={() => {}} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "menu_action_save_to_pocket")));
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "newtab-menu-save-to-pocket")));
|
||||
});
|
||||
it("should show Delete from Pocket option for a saved Pocket item if CheckSavedToPocket in options list", () => {
|
||||
wrapper = shallowWithIntl(<LinkMenu site={{url: "", pocket_id: 1234}} source={"HIGHLIGHTS"} options={["CheckSavedToPocket"]} dispatch={() => {}} />);
|
||||
wrapper = shallow(<LinkMenu site={{url: "", pocket_id: 1234}} source={"HIGHLIGHTS"} options={["CheckSavedToPocket"]} dispatch={() => {}} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "menu_action_delete_pocket")));
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "newtab-menu-delete-pocket")));
|
||||
});
|
||||
it("should show Archive from Pocket option for a saved Pocket item if CheckBookmarkOrArchive", () => {
|
||||
wrapper = shallowWithIntl(<LinkMenu site={{url: "", pocket_id: 1234}} source={"HIGHLIGHTS"} options={["CheckBookmarkOrArchive"]} dispatch={() => {}} />);
|
||||
wrapper = shallow(<LinkMenu site={{url: "", pocket_id: 1234}} source={"HIGHLIGHTS"} options={["CheckBookmarkOrArchive"]} dispatch={() => {}} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "menu_action_archive_pocket")));
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "newtab-menu-archive-pocket")));
|
||||
});
|
||||
it("should show Bookmark option for an unbookmarked site if CheckBookmarkOrArchive in options list and no pocket_id", () => {
|
||||
wrapper = shallowWithIntl(<LinkMenu site={{url: ""}} source={"HIGHLIGHTS"} options={["CheckBookmarkOrArchive"]} dispatch={() => {}} />);
|
||||
wrapper = shallow(<LinkMenu site={{url: ""}} source={"HIGHLIGHTS"} options={["CheckBookmarkOrArchive"]} dispatch={() => {}} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "menu_action_bookmark")));
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "newtab-menu-bookmark")));
|
||||
});
|
||||
it("should show Unbookmark option for a bookmarked site if CheckBookmarkOrArchive in options list and no pocket_id", () => {
|
||||
wrapper = shallowWithIntl(<LinkMenu site={{url: "", bookmarkGuid: 1234}} source={"HIGHLIGHTS"} options={["CheckBookmarkOrArchive"]} dispatch={() => {}} />);
|
||||
wrapper = shallow(<LinkMenu site={{url: "", bookmarkGuid: 1234}} source={"HIGHLIGHTS"} options={["CheckBookmarkOrArchive"]} dispatch={() => {}} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "menu_action_remove_bookmark")));
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "newtab-menu-remove-bookmark")));
|
||||
});
|
||||
it("should show Open File option for a downloaded item", () => {
|
||||
wrapper = shallowWithIntl(<LinkMenu site={{url: "", type: "download", path: "foo"}} source={"HIGHLIGHTS"} options={["OpenFile"]} dispatch={() => {}} />);
|
||||
wrapper = shallow(<LinkMenu site={{url: "", type: "download", path: "foo"}} source={"HIGHLIGHTS"} options={["OpenFile"]} dispatch={() => {}} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "menu_action_open_file")));
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "newtab-menu-open-file")));
|
||||
});
|
||||
it("should show Show File option for a downloaded item on a default platform", () => {
|
||||
wrapper = shallowWithIntl(<LinkMenu site={{url: "", type: "download", path: "foo"}} source={"HIGHLIGHTS"} options={["ShowFile"]} platform={"default"} dispatch={() => {}} />);
|
||||
wrapper = shallow(<LinkMenu site={{url: "", type: "download", path: "foo"}} source={"HIGHLIGHTS"} options={["ShowFile"]} platform={"default"} dispatch={() => {}} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "menu_action_show_file_default")));
|
||||
});
|
||||
it("should show Show in Finder option for a downloaded item on a mac", () => {
|
||||
wrapper = shallowWithIntl(<LinkMenu site={{url: "", type: "download"}} source={"HIGHLIGHTS"} options={["ShowFile"]} platform={"macosx"} dispatch={() => {}} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "menu_action_show_file_mac_os")));
|
||||
});
|
||||
it("should show Open containing folder option for a downloaded item on windows", () => {
|
||||
wrapper = shallowWithIntl(<LinkMenu site={{url: "", type: "download"}} source={"HIGHLIGHTS"} options={["ShowFile"]} platform={"win"} dispatch={() => {}} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "menu_action_show_file_windows")));
|
||||
});
|
||||
it("should show Open containing folder option for a downloaded item on linux", () => {
|
||||
wrapper = shallowWithIntl(<LinkMenu site={{url: "", type: "download"}} source={"HIGHLIGHTS"} options={["ShowFile"]} platform={"linux"} dispatch={() => {}} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "menu_action_show_file_linux")));
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "newtab-menu-show-file")));
|
||||
});
|
||||
it("should show Copy Downlad Link option for a downloaded item when CopyDownloadLink", () => {
|
||||
wrapper = shallowWithIntl(<LinkMenu site={{url: "", type: "download"}} source={"HIGHLIGHTS"} options={["CopyDownloadLink"]} dispatch={() => {}} />);
|
||||
wrapper = shallow(<LinkMenu site={{url: "", type: "download"}} source={"HIGHLIGHTS"} options={["CopyDownloadLink"]} dispatch={() => {}} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "menu_action_copy_download_link")));
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "newtab-menu-copy-download-link")));
|
||||
});
|
||||
it("should show Go To Download Page option for a downloaded item when GoToDownloadPage", () => {
|
||||
wrapper = shallowWithIntl(<LinkMenu site={{url: "", type: "download", referrer: "foo"}} source={"HIGHLIGHTS"} options={["GoToDownloadPage"]} dispatch={() => {}} />);
|
||||
wrapper = shallow(<LinkMenu site={{url: "", type: "download", referrer: "foo"}} source={"HIGHLIGHTS"} options={["GoToDownloadPage"]} dispatch={() => {}} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "menu_action_go_to_download_page")));
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "newtab-menu-go-to-download-page")));
|
||||
assert.isFalse(options[0].disabled);
|
||||
});
|
||||
it("should show Go To Download Page option as disabled for a downloaded item when GoToDownloadPage if no referrer exists", () => {
|
||||
wrapper = shallowWithIntl(<LinkMenu site={{url: "", type: "download", referrer: null}} source={"HIGHLIGHTS"} options={["GoToDownloadPage"]} dispatch={() => {}} />);
|
||||
wrapper = shallow(<LinkMenu site={{url: "", type: "download", referrer: null}} source={"HIGHLIGHTS"} options={["GoToDownloadPage"]} dispatch={() => {}} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "menu_action_go_to_download_page")));
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "newtab-menu-go-to-download-page")));
|
||||
assert.isTrue(options[0].disabled);
|
||||
});
|
||||
it("should show Remove Download Link option for a downloaded item when RemoveDownload", () => {
|
||||
wrapper = shallowWithIntl(<LinkMenu site={{url: "", type: "download"}} source={"HIGHLIGHTS"} options={["RemoveDownload"]} dispatch={() => {}} />);
|
||||
wrapper = shallow(<LinkMenu site={{url: "", type: "download"}} source={"HIGHLIGHTS"} options={["RemoveDownload"]} dispatch={() => {}} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "menu_action_remove_download")));
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "newtab-menu-remove-download")));
|
||||
});
|
||||
it("should show Edit option", () => {
|
||||
const props = {url: "foo", label: "label"};
|
||||
const index = 5;
|
||||
wrapper = shallowWithIntl(<LinkMenu site={props} index={5} source={"TOP_SITES"} options={["EditTopSite"]} dispatch={() => {}} />);
|
||||
wrapper = shallow(<LinkMenu site={props} index={5} source={"TOP_SITES"} options={["EditTopSite"]} dispatch={() => {}} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
const option = options.find(o => (o.id && o.id === "edit_topsites_button_text"));
|
||||
const option = options.find(o => (o.id && o.id === "newtab-menu-edit-topsites"));
|
||||
assert.isDefined(option);
|
||||
assert.equal(option.action.data.index, index);
|
||||
});
|
||||
it("should call intl.formatMessage with the correct string ids", () => {
|
||||
const FAKE_OPTIONS = ["AddBookmark", "OpenInNewWindow"];
|
||||
const intlProvider = new IntlProvider({locale: "en", messages});
|
||||
const {intl} = intlProvider.getChildContext();
|
||||
const spy = sinon.spy(intl, "formatMessage");
|
||||
|
||||
// Identical to calling shallowWithIntl, but passing in the mocked intl object
|
||||
const node = <LinkMenu site={{url: ""}} options={FAKE_OPTIONS} dispatch={() => {}} />;
|
||||
shallow(React.cloneElement(node, {intl}), {context: {intl}});
|
||||
|
||||
// Called once for each option in the menu
|
||||
assert.ok(spy.callCount === FAKE_OPTIONS.length);
|
||||
|
||||
// Called with correct ids both times
|
||||
assert.ok(spy.firstCall.calledWith(sinon.match({id: "menu_action_bookmark"})));
|
||||
assert.ok(spy.secondCall.calledWith(sinon.match({id: "menu_action_open_new_window"})));
|
||||
});
|
||||
describe(".onClick", () => {
|
||||
const FAKE_INDEX = 3;
|
||||
const FAKE_SOURCE = "TOP_SITES";
|
||||
|
@ -190,25 +154,24 @@ describe("<LinkMenu>", () => {
|
|||
const dispatch = sinon.stub();
|
||||
const propOptions = ["ShowFile", "CopyDownloadLink", "GoToDownloadPage", "RemoveDownload", "Separator", "RemoveBookmark", "AddBookmark", "OpenInNewWindow", "OpenInPrivateWindow", "BlockUrl", "DeleteUrl", "PinTopSite", "UnpinTopSite", "SaveToPocket", "DeleteFromPocket", "ArchiveFromPocket", "WebExtDismiss"];
|
||||
const expectedActionData = {
|
||||
menu_action_remove_bookmark: FAKE_SITE.bookmarkGuid,
|
||||
menu_action_bookmark: {url: FAKE_SITE.url, title: FAKE_SITE.title, type: FAKE_SITE.type},
|
||||
menu_action_open_new_window: {url: FAKE_SITE.url, referrer: FAKE_SITE.referrer, typedBonus: FAKE_SITE.typedBonus},
|
||||
menu_action_open_private_window: {url: FAKE_SITE.url, referrer: FAKE_SITE.referrer},
|
||||
menu_action_dismiss: {url: FAKE_SITE.url, pocket_id: FAKE_SITE.pocket_id},
|
||||
menu_action_webext_dismiss: {source: "TOP_SITES", url: FAKE_SITE.url, action_position: 3},
|
||||
menu_action_delete: {url: FAKE_SITE.url, pocket_id: FAKE_SITE.pocket_id, forceBlock: FAKE_SITE.bookmarkGuid},
|
||||
menu_action_pin: {site: {url: FAKE_SITE.url}, index: FAKE_INDEX},
|
||||
menu_action_unpin: {site: {url: FAKE_SITE.url}},
|
||||
menu_action_save_to_pocket: {site: {url: FAKE_SITE.url, title: FAKE_SITE.title}},
|
||||
menu_action_delete_pocket: {pocket_id: "1234"},
|
||||
menu_action_archive_pocket: {pocket_id: "1234"},
|
||||
menu_action_show_file_default: {url: FAKE_SITE.url},
|
||||
menu_action_copy_download_link: {url: FAKE_SITE.url},
|
||||
menu_action_go_to_download_page: {url: FAKE_SITE.referrer},
|
||||
menu_action_remove_download: {url: FAKE_SITE.url},
|
||||
"newtab-menu-remove-bookmark": FAKE_SITE.bookmarkGuid,
|
||||
"newtab-menu-bookmark": {url: FAKE_SITE.url, title: FAKE_SITE.title, type: FAKE_SITE.type},
|
||||
"newtab-menu-open-new-window": {url: FAKE_SITE.url, referrer: FAKE_SITE.referrer, typedBonus: FAKE_SITE.typedBonus},
|
||||
"newtab-menu-open-new-private-window": {url: FAKE_SITE.url, referrer: FAKE_SITE.referrer},
|
||||
"newtab-menu-dismiss": {url: FAKE_SITE.url, pocket_id: FAKE_SITE.pocket_id},
|
||||
"menu_action_webext_dismiss": {source: "TOP_SITES", url: FAKE_SITE.url, action_position: 3},
|
||||
"newtab-menu-delete-history": {url: FAKE_SITE.url, pocket_id: FAKE_SITE.pocket_id, forceBlock: FAKE_SITE.bookmarkGuid},
|
||||
"newtab-menu-pin": {site: {url: FAKE_SITE.url}, index: FAKE_INDEX},
|
||||
"newtab-menu-unpin": {site: {url: FAKE_SITE.url}},
|
||||
"newtab-menu-save-to-pocket": {site: {url: FAKE_SITE.url, title: FAKE_SITE.title}},
|
||||
"newtab-menu-delete-pocket": {pocket_id: "1234"},
|
||||
"newtab-menu-archive-pocket": {pocket_id: "1234"},
|
||||
"newtab-menu-show-file": {url: FAKE_SITE.url},
|
||||
"newtab-menu-copy-download-link": {url: FAKE_SITE.url},
|
||||
"newtab-menu-go-to-download-page": {url: FAKE_SITE.referrer},
|
||||
"newtab-menu-remove-download": {url: FAKE_SITE.url},
|
||||
};
|
||||
|
||||
const {options} = shallowWithIntl(<LinkMenu
|
||||
const {options} = shallow(<LinkMenu
|
||||
site={FAKE_SITE}
|
||||
siteInfo={{value: {card_type: FAKE_SITE.type}}}
|
||||
dispatch={dispatch}
|
||||
|
@ -239,7 +202,7 @@ describe("<LinkMenu>", () => {
|
|||
// (delete is a special case as it dispatches a nested DIALOG_OPEN-type action)
|
||||
// in the case of this FAKE_SITE, we send a bookmarkGuid therefore we also want
|
||||
// to block this if we delete it
|
||||
if (option.id === "menu_action_delete") {
|
||||
if (option.id === "newtab-menu-delete-history") {
|
||||
assert.deepEqual(option.action.data.onConfirm[0].data, expectedActionData[option.id]);
|
||||
// Test UserEvent send correct meta about item deleted
|
||||
assert.propertyVal(option.action.data.onConfirm[1].data, "action_position", FAKE_INDEX);
|
||||
|
@ -267,7 +230,7 @@ describe("<LinkMenu>", () => {
|
|||
});
|
||||
});
|
||||
it(`should not send impression stats if not configured`, () => {
|
||||
const fakeOptions = shallowWithIntl(<LinkMenu site={FAKE_SITE} dispatch={dispatch} index={FAKE_INDEX} options={propOptions} source={FAKE_SOURCE} shouldSendImpressionStats={false} />)
|
||||
const fakeOptions = shallow(<LinkMenu site={FAKE_SITE} dispatch={dispatch} index={FAKE_INDEX} options={propOptions} source={FAKE_SOURCE} shouldSendImpressionStats={false} />)
|
||||
.find(ContextMenu).props().options;
|
||||
|
||||
fakeOptions.filter(o => o.type !== "separator").forEach(option => {
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
import {ContextMenu} from "content-src/components/ContextMenu/ContextMenu";
|
||||
import {IntlProvider} from "react-intl";
|
||||
import React from "react";
|
||||
import {_SectionMenu as SectionMenu} from "content-src/components/SectionMenu/SectionMenu";
|
||||
import {shallow} from "enzyme";
|
||||
import {shallowWithIntl} from "test/unit/utils";
|
||||
|
||||
const messages = require("data/locales.json")["en-US"]; // eslint-disable-line import/no-commonjs
|
||||
|
||||
const DEFAULT_PROPS = {
|
||||
name: "Section Name",
|
||||
|
@ -22,7 +18,7 @@ const DEFAULT_PROPS = {
|
|||
describe("<SectionMenu>", () => {
|
||||
let wrapper;
|
||||
beforeEach(() => {
|
||||
wrapper = shallowWithIntl(<SectionMenu {...DEFAULT_PROPS} />);
|
||||
wrapper = shallow(<SectionMenu {...DEFAULT_PROPS} />);
|
||||
});
|
||||
it("should render a ContextMenu element", () => {
|
||||
assert.ok(wrapper.find(ContextMenu).exists());
|
||||
|
@ -51,90 +47,71 @@ describe("<SectionMenu>", () => {
|
|||
}
|
||||
});
|
||||
it("should show the correct default options", () => {
|
||||
wrapper = shallowWithIntl(<SectionMenu {...DEFAULT_PROPS} />);
|
||||
wrapper = shallow(<SectionMenu {...DEFAULT_PROPS} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
let i = 0;
|
||||
assert.propertyVal(options[i++], "id", "section_menu_action_move_up");
|
||||
assert.propertyVal(options[i++], "id", "section_menu_action_move_down");
|
||||
assert.propertyVal(options[i++], "id", "newtab-section-menu-move-up");
|
||||
assert.propertyVal(options[i++], "id", "newtab-section-menu-move-down");
|
||||
assert.propertyVal(options[i++], "type", "separator");
|
||||
assert.propertyVal(options[i++], "id", "section_menu_action_remove_section");
|
||||
assert.propertyVal(options[i++], "id", "section_menu_action_collapse_section");
|
||||
assert.propertyVal(options[i++], "id", "newtab-section-menu-remove-section");
|
||||
assert.propertyVal(options[i++], "id", "newtab-section-menu-collapse-section");
|
||||
assert.propertyVal(options[i++], "type", "separator");
|
||||
assert.propertyVal(options[i++], "id", "section_menu_action_manage_section");
|
||||
assert.propertyVal(options[i++], "id", "newtab-section-menu-manage-section");
|
||||
assert.propertyVal(options, "length", i);
|
||||
});
|
||||
it("should show the correct default options for a web extension", () => {
|
||||
wrapper = shallowWithIntl(<SectionMenu {...DEFAULT_PROPS} isWebExtension={true} />);
|
||||
wrapper = shallow(<SectionMenu {...DEFAULT_PROPS} isWebExtension={true} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
let i = 0;
|
||||
assert.propertyVal(options[i++], "id", "section_menu_action_move_up");
|
||||
assert.propertyVal(options[i++], "id", "section_menu_action_move_down");
|
||||
assert.propertyVal(options[i++], "id", "newtab-section-menu-move-up");
|
||||
assert.propertyVal(options[i++], "id", "newtab-section-menu-move-down");
|
||||
assert.propertyVal(options[i++], "type", "separator");
|
||||
assert.propertyVal(options[i++], "id", "section_menu_action_collapse_section");
|
||||
assert.propertyVal(options[i++], "id", "newtab-section-menu-collapse-section");
|
||||
assert.propertyVal(options[i++], "type", "separator");
|
||||
assert.propertyVal(options[i++], "id", "section_menu_action_manage_webext");
|
||||
assert.propertyVal(options[i++], "id", "newtab-section-menu-manage-webext");
|
||||
assert.propertyVal(options, "length", i);
|
||||
});
|
||||
it("should show Collapse option for an expanded section if CheckCollapsed in options list", () => {
|
||||
wrapper = shallowWithIntl(<SectionMenu {...DEFAULT_PROPS} collapsed={false} />);
|
||||
wrapper = shallow(<SectionMenu {...DEFAULT_PROPS} collapsed={false} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "section_menu_action_collapse_section")));
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "newtab-section-menu-collapse-section")));
|
||||
});
|
||||
it("should show Expand option for a collapsed section if CheckCollapsed in options list", () => {
|
||||
wrapper = shallowWithIntl(<SectionMenu {...DEFAULT_PROPS} collapsed={true} />);
|
||||
wrapper = shallow(<SectionMenu {...DEFAULT_PROPS} collapsed={true} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "section_menu_action_expand_section")));
|
||||
assert.isDefined(options.find(o => (o.id && o.id === "newtab-section-menu-expand-section")));
|
||||
});
|
||||
it("should show Add Top Site option", () => {
|
||||
wrapper = shallowWithIntl(<SectionMenu {...DEFAULT_PROPS} extraOptions={["AddTopSite"]} />);
|
||||
wrapper = shallow(<SectionMenu {...DEFAULT_PROPS} extraOptions={["AddTopSite"]} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.equal(options[0].id, "section_menu_action_add_topsite");
|
||||
assert.equal(options[0].id, "newtab-section-menu-add-topsite");
|
||||
});
|
||||
it("should show Add Search Engine option", () => {
|
||||
wrapper = shallowWithIntl(<SectionMenu {...DEFAULT_PROPS} extraOptions={["AddSearchShortcut"]} />);
|
||||
wrapper = shallow(<SectionMenu {...DEFAULT_PROPS} extraOptions={["AddSearchShortcut"]} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.equal(options[0].id, "section_menu_action_add_search_engine");
|
||||
assert.equal(options[0].id, "newtab-section-menu-add-search-engine");
|
||||
});
|
||||
it("should show Privacy Notice option if privacyNoticeURL is passed", () => {
|
||||
wrapper = shallowWithIntl(<SectionMenu {...DEFAULT_PROPS} privacyNoticeURL="https://mozilla.org/privacy" />);
|
||||
wrapper = shallow(<SectionMenu {...DEFAULT_PROPS} privacyNoticeURL="https://mozilla.org/privacy" />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
let i = 0;
|
||||
assert.propertyVal(options[i++], "id", "section_menu_action_move_up");
|
||||
assert.propertyVal(options[i++], "id", "section_menu_action_move_down");
|
||||
assert.propertyVal(options[i++], "id", "newtab-section-menu-move-up");
|
||||
assert.propertyVal(options[i++], "id", "newtab-section-menu-move-down");
|
||||
assert.propertyVal(options[i++], "type", "separator");
|
||||
assert.propertyVal(options[i++], "id", "section_menu_action_remove_section");
|
||||
assert.propertyVal(options[i++], "id", "section_menu_action_collapse_section");
|
||||
assert.propertyVal(options[i++], "id", "newtab-section-menu-remove-section");
|
||||
assert.propertyVal(options[i++], "id", "newtab-section-menu-collapse-section");
|
||||
assert.propertyVal(options[i++], "type", "separator");
|
||||
assert.propertyVal(options[i++], "id", "section_menu_action_privacy_notice");
|
||||
assert.propertyVal(options[i++], "id", "section_menu_action_manage_section");
|
||||
assert.propertyVal(options[i++], "id", "newtab-section-menu-privacy-notice");
|
||||
assert.propertyVal(options[i++], "id", "newtab-section-menu-manage-section");
|
||||
assert.propertyVal(options, "length", i);
|
||||
});
|
||||
it("should call intl.formatMessage with the correct string ids", () => {
|
||||
const intlProvider = new IntlProvider({locale: "en", messages});
|
||||
const {intl} = intlProvider.getChildContext();
|
||||
const spy = sinon.spy(intl, "formatMessage");
|
||||
|
||||
// Identical to calling shallowWithIntl, but passing in the mocked intl object
|
||||
const node = <SectionMenu {...DEFAULT_PROPS} />;
|
||||
shallow(React.cloneElement(node, {intl}), {context: {intl}});
|
||||
|
||||
// Called once for each option in the menu
|
||||
assert.equal(spy.callCount, 5);
|
||||
|
||||
// Called with correct ids
|
||||
assert.ok(spy.calledWith(sinon.match({id: "section_menu_action_move_up"})));
|
||||
assert.ok(spy.calledWith(sinon.match({id: "section_menu_action_move_down"})));
|
||||
assert.ok(spy.calledWith(sinon.match({id: "section_menu_action_remove_section"})));
|
||||
assert.ok(spy.calledWith(sinon.match({id: "section_menu_action_collapse_section"})));
|
||||
assert.ok(spy.calledWith(sinon.match({id: "section_menu_action_manage_section"})));
|
||||
});
|
||||
it("should disable Move Up on first section", () => {
|
||||
wrapper = shallowWithIntl(<SectionMenu {...DEFAULT_PROPS} isFirst={true} />);
|
||||
wrapper = shallow(<SectionMenu {...DEFAULT_PROPS} isFirst={true} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.ok(options[0].disabled);
|
||||
});
|
||||
it("should disable Move Down on last section", () => {
|
||||
wrapper = shallowWithIntl(<SectionMenu {...DEFAULT_PROPS} isLast={true} />);
|
||||
wrapper = shallow(<SectionMenu {...DEFAULT_PROPS} isLast={true} />);
|
||||
const {options} = wrapper.find(ContextMenu).props();
|
||||
assert.ok(options[1].disabled);
|
||||
});
|
||||
|
@ -142,16 +119,16 @@ describe("<SectionMenu>", () => {
|
|||
const dispatch = sinon.stub();
|
||||
const propOptions = ["Separator", "MoveUp", "MoveDown", "RemoveSection", "CollapseSection", "ExpandSection", "ManageSection", "AddTopSite", "PrivacyNotice"];
|
||||
const expectedActionData = {
|
||||
section_menu_action_move_up: {id: "sectionId", direction: -1},
|
||||
section_menu_action_move_down: {id: "sectionId", direction: +1},
|
||||
section_menu_action_remove_section: {name: "showSection", value: false},
|
||||
section_menu_action_collapse_section: {id: DEFAULT_PROPS.id, value: {collapsed: true}},
|
||||
section_menu_action_expand_section: {id: DEFAULT_PROPS.id, value: {collapsed: false}},
|
||||
section_menu_action_manage_section: undefined,
|
||||
section_menu_action_add_topsite: {index: -1},
|
||||
section_menu_action_privacy_notice: {url: DEFAULT_PROPS.privacyNoticeURL},
|
||||
"newtab-section-menu-move-up": {id: "sectionId", direction: -1},
|
||||
"newtab-section-menu-move-down": {id: "sectionId", direction: +1},
|
||||
"newtab-section-menu-remove-section": {name: "showSection", value: false},
|
||||
"newtab-section-menu-collapse-section": {id: DEFAULT_PROPS.id, value: {collapsed: true}},
|
||||
"newtab-section-menu-expand-section": {id: DEFAULT_PROPS.id, value: {collapsed: false}},
|
||||
"newtab-section-menu-manage-section": undefined,
|
||||
"newtab-section-menu-add-topsite": {index: -1},
|
||||
"newtab-section-menu-privacy-notice": {url: DEFAULT_PROPS.privacyNoticeURL},
|
||||
};
|
||||
const {options} = shallowWithIntl(<SectionMenu {...DEFAULT_PROPS} dispatch={dispatch} options={propOptions} />)
|
||||
const {options} = shallow(<SectionMenu {...DEFAULT_PROPS} dispatch={dispatch} options={propOptions} />)
|
||||
.find(ContextMenu).props();
|
||||
afterEach(() => dispatch.reset());
|
||||
options.filter(o => o.type !== "separator").forEach(option => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче