Skip to content

Commit cae2d9e

Browse files
committed
refactoring
1 parent 28416b4 commit cae2d9e

11 files changed

+126
-116
lines changed

dotcom-rendering/src/components/SignInGate/displayRule.test.ts

Lines changed: 0 additions & 108 deletions
This file was deleted.
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import { incrementDailyArticleCount } from '../../lib/dailyArticleCount';
2+
import {
3+
isNPageOrHigherPageView,
4+
isValidContentType,
5+
isValidSection,
6+
isValidTag,
7+
pageIdIsAllowedForGating,
8+
} from './displayRules';
9+
10+
describe('isNPageOrHigherPageView', () => {
11+
beforeEach(() => {
12+
localStorage.clear();
13+
});
14+
15+
test('default - checks for is 2 article views returns true', () => {
16+
incrementDailyArticleCount();
17+
incrementDailyArticleCount();
18+
19+
const output = isNPageOrHigherPageView();
20+
21+
expect(output).toBe(true);
22+
});
23+
24+
test('default - checks for higher 2 article views returns true', () => {
25+
incrementDailyArticleCount();
26+
incrementDailyArticleCount();
27+
incrementDailyArticleCount();
28+
29+
const output = isNPageOrHigherPageView();
30+
31+
expect(output).toBe(true);
32+
});
33+
34+
test('default - checks for lower than 2 article views returns false', () => {
35+
incrementDailyArticleCount();
36+
37+
const output = isNPageOrHigherPageView();
38+
39+
expect(output).toBe(false);
40+
});
41+
42+
test('default - checks for is n = 3 article views returns true', () => {
43+
incrementDailyArticleCount();
44+
incrementDailyArticleCount();
45+
incrementDailyArticleCount();
46+
47+
const output = isNPageOrHigherPageView(3);
48+
49+
expect(output).toBe(true);
50+
});
51+
52+
test('default - checks for is n = 5 article views returns false', () => {
53+
incrementDailyArticleCount();
54+
incrementDailyArticleCount();
55+
incrementDailyArticleCount();
56+
57+
const output = isNPageOrHigherPageView(5);
58+
59+
expect(output).toBe(false);
60+
});
61+
});
62+
63+
describe('isValidContentType', () => {
64+
test('is a valid type - article', () => {
65+
expect(isValidContentType('Article')).toBe(true);
66+
});
67+
68+
test('is not a valid type - LiveBlog', () => {
69+
expect(isValidContentType('LiveBlog')).toBe(false);
70+
});
71+
});
72+
73+
describe('isValidSection', () => {
74+
test('is valid section - politics - returns true', () => {
75+
expect(isValidSection('politics')).toBe(true);
76+
});
77+
78+
test('is valid section - membership - return false', () => {
79+
expect(isValidSection('membership')).toBe(false);
80+
});
81+
});
82+
83+
describe('isValidTag', () => {
84+
test('is valid tag - us-news/us-news - returns true', () => {
85+
expect(
86+
isValidTag([
87+
{
88+
id: 'us-news/us-news',
89+
type: 'Keyword',
90+
title: 'US news',
91+
},
92+
]),
93+
).toBe(true);
94+
});
95+
96+
test('is valid tag - info/newsletter-sign-up - return false', () => {
97+
expect(
98+
isValidTag([
99+
{
100+
id: 'info/newsletter-sign-up',
101+
type: 'Keyword',
102+
title: 'Newsletters',
103+
},
104+
]),
105+
).toBe(false);
106+
});
107+
});
108+
109+
describe('articleIdentifierIsAllowed', () => {
110+
expect(
111+
pageIdIsAllowedForGating(
112+
'money/2017/mar/10/ministers-to-criminalise-use-of-ticket-tout-harvesting-software',
113+
),
114+
).toBe(true);
115+
expect(pageIdIsAllowedForGating('tips')).toBe(false);
116+
expect(pageIdIsAllowedForGating('tips#test')).toBe(false);
117+
expect(pageIdIsAllowedForGating('tips/test')).toBe(false);
118+
});

dotcom-rendering/src/components/SignInGate/gates/alternative-wording-control.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { startPerformanceMeasure } from '@guardian/libs';
22
import React, { Suspense } from 'react';
33
import { Lazy } from '../../Lazy';
4-
import { canShowSignInGateWithOffers } from '../displayRule';
4+
import { canShowSignInGateWithOffers } from '../displayRules';
55
import type { SignInGateComponent } from '../types';
66

77
const SignInGateMain = React.lazy(() => {

dotcom-rendering/src/components/SignInGate/gates/alternative-wording-guardian-live.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { startPerformanceMeasure } from '@guardian/libs';
22
import React, { Suspense } from 'react';
33
import { Lazy } from '../../Lazy';
4-
import { canShowSignInGateWithOffers } from '../displayRule';
4+
import { canShowSignInGateWithOffers } from '../displayRules';
55
import type { SignInGateComponent } from '../types';
66

77
const SignInGateCustomizableText = React.lazy(() => {

dotcom-rendering/src/components/SignInGate/gates/alternative-wording-saturday-edition.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { startPerformanceMeasure } from '@guardian/libs';
22
import React, { Suspense } from 'react';
33
import { Lazy } from '../../Lazy';
4-
import { canShowSignInGateWithOffers } from '../displayRule';
4+
import { canShowSignInGateWithOffers } from '../displayRules';
55
import type { SignInGateComponent } from '../types';
66

77
const SignInGateCustomizableText = React.lazy(() => {

dotcom-rendering/src/components/SignInGate/gates/fake-social-variant.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { startPerformanceMeasure } from '@guardian/libs';
22
import React, { Suspense } from 'react';
33
import { Lazy } from '../../Lazy';
4-
import { canShowSignInGate } from '../displayRule';
4+
import { canShowSignInGate } from '../displayRules';
55
import type { SignInGateComponent } from '../types';
66

77
const SignInGateFakeSocial = React.lazy(() => {

dotcom-rendering/src/components/SignInGate/gates/main-control.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
isValidContentType,
55
isValidSection,
66
isValidTag,
7-
} from '../displayRule';
7+
} from '../displayRules';
88
import type { CanShowGateProps, SignInGateComponent } from '../types';
99

1010
const canShow = ({

dotcom-rendering/src/components/SignInGate/gates/main-mandatory-variant.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { startPerformanceMeasure } from '@guardian/libs';
22
import React, { Suspense } from 'react';
33
import { Lazy } from '../../Lazy';
4-
import { canShowSignInGateMandatory } from '../displayRule';
4+
import { canShowSignInGateMandatory } from '../displayRules';
55
import type { SignInGateComponent } from '../types';
66

77
const SignInGateMain = React.lazy(() => {

dotcom-rendering/src/components/SignInGate/gates/main-variant.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isUndefined, startPerformanceMeasure } from '@guardian/libs';
22
import React, { Suspense } from 'react';
33
import { Lazy } from '../../Lazy';
4-
import { canShowSignInGate } from '../displayRule';
4+
import { canShowSignInGate } from '../displayRules';
55
import type { SignInGateComponent } from '../types';
66

77
const SignInGateMain = React.lazy(() => {

0 commit comments

Comments
 (0)