@operato/app 10.24.0 → 10.25.0

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
@@ -2,7 +2,7 @@
2
2
  "name": "@operato/app",
3
3
  "description": "WebApplication production supporting components following open-wc recommendations",
4
4
  "author": "heartyoh",
5
- "version": "10.24.0",
5
+ "version": "10.25.0",
6
6
  "type": "module",
7
7
  "main": "dist/src/index.js",
8
8
  "module": "dist/src/index.js",
@@ -201,5 +201,5 @@
201
201
  "prettier --write"
202
202
  ]
203
203
  },
204
- "gitHead": "c3cb8b0e25f05aba9836418b05bc0e24c8095797"
204
+ "gitHead": "98d2e2b33bcb60d78d5cee6d56f410ff59ca386a"
205
205
  }
@@ -0,0 +1,75 @@
1
+ import { expect } from '@open-wc/testing'
2
+ import { html } from 'lit-html'
3
+
4
+ import { registerEntity360Kind } from '@operato/layout'
5
+ import { OxGristRendererResourceObject } from '../src/grist-editor/ox-grist-renderer-resource-object.js'
6
+
7
+ /**
8
+ * The resource-object cell links a value to its 360 only when its kind is registered - and otherwise
9
+ * returns exactly what it always did (architect ruling on the person 360: dssp and fmsim render
10
+ * through this cell, and their screens must not change by a byte).
11
+ *
12
+ * `original` is the renderer as it stood before, kept verbatim here as the reference.
13
+ */
14
+ function original(value: any, column: any) {
15
+ if (!value) {
16
+ return ''
17
+ }
18
+
19
+ var { nameField = 'name', descriptionField = 'description' } = column.record.options || {}
20
+ var name, description
21
+
22
+ if (typeof nameField === 'function') {
23
+ name = nameField(value)
24
+ } else {
25
+ name = value[nameField]
26
+ }
27
+
28
+ if (typeof descriptionField === 'function') {
29
+ description = descriptionField(value)
30
+ } else {
31
+ description = value[descriptionField] && `(${value[descriptionField]})`
32
+ }
33
+
34
+ return html`<span>${name || ''}${description || ''}</span> `
35
+ }
36
+
37
+ const column = (options?: any) => ({ record: { options } }) as any
38
+ const render = (value: any, col = column()) => (OxGristRendererResourceObject as any)(value, col, {}, 0, {})
39
+
40
+ /** A template's identity: the same static strings and the same values. */
41
+ const same = (a: any, b: any) => {
42
+ if (typeof a === 'string' || typeof b === 'string') return a === b
43
+ return a.strings === b.strings || (a.strings.join('\u0000') === b.strings.join('\u0000') && JSON.stringify(a.values) === JSON.stringify(b.values))
44
+ }
45
+
46
+ describe('resource-object cell and the entity 360', () => {
47
+ before(() => {
48
+ registerEntity360Kind({ kind: 'cell-test-person', typenames: ['CellTestUser'], title: s => s.value.name })
49
+ })
50
+
51
+ const unchanged = [
52
+ ['an unregistered type', { __typename: 'SomethingElse', id: '1', name: 'Kim', description: 'QA' }],
53
+ ['a value without __typename', { id: '1', name: 'Kim', description: 'QA' }],
54
+ ['a value with a name only', { __typename: 'Nobody', id: '2', name: 'Lee' }],
55
+ ['no value at all', null]
56
+ ] as const
57
+
58
+ for (const [what, value] of unchanged) {
59
+ it(`★ ${what} renders exactly as before`, () => {
60
+ expect(same(render(value), original(value, column()))).to.equal(true)
61
+ })
62
+ }
63
+
64
+ it('★ and with custom name and description fields, still exactly as before', () => {
65
+ const col = column({ nameField: 'title', descriptionField: (v: any) => `[${v.code}]` })
66
+ const value = { __typename: 'Other', title: 'T', code: 'C' }
67
+ expect(same(render(value, col), original(value, col))).to.equal(true)
68
+ })
69
+
70
+ it('★ a registered type renders the name as a link to its 360', () => {
71
+ const result = render({ __typename: 'CellTestUser', id: '9', name: 'Park' })
72
+ expect(result.strings.join('')).to.contain('data-entity360')
73
+ expect(result.values).to.include('Park')
74
+ })
75
+ })