Browse Source

Fix and test notification page detection (#544)

master
Federico Brigante 7 years ago
committed by Sindre Sorhus
parent
commit
a42ebf12f7
  1. 2
      src/libs/page-detect.js
  2. 13
      test/page-detect.js

2
src/libs/page-detect.js

@ -48,7 +48,7 @@ export const isReleases = () => isRepo() && /^\/(releases|tags)/.test(getRepoPat
export const isBlame = () => isRepo() && /^\/blame\//.test(getRepoPath());
export const isNotifications = () => /\/notifications(\/participating)?/.test(location.pathname);
export const isNotifications = () => location.pathname.startsWith('/notifications');
export const isRepoSettings = () => isRepo() && /^\/settings/.test(getRepoPath());

13
test/page-detect.js

@ -1,11 +1,10 @@
import test from 'ava';
import * as pageDetect from '../src/libs/page-detect';
import Window from './fixtures/window';
global.window = new Window();
global.location = window.location;
const pageDetect = require('../src/libs/page-detect.js'); // eslint-disable-line import/no-unassigned-import
function urlMatcherMacro(t, detectFn, shouldMatch = [], shouldNotMatch = []) {
for (const url of shouldMatch) {
location.href = url;
@ -160,6 +159,16 @@ test('isBlame', urlMatcherMacro, pageDetect.isBlame, [
'https://github.com/sindresorhus/refined-github/blob/master/package.json'
]);
test('isNotifications', urlMatcherMacro, pageDetect.isNotifications, [
'https://github.com/notifications',
'https://github.com/notifications/participating',
'https://github.com/notifications?all=1'
], [
'https://github.com/settings/notifications',
'https://github.com/watching',
'https://github.com/jaredhanson/node-notifications/tree/master/lib/notifications'
]);
test('isSingleFile', urlMatcherMacro, pageDetect.isSingleFile, [
'https://github.com/sindresorhus/refined-github/blob/master/.gitattributes',
'https://github.com/sindresorhus/refined-github/blob/fix-narrow-diff/extension/content.css'

Loading…
Cancel
Save