@financial-times/dotcom-ui-data-embed 7.3.0 → 7.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,19 +1,18 @@
1
1
  {
2
2
  "name": "@financial-times/dotcom-ui-data-embed",
3
- "version": "7.3.0",
3
+ "version": "7.3.2",
4
4
  "description": "",
5
5
  "main": "component.js",
6
6
  "browser": "browser.js",
7
7
  "types": "src/index.ts",
8
8
  "scripts": {
9
9
  "test": "echo \"Error: no test specified\" && exit 1",
10
- "tsc": "../../node_modules/.bin/tsc --incremental",
11
10
  "clean": "npm run clean:dist && npm run clean:node_modules",
12
11
  "clean:dist": "rm -rf dist",
13
12
  "clean:node_modules": "rm -rf node_modules",
14
13
  "clean:install": "npm run clean && npm i",
15
- "build:node": "npm run tsc -- --module commonjs --outDir ./dist/node",
16
- "build:browser": "npm run tsc -- --module es2015 --outDir ./dist/browser",
14
+ "build:browser": "tsc --module es2015 --outDir ./dist/browser",
15
+ "build:node": "tsc",
17
16
  "build": "npm run build:node && npm run build:browser",
18
17
  "dev": "echo -n node browser | parallel -u -d ' ' npm run build:{} -- --watch",
19
18
  "preinstall": "[ \"$INIT_CWD\" != \"$PWD\" ] || npm_config_yes=true npx check-engine"
@@ -28,6 +27,13 @@
28
27
  "peerDependencies": {
29
28
  "react": "16.x || 17.x"
30
29
  },
30
+ "files": [
31
+ "dist/",
32
+ "src/",
33
+ "browser.js",
34
+ "component.js",
35
+ "server.js"
36
+ ],
31
37
  "repository": {
32
38
  "type": "git",
33
39
  "repository": "https://github.com/Financial-Times/dotcom-page-kit.git",
@@ -41,4 +47,4 @@
41
47
  "check-engine": "^1.10.1",
42
48
  "react": "^16.8.6"
43
49
  }
44
- }
50
+ }
@@ -0,0 +1,37 @@
1
+ import subject from '../../client/DataEmbedStore'
2
+
3
+ const fakeData = {
4
+ foo: 1,
5
+ bar: true,
6
+ baz: 'qux'
7
+ }
8
+
9
+ describe('dotcom-ui-data-embed/src/client/DataEmbedStore', () => {
10
+ let instance
11
+
12
+ beforeEach(() => {
13
+ instance = new subject(fakeData)
14
+ })
15
+
16
+ describe('.get()', () => {
17
+ it('returns the value of an existing data', () => {
18
+ expect(instance.get('foo')).toBe(1)
19
+ expect(instance.get('bar')).toBe(true)
20
+ expect(instance.get('baz')).toBe('qux')
21
+ })
22
+
23
+ it('returns undefined for properties that do not exist', () => {
24
+ expect(instance.get('buzz')).toBeUndefined()
25
+ })
26
+ })
27
+
28
+ describe('.getAll()', () => {
29
+ it('returns all data', () => {
30
+ expect(instance.getAll()).toEqual(fakeData)
31
+ })
32
+
33
+ it('freezes the data', () => {
34
+ expect(Object.isFrozen(instance.getAll())).toBe(true)
35
+ })
36
+ })
37
+ })
@@ -0,0 +1,16 @@
1
+ import { init as subject } from '../../client'
2
+ import loadDataEmbed from '../../client/loadDataEmbed'
3
+ import DataEmbedStore from '../../client/DataEmbedStore'
4
+ jest.mock('../../client/loadDataEmbed.ts')
5
+ jest.mock('../../client/DataEmbedStore.ts')
6
+
7
+ describe('dotcom-ui-data-embed/src/client/index', () => {
8
+ describe('.init()', () => {
9
+ it('returns the value of an existing data embed store', () => {
10
+ const result = subject({ id: 'data-embed' })
11
+ expect(result).toBeInstanceOf(DataEmbedStore)
12
+ expect(loadDataEmbed).toBeCalledWith('data-embed')
13
+ expect(DataEmbedStore).toHaveBeenCalledTimes(1)
14
+ })
15
+ })
16
+ })
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+
5
+ import subject from '../../client/loadDataEmbed'
6
+ const SCRIPT_ELEMENT_ID = 'data-embed'
7
+
8
+ describe('dotcom-ui-data-embed/src/client/loadDataEmbed', () => {
9
+ describe('when there is a configuration object', () => {
10
+ beforeEach(() => {
11
+ document.body.innerHTML = `
12
+ <script id="${SCRIPT_ELEMENT_ID}">{"foo":1,"bar":true,"baz":"qux"}</script>
13
+ `
14
+ })
15
+
16
+ it('returns a frozen object', () => {
17
+ const result = subject(SCRIPT_ELEMENT_ID)
18
+
19
+ expect(result).toEqual({ foo: 1, bar: true, baz: 'qux' })
20
+ expect(Object.isFrozen(result)).toBe(true)
21
+ })
22
+ })
23
+
24
+ describe('when there is no a configuration object', () => {
25
+ beforeEach(() => {
26
+ document.body.innerHTML = ''
27
+ })
28
+
29
+ it('returns a frozen empty object', () => {
30
+ const result = subject(SCRIPT_ELEMENT_ID)
31
+
32
+ expect(result).toEqual({})
33
+ expect(Object.isFrozen(result)).toBe(true)
34
+ })
35
+ })
36
+ })
@@ -0,0 +1,18 @@
1
+ import renderer from 'react-test-renderer'
2
+ import { DataEmbed as subject } from '../../components/DataEmbed'
3
+
4
+ const data = {
5
+ id: 'data-embed',
6
+ data: {
7
+ foo: 1,
8
+ bar: true,
9
+ baz: 'qux'
10
+ }
11
+ }
12
+
13
+ describe('dotcom-ui-data-embed/src/components/dataEmbed', () => {
14
+ it('renders a script element containing data', () => {
15
+ const tree = renderer.create(subject(data))
16
+ expect(tree).toMatchSnapshot()
17
+ })
18
+ })
@@ -0,0 +1,13 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`dotcom-ui-data-embed/src/components/dataEmbed renders a script element containing data 1`] = `
4
+ <script
5
+ dangerouslySetInnerHTML={
6
+ Object {
7
+ "__html": "{\\"foo\\":1,\\"bar\\":true,\\"baz\\":\\"qux\\"}",
8
+ }
9
+ }
10
+ id="data-embed"
11
+ type="application/json"
12
+ />
13
+ `;