-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(editor): Fix issues with push connect reconnection (#13085)
- Loading branch information
Showing
19 changed files
with
905 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/editor-ui/src/components/PushConnectionTracker.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { createComponentRenderer } from '@/__tests__/render'; | ||
import PushConnectionTracker from '@/components/PushConnectionTracker.vue'; | ||
import { STORES } from '@/constants'; | ||
import { createTestingPinia } from '@pinia/testing'; | ||
import { setActivePinia } from 'pinia'; | ||
|
||
let isConnected = true; | ||
let isConnectionRequested = true; | ||
|
||
vi.mock('@/stores/pushConnection.store', () => { | ||
return { | ||
usePushConnectionStore: vi.fn(() => ({ | ||
isConnected, | ||
isConnectionRequested, | ||
})), | ||
}; | ||
}); | ||
|
||
describe('PushConnectionTracker', () => { | ||
const render = () => { | ||
const pinia = createTestingPinia({ | ||
stubActions: false, | ||
initialState: { | ||
[STORES.PUSH]: { | ||
isConnected, | ||
isConnectionRequested, | ||
}, | ||
}, | ||
}); | ||
setActivePinia(pinia); | ||
|
||
return createComponentRenderer(PushConnectionTracker)(); | ||
}; | ||
|
||
it('should not render error when connected and connection requested', () => { | ||
isConnected = true; | ||
isConnectionRequested = true; | ||
const { container } = render(); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render error when disconnected and connection requested', () => { | ||
isConnected = false; | ||
isConnectionRequested = true; | ||
const { container } = render(); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('should not render error when connected and connection not requested', () => { | ||
isConnected = true; | ||
isConnectionRequested = false; | ||
const { container } = render(); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
17 changes: 12 additions & 5 deletions
17
packages/editor-ui/src/components/PushConnectionTracker.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/editor-ui/src/components/__snapshots__/PushConnectionTracker.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`PushConnectionTracker > should not render error when connected and connection not requested 1`] = ` | ||
<div> | ||
<span> | ||
</span> | ||
</div> | ||
`; | ||
|
||
exports[`PushConnectionTracker > should not render error when connected and connection requested 1`] = ` | ||
<div> | ||
<span> | ||
</span> | ||
</div> | ||
`; | ||
|
||
exports[`PushConnectionTracker > should render error when disconnected and connection requested 1`] = ` | ||
<div> | ||
<span> | ||
<div | ||
class="push-connection-lost primary-color" | ||
> | ||
<span | ||
class="el-tooltip__trigger" | ||
> | ||
<svg | ||
aria-hidden="true" | ||
class="svg-inline--fa fa-exclamation-triangle fa-w-18" | ||
data-icon="exclamation-triangle" | ||
data-prefix="fas" | ||
focusable="false" | ||
role="img" | ||
viewBox="0 0 576 512" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
class="" | ||
d="M569.517 440.013C587.975 472.007 564.806 512 527.94 512H48.054c-36.937 0-59.999-40.055-41.577-71.987L246.423 23.985c18.467-32.009 64.72-31.951 83.154 0l239.94 416.028zM288 354c-25.405 0-46 20.595-46 46s20.595 46 46 46 46-20.595 46-46-20.595-46-46-46zm-43.673-165.346l7.418 136c.347 6.364 5.609 11.346 11.982 11.346h48.546c6.373 0 11.635-4.982 11.982-11.346l7.418-136c.375-6.874-5.098-12.654-11.982-12.654h-63.383c-6.884 0-12.356 5.78-11.981 12.654z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
Connection lost | ||
</span> | ||
<!--teleport start--> | ||
<!--teleport end--> | ||
</div> | ||
</span> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/editor-ui/src/push-connection/__tests__/mockEventSource.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** Mocked EventSource class to help testing */ | ||
export class MockEventSource extends EventTarget { | ||
constructor(public url: string) { | ||
super(); | ||
} | ||
|
||
simulateConnectionOpen() { | ||
this.dispatchEvent(new Event('open')); | ||
} | ||
|
||
simulateConnectionClose() { | ||
this.dispatchEvent(new Event('close')); | ||
} | ||
|
||
simulateMessageEvent(data: string) { | ||
this.dispatchEvent(new MessageEvent('message', { data })); | ||
} | ||
|
||
close = vi.fn(); | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/editor-ui/src/push-connection/__tests__/mockWebSocketClient.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { WebSocketState } from '@/push-connection/useWebSocketClient'; | ||
|
||
/** Mocked WebSocket class to help testing */ | ||
export class MockWebSocket extends EventTarget { | ||
readyState: number = WebSocketState.CONNECTING; | ||
|
||
constructor(public url: string) { | ||
super(); | ||
} | ||
|
||
simulateConnectionOpen() { | ||
this.dispatchEvent(new Event('open')); | ||
this.readyState = WebSocketState.OPEN; | ||
} | ||
|
||
simulateConnectionClose(code: number) { | ||
this.dispatchEvent(new CloseEvent('close', { code })); | ||
this.readyState = WebSocketState.CLOSED; | ||
} | ||
|
||
simulateMessageEvent(data: string) { | ||
this.dispatchEvent(new MessageEvent('message', { data })); | ||
} | ||
|
||
dispatchErrorEvent() { | ||
this.dispatchEvent(new Event('error')); | ||
} | ||
|
||
send = vi.fn(); | ||
|
||
close = vi.fn(); | ||
} |
Oops, something went wrong.