Skip to content

Commit 43b949d

Browse files
snewcomerJosé Valim
authored andcommitted
[BUGFIX]: morphdom v2.5.11 bump (#524)
1 parent 59ec6eb commit 43b949d

4 files changed

Lines changed: 84 additions & 8 deletions

File tree

assets/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"test.watch": "jest --watch"
1414
},
1515
"dependencies": {
16-
"morphdom": "2.5.5",
16+
"morphdom": "2.5.12",
1717
"phoenix_html": "file:../deps/phoenix_html"
1818
},
1919
"devDependencies": {

assets/test/view_test.js

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import LiveSocket, {View, DOM} from '../js/phoenix_live_view'
33

44
function liveViewDOM() {
55
const div = document.createElement('div')
6-
div.setAttribute('data-phx-view', '')
6+
div.setAttribute('data-phx-view', 'User.Form')
77
div.setAttribute('data-phx-session', 'abc123')
88
div.setAttribute('id', 'container')
99
div.setAttribute('class', 'user-implemented-class')
@@ -271,7 +271,7 @@ describe('View', function() {
271271
expect(view.parent).toBeUndefined()
272272
expect(view.el).toBe(el)
273273
expect(view.id).toEqual('container')
274-
expect(view.view).toEqual('')
274+
expect(view.view).toEqual('User.Form')
275275
expect(view.channel).toBeDefined()
276276
expect(view.loaderTimer).toBeDefined()
277277
})
@@ -290,6 +290,17 @@ describe('View', function() {
290290
expect(view.getSession()).toEqual('abc123')
291291
})
292292

293+
test('getStatic', async () => {
294+
let liveSocket = new LiveSocket('/live', Socket)
295+
let el = liveViewDOM()
296+
let view = new View(el, liveSocket)
297+
expect(view.getStatic()).toEqual(null)
298+
299+
el.setAttribute('data-phx-static', 'foo')
300+
view = new View(el, liveSocket)
301+
expect(view.getStatic()).toEqual('foo')
302+
})
303+
293304
test('showLoader and hideLoader', async () => {
294305
let liveSocket = new LiveSocket('/live', Socket)
295306
let el = document.querySelector('[data-phx-view]')
@@ -383,3 +394,68 @@ describe('View Hooks', function() {
383394
expect(upcaseWasDestroyed).toBe(true)
384395
})
385396
})
397+
398+
function liveViewComponent() {
399+
const div = document.createElement('div')
400+
div.setAttribute('data-phx-view', 'User.Form')
401+
div.setAttribute('data-phx-session', 'abc123')
402+
div.setAttribute('id', 'container')
403+
div.setAttribute('class', 'user-implemented-class')
404+
div.innerHTML = `
405+
<article class="form-wrapper" data-phx-component="0">
406+
<form>
407+
<label for="plus">Plus</label>
408+
<input id="plus" value="1" name="increment" phx-target=".form-wrapper" />
409+
<input type="checkbox" phx-click="toggle_me" phx-target=".form-wrapper" />
410+
<button phx-click="inc_temperature">Inc Temperature</button>
411+
</form>
412+
</article>
413+
`
414+
return div
415+
}
416+
417+
describe('View + Component', function() {
418+
beforeEach(() => {
419+
global.Phoenix = { Socket }
420+
global.document.body.innerHTML = liveViewComponent().outerHTML
421+
})
422+
423+
afterAll(() => {
424+
global.document.body.innerHTML = ''
425+
})
426+
427+
test('targetComponentID', async () => {
428+
let liveSocket = new LiveSocket('/live', Socket)
429+
let el = liveViewComponent()
430+
let view = new View(el, liveSocket)
431+
let form = el.querySelector('input[type="checkbox"]')
432+
let targetCtx = el.querySelector('.form-wrapper')
433+
expect(view.targetComponentID(el, targetCtx)).toBe(null)
434+
expect(view.targetComponentID(form, targetCtx)).toBe(0)
435+
})
436+
437+
test('pushEvent', function() {
438+
expect.assertions(4)
439+
440+
let liveSocket = new LiveSocket('/live', Socket)
441+
let el = liveViewComponent()
442+
let targetCtx = el.querySelector('.form-wrapper')
443+
let input = el.querySelector('input')
444+
445+
let view = new View(el, liveSocket)
446+
let channelStub = {
447+
push(evt, payload, timeout) {
448+
expect(payload.type).toBe('keyup')
449+
expect(payload.event).toBeDefined()
450+
expect(payload.value).toEqual({"value": "1"})
451+
expect(payload.cid).toEqual(0)
452+
return {
453+
receive() {}
454+
}
455+
}
456+
}
457+
view.channel = channelStub
458+
459+
view.pushEvent('keyup', input, targetCtx, "click", {})
460+
})
461+
});

lib/phoenix_live_view/socket.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ defmodule Phoenix.LiveView.Socket do
5555
socket "/live", Phoenix.LiveView.Socket,
5656
websocket: [connect_info: [session: @session_options]]
5757
58-
4) Define the CSRF meta tag inside the in <head> in your layout:
58+
4) Define the CSRF meta tag inside the `<head>` tag in your layout:
5959
6060
<%= csrf_meta_tag() %>
6161

0 commit comments

Comments
 (0)