Skip to content

Commit d527997

Browse files
committed
testing
1 parent 85020be commit d527997

File tree

3 files changed

+93
-44
lines changed

3 files changed

+93
-44
lines changed

src/chat/message.js

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@ import * as style from '../style'
1919
import * as utils from '../utils'
2020
import * as widgets from '../widgets'
2121
import { getBlankMsg, verifySignature, SEC } from './signature'
22-
import { getPrivateKey, getPublicKey } from './keys'
22+
import { getPublicKey } from './keys'
2323

2424
const dom = window.document
2525
const messageBodyStyle = style.messageBodyStyle
2626

2727
const label = utils.label
2828

2929
/**
30+
* elementForImageURI
3031
* HTML component for an image
32+
* @param imageUri
33+
* @param options { inlineImageHeightEms }
34+
* @returns HTMLAnchorElement For Image
3135
*/
3236
export function elementForImageURI (imageUri, options) {
3337
const img = dom.createElement('img')
@@ -61,33 +65,45 @@ const anchor = function (text, term) {
6165
return a
6266
}
6367

64-
function nick (person) {
68+
function nickname (person) {
6569
const s = store.any(person, ns.foaf('nick'))
6670
if (s) return '' + s.value
6771
return '' + label(person)
6872
}
6973

7074
/**
75+
* creatorAndDate
7176
* Displays creator and date for a chat message
7277
* inside the `td1` element
78+
* @param td1
79+
* @param creator
80+
* @param date
81+
* @param message
82+
* @returns HTMLAnchorElement For Image
7383
*/
7484
export function creatorAndDate (td1, creator, date, message) {
75-
const nickAnchor = td1.appendChild(anchor(nick(creator), creator))
85+
const nickAnchor = td1.appendChild(anchor(nickname(creator), creator))
7686
if (creator.uri) {
7787
store.fetcher.nowOrWhenFetched(creator.doc(), undefined, function (
7888
_ok,
7989
_body
8090
) {
81-
nickAnchor.textContent = nick(creator)
91+
nickAnchor.textContent = nickname(creator)
8292
})
8393
}
8494
td1.appendChild(dom.createElement('br'))
8595
td1.appendChild(anchor(date, message))
8696
}
8797

8898
/**
99+
* creatorAndDateHorizontal
89100
* Horizontally displays creator and date for a chat message
90101
* inside the `td1` element
102+
* @param td1
103+
* @param creator
104+
* @param date
105+
* @param message
106+
* @returns HTMLAnchorElement For Image
91107
*/
92108
export function creatorAndDateHorizontal (td1, creator, date, message) {
93109
const nickAnchor = td1.appendChild(anchor(label(creator), creator))
@@ -96,7 +112,7 @@ export function creatorAndDateHorizontal (td1, creator, date, message) {
96112
_ok,
97113
_body
98114
) {
99-
nickAnchor.textContent = nick(creator)
115+
nickAnchor.textContent = nickname(creator)
100116
})
101117
}
102118
const dateBit = td1.appendChild(anchor(date, message))
@@ -106,12 +122,20 @@ export function creatorAndDateHorizontal (td1, creator, date, message) {
106122
}
107123

108124
/**
125+
* renderMessageRow
109126
* Renders a chat message, read-only mode
127+
* @param channelObject
128+
* @param message
129+
* @param fresh
130+
* @param options
131+
* @param userContext
132+
* @returns Message Row HTML Table Element
110133
*/
111134
export function renderMessageRow (channelObject, message, fresh, options, userContext) {
135+
let unsignedMessage = false
112136
const colorizeByAuthor =
113137
options.colorizeByAuthor === '1' || options.colorizeByAuthor === true
114-
138+
debug.log('HELLOOOOO SI am here using this render')
115139
const creator = store.any(message, ns.foaf('maker'))
116140
const date = store.any(message, ns.dct('created'))
117141
const latestVersion = mostRecentVersion(message)
@@ -130,10 +154,10 @@ export function renderMessageRow (channelObject, message, fresh, options, userCo
130154
msg.maker = creator.uri
131155

132156
// unsigned message
133-
if (!signature?.value) debug.warn(msgId.uri + ' is unsigned') // TODO replace with UI (colored message ?)
134-
135-
// signed message, get public key and check signature
136-
else {
157+
if (!signature?.value) {
158+
unsignedMessage = true
159+
debug.warn(msgId.uri + ' is unsigned') // TODO replace with UI (colored message ?)
160+
} else { // signed message, get public key and check signature
137161
getPublicKey(creator).then(publicKey => {
138162
debug.log(creator.uri + '\n' + msg.created + '\n' + msg.id + '\n' + publicKey)
139163
if (!publicKey) {
@@ -155,6 +179,7 @@ export function renderMessageRow (channelObject, message, fresh, options, userCo
155179
const sortDate = store.the(originalMessage, ns.dct('created'), null, originalMessage.doc()) // In message
156180

157181
const messageRow = dom.createElement('tr')
182+
if (unsignedMessage) messageRow.setAttribute('style', 'background-color: red')
158183
messageRow.AJAR_date = sortDate.value
159184
messageRow.AJAR_subject = message
160185

@@ -262,7 +287,7 @@ export function renderMessageRow (channelObject, message, fresh, options, userCo
262287
toolsTD.appendChild(tools)
263288
})
264289
return messageRow
265-
}
290+
} // END OF RENDERMESSAGE
266291

267292
export function switchToEditor (messageRow, message, channelObject, userContext) {
268293
const messageTable = messageRow.parentNode

src/utils/keyHelpers/accessData.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,6 @@ export async function getKeyIfExists (webId: NamedNode, keyUrl: string, keyType:
5858
const key = store.any(webId, store.sym(CERT + keyType))
5959
return key?.value // as NamedNode
6060
} catch (err) {
61-
if (err?.response?.status === 404) { // If PATCH on some server do not all create intermediate containers
62-
try {
63-
// create resource
64-
const data = ''
65-
const contentType = 'text/turtle'
66-
const response = await store.fetcher.webOperation('PUT', keyUrl, {
67-
data,
68-
contentType
69-
})
70-
} catch (err) {
71-
debug.log('createIfNotExists doc FAILED: ' + keyUrl + ': ' + err)
72-
throw err
73-
}
74-
delete store.fetcher.requested[keyUrl] // delete cached 404 error
75-
return undefined
76-
}
7761
debug.log('createIfNotExists doc FAILED: ' + keyUrl + ': ' + err)
7862
throw err
7963
}

test/unit/chat/message.test.ts

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,45 @@ import {
55
creatorAndDateHorizontal,
66
renderMessageRow
77
} from '../../../src/chat/message'
8+
import { store } from 'solid-logic'
9+
// import { originalVersion } from '../../../src/chat/chatLogic'
10+
import * as widgets from '../../../src/widgets'
11+
12+
const bindings = {
13+
'?creator': {
14+
value: {
15+
termType: ''
16+
}
17+
},
18+
'?date': {
19+
value: ''
20+
},
21+
doc: () => '',
22+
'?content': {
23+
value: ''
24+
},
25+
sameTerm: () => ''
26+
}
27+
28+
store.any = jest.fn()
29+
store.the = jest.fn()
30+
31+
jest.mock('../../../src/widgets', () => {
32+
const originalModule = jest.requireActual('../../../src/widgets')
33+
return {
34+
__esModule: true,
35+
...originalModule,
36+
setImage: () => '',
37+
shortDate: () => ''
38+
}
39+
})
40+
41+
jest.mock('../../../src/chat/chatLogic', () => {
42+
return {
43+
mostRecentVersion: jest.fn(() => ''),
44+
originalVersion: jest.fn(() => bindings)
45+
}
46+
})
847

948
silenceDebugMessages()
1049

@@ -62,26 +101,27 @@ describe('renderMessageRow', () => {
62101
it('exists', () => {
63102
expect(renderMessageRow).toBeInstanceOf(Function)
64103
})
65-
it.skip('runs', () => {
104+
it('runs', () => {
105+
// first store.any should return creator
106+
// the second should return a date
107+
// third shoudl return latestVersionCreator
108+
// content
109+
// signature
110+
// created
111+
//
112+
/* @ts-ignore */
113+
store.any.mockReturnValueOnce('creator')
114+
.mockReturnValueOnce('date')
115+
.mockReturnValueOnce('latestVersion')
116+
.mockReturnValueOnce({ value: 'content' })
117+
.mockReturnValueOnce('signature')
118+
.mockReturnValueOnce('created')
119+
/* @ts-ignore */
120+
store.the.mockReturnValue('test')
66121
const messageTable = {
67122
appendChild: () => {}
68123
}
69-
const bindings = {
70-
'?creator': {
71-
value: {
72-
termType: ''
73-
}
74-
},
75-
'?date': {
76-
value: ''
77-
},
78-
'?msg': {
79-
doc: () => ''
80-
},
81-
'?content': {
82-
value: ''
83-
}
84-
}
124+
85125
const fresh = {}
86126
const options = {}
87127
const userContext = {}

0 commit comments

Comments
 (0)