@financial-times/n-myft-ui 25.0.0 → 25.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/.circleci/config.yml +0 -3
- package/README.md +0 -51
- package/build-state/npm-shrinkwrap.json +0 -442
- package/components/collections/collections.html +77 -0
- package/components/concept-list/concept-list.html +28 -0
- package/components/follow-button/__tests__/follow-button.test.js +3 -3
- package/components/follow-button/follow-button.jsx +3 -3
- package/components/pin-button/pin-button.html +20 -0
- package/components/save-for-later/save-for-later.html +67 -0
- package/demos/app.js +4 -2
- package/demos/templates/demo.html +7 -7
- package/demos/templates/demo.jsx +1 -93
- package/package.json +3 -7
- package/components/collections/collections.jsx +0 -68
- package/components/collections/collections.test.js +0 -83
- package/components/concept-list/concept-list.jsx +0 -55
- package/components/concept-list/concept-list.test.js +0 -116
- package/components/index.js +0 -15
- package/components/pin-button/pin-button.jsx +0 -40
- package/components/pin-button/pin-button.test.js +0 -57
- package/components/save-for-later/save-for-later.jsx +0 -103
- package/components/save-for-later/save-for-later.test.js +0 -59
- package/dist/bundles/bundle.js +0 -3133
- package/webpack.config.js +0 -34
@@ -1,116 +0,0 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import ConceptList from './concept-list';
|
3
|
-
import { render, screen } from '@testing-library/react';
|
4
|
-
import '@testing-library/jest-dom';
|
5
|
-
|
6
|
-
const fixtures = [
|
7
|
-
{
|
8
|
-
'conceptListTitle': 'Follow european union things',
|
9
|
-
'concepts': [
|
10
|
-
{
|
11
|
-
'id': '00000000-0000-0000-0000-000000000161',
|
12
|
-
'prefLabel': 'EU immigration',
|
13
|
-
'directType': 'http://www.ft.com/ontology/Topic',
|
14
|
-
'url': 'https://www.ft.com/stream/00000000-0000-0000-0000-000000000161',
|
15
|
-
'name': 'EU immigration'
|
16
|
-
},
|
17
|
-
{
|
18
|
-
'id': '00000000-0000-0000-0000-000000000162',
|
19
|
-
'prefLabel': 'Europe Quantitative Easing',
|
20
|
-
'directType': 'http://www.ft.com/ontology/Topic',
|
21
|
-
'url': 'https://www.ft.com/stream/00000000-0000-0000-0000-000000000162',
|
22
|
-
'name': 'Europe Quantitative Easing'
|
23
|
-
},
|
24
|
-
{
|
25
|
-
'id': '00000000-0000-0000-0000-000000000163',
|
26
|
-
'prefLabel': 'EU financial regulation',
|
27
|
-
'directType': 'http://www.ft.com/ontology/Topic',
|
28
|
-
'url': 'https://www.ft.com/stream/00000000-0000-0000-0000-000000000163',
|
29
|
-
'name': 'EU financial regulation'
|
30
|
-
},
|
31
|
-
{
|
32
|
-
'id': '00000000-0000-0000-0000-000000000164',
|
33
|
-
'prefLabel': 'EU nothing',
|
34
|
-
'directType': 'http://www.ft.com/ontology/Topic',
|
35
|
-
'url': 'https://www.ft.com/stream/00000000-0000-0000-0000-000000000164',
|
36
|
-
'name': 'EU nothing'
|
37
|
-
},
|
38
|
-
{
|
39
|
-
'id': '00000000-0000-0000-0000-000000000165',
|
40
|
-
'prefLabel': 'EU trade',
|
41
|
-
'directType': 'http://www.ft.com/ontology/Topic',
|
42
|
-
'url': 'https://www.ft.com/stream/00000000-0000-0000-0000-000000000165',
|
43
|
-
'name': 'EU trade'
|
44
|
-
}
|
45
|
-
]
|
46
|
-
},
|
47
|
-
{
|
48
|
-
'contentType': 'search',
|
49
|
-
'concepts': [
|
50
|
-
{
|
51
|
-
'id': '00000000-0000-0000-0000-000000000166',
|
52
|
-
'prefLabel': 'Noodle',
|
53
|
-
'directType': 'http://www.ft.com/ontology/Topic',
|
54
|
-
'url': 'https://www.ft.com/stream/00000000-0000-0000-0000-000000000166',
|
55
|
-
'name': 'Noodle'
|
56
|
-
},
|
57
|
-
{
|
58
|
-
'id': '00000000-0000-0000-0000-000000000167',
|
59
|
-
'prefLabel': 'Green apples',
|
60
|
-
'directType': 'http://www.ft.com/ontology/Topic',
|
61
|
-
'url': 'https://www.ft.com/stream/00000000-0000-0000-0000-000000000167',
|
62
|
-
'name': 'Green apples'
|
63
|
-
},
|
64
|
-
{
|
65
|
-
'id': '00000000-0000-0000-0000-000000000168',
|
66
|
-
'prefLabel': 'Fox blood',
|
67
|
-
'directType': 'http://www.ft.com/ontology/Topic',
|
68
|
-
'url': 'https://www.ft.com/stream/00000000-0000-0000-0000-000000000168',
|
69
|
-
'name': 'Fox blood'
|
70
|
-
},
|
71
|
-
{
|
72
|
-
'id': '00000000-0000-0000-0000-000000000169',
|
73
|
-
'prefLabel': 'Dog party',
|
74
|
-
'directType': 'http://www.ft.com/ontology/Topic',
|
75
|
-
'url': 'https://www.ft.com/stream/00000000-0000-0000-0000-000000000169',
|
76
|
-
'name': 'Dog party'
|
77
|
-
},
|
78
|
-
{
|
79
|
-
'id': '00000000-0000-0000-0000-000000000170',
|
80
|
-
'prefLabel': 'Fifth thing',
|
81
|
-
'directType': 'http://www.ft.com/ontology/Topic',
|
82
|
-
'url': 'https://www.ft.com/stream/00000000-0000-0000-0000-000000000170',
|
83
|
-
'name': 'Fifth thing'
|
84
|
-
}
|
85
|
-
]
|
86
|
-
},
|
87
|
-
];
|
88
|
-
|
89
|
-
|
90
|
-
const flags = {
|
91
|
-
myFtApi: true,
|
92
|
-
myFtApiWrite: true
|
93
|
-
};
|
94
|
-
|
95
|
-
describe('Concept List', () => {
|
96
|
-
|
97
|
-
test('It renders conceptListTitle value as title when conceptListTitle is provided', async () => {
|
98
|
-
render(<ConceptList {...fixtures[0]} flags={flags} />);
|
99
|
-
expect(await screen.findByText('Follow european union things')).toBeTruthy();
|
100
|
-
});
|
101
|
-
|
102
|
-
test('It renders "Follow the topics in this {conceptType}" value as title when conceptType is provided', async () => {
|
103
|
-
render(<ConceptList {...fixtures[1]} flags={flags} />);
|
104
|
-
expect(await screen.findByText('Follow the topics in this search')).toBeTruthy();
|
105
|
-
});
|
106
|
-
|
107
|
-
test('It renders label for the concept button', async () => {
|
108
|
-
render(<ConceptList {...fixtures[0]} flags={flags} />);
|
109
|
-
expect(await screen.findByText('EU immigration')).toBeTruthy();
|
110
|
-
expect(await screen.findByText('Europe Quantitative Easing')).toBeTruthy();
|
111
|
-
expect(await screen.findByText('EU financial regulation')).toBeTruthy();
|
112
|
-
expect(await screen.findByText('EU nothing')).toBeTruthy();
|
113
|
-
expect(await screen.findByText('EU trade')).toBeTruthy();
|
114
|
-
});
|
115
|
-
|
116
|
-
});
|
package/components/index.js
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
import CsrfToken from './csrf-token/input';
|
2
|
-
import FollowButton from './follow-button/follow-button';
|
3
|
-
import ConceptList from './concept-list/concept-list';
|
4
|
-
import Collections from './collections/collections';
|
5
|
-
import SaveForLater from './save-for-later/save-for-later';
|
6
|
-
import PinButton from './pin-button/pin-button';
|
7
|
-
|
8
|
-
export {
|
9
|
-
CsrfToken,
|
10
|
-
FollowButton,
|
11
|
-
ConceptList,
|
12
|
-
Collections,
|
13
|
-
SaveForLater,
|
14
|
-
PinButton
|
15
|
-
};
|
@@ -1,40 +0,0 @@
|
|
1
|
-
import React, { Fragment } from 'react';
|
2
|
-
import CsrfToken from '../csrf-token/input';
|
3
|
-
export default function PinButton ({ showPrioritiseButton, id, name, directType, prioritised }) {
|
4
|
-
|
5
|
-
const getAction = () => `/__myft/api/core/prioritised/concept/${id}?method=${prioritised ? 'delete' : 'put'}`
|
6
|
-
|
7
|
-
return (
|
8
|
-
<Fragment>
|
9
|
-
{showPrioritiseButton &&
|
10
|
-
<Fragment>
|
11
|
-
<span className="myft-pin-divider"></span>
|
12
|
-
<div className="myft-pin-button-wrapper">
|
13
|
-
<form method="post" action={getAction()} data-myft-prioritise>
|
14
|
-
<CsrfToken />
|
15
|
-
<input type="hidden" value={name} name="name" />
|
16
|
-
<input type="hidden" value={directType || 'http://www.ft.com/ontology/concept/Concept'} name="directType" />
|
17
|
-
<div
|
18
|
-
className="n-myft-ui__announcement o-normalise-visually-hidden"
|
19
|
-
aria-live="assertive"
|
20
|
-
data-pressed-text={`${name} pinned in myFT.`}
|
21
|
-
data-unpressed-text={`Unpinned ${name} from myFT.`}
|
22
|
-
></div>
|
23
|
-
<button id={`myft-pin-button__${id}`}
|
24
|
-
className="myft-pin-button"
|
25
|
-
data-prioritise-button
|
26
|
-
data-trackable="prioritised"
|
27
|
-
data-concept-id={id}
|
28
|
-
data-prioritised={prioritised ? true : false}
|
29
|
-
aria-label={`${prioritised ? 'Unpin' : 'Pin'} ${name} ${prioritised ? 'from' : 'in'} myFT`}
|
30
|
-
aria-pressed={prioritised ? true : false}
|
31
|
-
title={`${prioritised ? 'Unpin' : 'Pin'} ${name}`}>
|
32
|
-
</button>
|
33
|
-
</form>
|
34
|
-
</div>
|
35
|
-
</Fragment>
|
36
|
-
}
|
37
|
-
</Fragment>
|
38
|
-
)
|
39
|
-
|
40
|
-
}
|
@@ -1,57 +0,0 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import { render } from '@testing-library/react';
|
3
|
-
import '@testing-library/jest-dom';
|
4
|
-
import PinButton from './pin-button';
|
5
|
-
|
6
|
-
const flags = {
|
7
|
-
myFtApi: true,
|
8
|
-
myFtApiWrite: true
|
9
|
-
};
|
10
|
-
|
11
|
-
const fixtures = [
|
12
|
-
{
|
13
|
-
id: '00000000-0000-0000-0000-000000000022',
|
14
|
-
name: 'myFT Enterprises',
|
15
|
-
directType: 'http://www.ft.com/ontology/Topic',
|
16
|
-
showPrioritiseButton: true
|
17
|
-
},
|
18
|
-
{
|
19
|
-
id: '00000000-0000-0000-0000-000000000023',
|
20
|
-
name: 'myFT Enterprises',
|
21
|
-
directType: 'http://www.ft.com/ontology/Topic',
|
22
|
-
showPrioritiseButton: false
|
23
|
-
}
|
24
|
-
];
|
25
|
-
|
26
|
-
|
27
|
-
describe('Pin Button', () => {
|
28
|
-
|
29
|
-
test('It renders', () => {
|
30
|
-
const { container } = render(<PinButton flags={flags} {...fixtures[0]} />);
|
31
|
-
expect(container.querySelector(`button[id="myft-pin-button__${fixtures[0].id}"]`)).toBeTruthy();
|
32
|
-
expect(container.querySelector('button[data-trackable="prioritised"]')).toBeTruthy();
|
33
|
-
});
|
34
|
-
|
35
|
-
test('It renders unprioritised', () => {
|
36
|
-
const { container } = render(<PinButton flags={flags} {...fixtures[0]} />);
|
37
|
-
expect(container.querySelector('button[aria-label="Pin myFT Enterprises in myFT"]')).toBeTruthy();
|
38
|
-
expect(container.querySelector('button[title="Pin myFT Enterprises"]')).toBeTruthy();
|
39
|
-
expect(container.querySelector('button[data-prioritised=false]')).toBeTruthy();
|
40
|
-
expect(container.querySelector(`button[data-concept-id="${fixtures[0].id}"]`)).toBeTruthy();
|
41
|
-
});
|
42
|
-
|
43
|
-
test('It renders with prioritised', () => {
|
44
|
-
const { container } = render(<PinButton flags={flags} prioritised={true} {...fixtures[0]} />);
|
45
|
-
expect(container.querySelector('button[aria-label="Unpin myFT Enterprises from myFT"]')).toBeTruthy();
|
46
|
-
expect(container.querySelector('button[title="Unpin myFT Enterprises"]')).toBeTruthy();
|
47
|
-
expect(container.querySelector('button[data-prioritised=true]')).toBeTruthy();
|
48
|
-
expect(container.querySelector(`button[data-concept-id="${fixtures[0].id}"]`)).toBeTruthy();
|
49
|
-
});
|
50
|
-
|
51
|
-
test('It renders the form element', () => {
|
52
|
-
const { container } = render(<PinButton flags={flags} {...fixtures[0]} />);
|
53
|
-
expect(container.querySelector('form[method="post"]')).toBeTruthy();
|
54
|
-
expect(container.querySelector(`form[action="/__myft/api/core/prioritised/concept/${fixtures[0].id}?method=put"]`)).toBeTruthy();
|
55
|
-
});
|
56
|
-
|
57
|
-
});
|
@@ -1,103 +0,0 @@
|
|
1
|
-
import React, { Fragment } from 'react';
|
2
|
-
import CsrfToken from '../csrf-token/input';
|
3
|
-
|
4
|
-
const ButtonContent = ({ saveButtonWithIcon, buttonText, isSaved, appIsStreamPage }) => {
|
5
|
-
|
6
|
-
return (<Fragment>
|
7
|
-
{
|
8
|
-
saveButtonWithIcon &&
|
9
|
-
<span className="save-button-with-icon-copy" data-variant-label>
|
10
|
-
{buttonText && buttonText}
|
11
|
-
{!buttonText && (isSaved ? 'Saved' : 'Save')}
|
12
|
-
</span>
|
13
|
-
}
|
14
|
-
|
15
|
-
{
|
16
|
-
!saveButtonWithIcon &&
|
17
|
-
<Fragment>
|
18
|
-
{buttonText && buttonText}
|
19
|
-
{!buttonText &&
|
20
|
-
<Fragment>
|
21
|
-
{
|
22
|
-
appIsStreamPage !== true &&
|
23
|
-
<Fragment>
|
24
|
-
<span className="save-button-longer-copy" data-variant-label>
|
25
|
-
{isSaved ? 'Saved ' : 'Save '}
|
26
|
-
</span>
|
27
|
-
<span className="n-myft-ui__button--viewport-large" aria-hidden="true">to myFT</span>
|
28
|
-
</Fragment>
|
29
|
-
}
|
30
|
-
|
31
|
-
{
|
32
|
-
appIsStreamPage === true && <span>{isSaved ? 'Saved' : 'Save'}</span>
|
33
|
-
}
|
34
|
-
</Fragment>
|
35
|
-
}
|
36
|
-
</Fragment>
|
37
|
-
}
|
38
|
-
</Fragment>);
|
39
|
-
}
|
40
|
-
export default function SaveForLater ({ flags, contentId, title, variant, trackableId, isSaved, appIsStreamPage, alternateText, saveButtonWithIcon, buttonText }) {
|
41
|
-
|
42
|
-
const { myFtApiWrite } = flags;
|
43
|
-
|
44
|
-
const generateSubmitButtonProps = () => {
|
45
|
-
let props = {
|
46
|
-
type: 'submit',
|
47
|
-
'data-trackable': trackableId ? trackableId : 'save-for-later',
|
48
|
-
'data-text-variant': appIsStreamPage !== true ? 'save-button-with-icon-copy' : 'save-button-longer-copy',
|
49
|
-
'data-content-id': contentId,
|
50
|
-
className: saveButtonWithIcon ? 'n-myft-ui__save-button-with-icon' : `n-myft-ui__button ${variant ? `n-myft-ui__button--${variant}` : ''}`
|
51
|
-
};
|
52
|
-
|
53
|
-
if (isSaved) {
|
54
|
-
let titleText = `${title ? `${title} is` : ''} Saved to myFT`;
|
55
|
-
props['title'] = title;
|
56
|
-
props['aria-label'] = titleText;
|
57
|
-
props['data-alternate-label'] = title ? `Save ${title} to myFT for later` : 'Save this article to myFT for later';
|
58
|
-
props['aria-pressed'] = true;
|
59
|
-
} else {
|
60
|
-
let titleText = title ? `Save ${title} to myFT for later` : 'Save this article to myFT for later';
|
61
|
-
props['title'] = titleText;
|
62
|
-
props['aria-label'] = titleText;
|
63
|
-
props['data-alternate-label'] = `${title ? `${title} is` : ''} Saved to myFT`;
|
64
|
-
props['aria-pressed'] = false;
|
65
|
-
}
|
66
|
-
|
67
|
-
if (alternateText) {
|
68
|
-
props['data-alternate-text'] = alternateText;
|
69
|
-
} else if (isSaved) {
|
70
|
-
props['data-alternate-text'] = 'Save ';
|
71
|
-
} else {
|
72
|
-
props['data-alternate-text'] = 'Saved ';
|
73
|
-
}
|
74
|
-
|
75
|
-
return props;
|
76
|
-
}
|
77
|
-
|
78
|
-
|
79
|
-
return (
|
80
|
-
<Fragment>
|
81
|
-
{myFtApiWrite &&
|
82
|
-
<form className="n-myft-ui n-myft-ui--save" method="GET"
|
83
|
-
data-content-id={contentId}
|
84
|
-
data-myft-ui="saved"
|
85
|
-
action={`/myft/save/${contentId}`}
|
86
|
-
data-js-action={`/__myft/api/core/saved/content/${contentId}?method=put`}>
|
87
|
-
<CsrfToken />
|
88
|
-
|
89
|
-
<div
|
90
|
-
className="n-myft-ui__announcement o-normalise-visually-hidden"
|
91
|
-
aria-live="assertive"
|
92
|
-
data-pressed-text="Article saved in My FT."
|
93
|
-
data-unpressed-text="Removed article from My FT."
|
94
|
-
></div>
|
95
|
-
<button {...generateSubmitButtonProps()}>
|
96
|
-
<ButtonContent buttonText={buttonText} saveButtonWithIcon={saveButtonWithIcon} isSaved={isSaved} appIsStreamPage={appIsStreamPage}/>
|
97
|
-
</button>
|
98
|
-
</form>
|
99
|
-
}
|
100
|
-
</Fragment>
|
101
|
-
|
102
|
-
)
|
103
|
-
}
|
@@ -1,59 +0,0 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import SaveForLater from './save-for-later';
|
3
|
-
import { render, screen } from '@testing-library/react';
|
4
|
-
import '@testing-library/jest-dom';
|
5
|
-
|
6
|
-
const flags = {
|
7
|
-
myFtApi: true,
|
8
|
-
myFtApiWrite: true
|
9
|
-
};
|
10
|
-
|
11
|
-
const fixture = {
|
12
|
-
contentId: '00000000-0000-0000-0000-000000000033',
|
13
|
-
title: 'myFT Enterprises'
|
14
|
-
};
|
15
|
-
|
16
|
-
describe('SaveForLater component', () => {
|
17
|
-
|
18
|
-
test('It renders', async () => {
|
19
|
-
render(<SaveForLater flags={flags} {...fixture}/>);
|
20
|
-
expect(await screen.findByText('Save')).toBeTruthy();
|
21
|
-
});
|
22
|
-
|
23
|
-
test('It renders button text wen provided', async () => {
|
24
|
-
render(<SaveForLater flags={flags} {...fixture} buttonText={'Globetrotter'}/>);
|
25
|
-
expect(await screen.findByText('Globetrotter')).toBeTruthy();
|
26
|
-
});
|
27
|
-
|
28
|
-
test('It renders the correct form action attribute', () => {
|
29
|
-
const { container } = render(<SaveForLater flags={flags} {...fixture} buttonText={'Globetrotter'}/>);
|
30
|
-
const formElement = container.querySelector(`form[action="/myft/save/${fixture.contentId}"]`);
|
31
|
-
expect(formElement).toBeTruthy();
|
32
|
-
});
|
33
|
-
|
34
|
-
test('It renders the correct form data-js-action attribute', () => {
|
35
|
-
const { container } = render(<SaveForLater flags={flags} {...fixture} buttonText={'Globetrotter'}/>);
|
36
|
-
const formElement = container.querySelector(`form[data-js-action="/__myft/api/core/saved/content/${fixture.contentId}?method=put"]`);
|
37
|
-
expect(formElement).toBeTruthy();
|
38
|
-
});
|
39
|
-
|
40
|
-
test('It renders the correct form method attribute', () => {
|
41
|
-
const { container } = render(<SaveForLater flags={flags} {...fixture} buttonText={'Globetrotter'}/>);
|
42
|
-
const formElement = container.querySelector('form[method="GET"]');
|
43
|
-
expect(formElement).toBeTruthy();
|
44
|
-
});
|
45
|
-
|
46
|
-
test('It renders the correct button data-text-variant attribute when appIsStreamPage=true', () => {
|
47
|
-
const { container } = render(<SaveForLater appIsStreamPage={true} flags={flags} {...fixture} buttonText={'Globetrotter'}/>);
|
48
|
-
const buttonElement = container.querySelector('button[data-text-variant="save-button-longer-copy"]');
|
49
|
-
expect(buttonElement).toBeTruthy();
|
50
|
-
});
|
51
|
-
|
52
|
-
describe('Saved', () => {
|
53
|
-
test('It renders saved item', async () => {
|
54
|
-
render(<SaveForLater isSaved={true} flags={flags} {...fixture}/>);
|
55
|
-
expect(await screen.findByText('Saved')).toBeTruthy();
|
56
|
-
});
|
57
|
-
});
|
58
|
-
|
59
|
-
});
|