it('matches guardian domain', function () { expect(isGuardian('http://' + CONST.mainDomain)).toBe(true); expect(isGuardian('https://' + CONST.mainDomain)).toBe(true); expect(isGuardian('http://guaridian.it')).toBe(false); expect(isGuardian('https://' + CONST.mainDomain + '/')).toBe(true); expect(isGuardian('https://' + CONST.mainDomain + '/uk?search=fruit#hash')).toBe(true); });
.then(function(res) { // TODO Phantom Babel bug if (!res) { res = {}; } var results = res.content, resultsTitle = res.title, capiItem, icc, pageCode, err; // ContentApi item if (results && results.length === 1) { capiItem = results[0]; icc = internalContentCode(capiItem); pageCode = internalPageCode(capiItem); if (icc && icc === item.id()) { populate(item, capiItem); cache.put('contentApi', icc, capiItem); item.id(icc); } else if (pageCode) { populate(item, capiItem); cache.put('contentApi', pageCode, capiItem); // Populate the cache with icc as well if (icc) { cache.put('contentApi', icc, capiItem); } item.id(pageCode); } else { err = 'Sorry, that article is malformed (has no internalPageCode)'; } // A snap, but not an absolute url } else if (!item.id().match(/^https?:\/\//)) { err = 'Sorry, URLs must begin with http...'; // A snap, but snaps can only be created to the Clipboard } else if (item.group.parentType !== 'Clipboard') { err = 'Sorry, special links must be dragged to the Clipboard, initially'; // A snap, but a link off of the tool itself } else if (item.id().indexOf(window.location.hostname) > -1) { err = 'Sorry, that link cannot be added to a front'; // A snap, but a link to unavailable guardian content } else if (results && results.length === 0 && isGuardianUrl(item.id())) { err = 'Sorry, that Guardian content is unavailable'; // A snap, that's setting it's own type, ie via dragged-in query params } else if (item.meta.snapType()) { item.convertToSnap(); // A snap, of type 'latest', ie. where the target is a Guardian tag/section page. } else if (results && results.length > 1) { modalDialog.confirm({ name: 'select_snap_type', data: { prefix: CONST.latestSnapPrefix, resultsTitle: resultsTitle } }).then(function () { item.convertToLatestSnap(resultsTitle); resolve(item); }, function () { item.convertToLinkSnap(); resolve(item); }); // Waiting for the modal to be closed return; // A snap, of default type 'link'. } else { item.convertToLinkSnap(); } if (err) { reject(new Error(err)); } else { resolve(item); } });