mirror of
https://github.com/streamwall/streamwall.git
synced 2026-01-24 22:22:50 -05:00
Makes control.js testable with various config. changes. Adds coverage for util.js, roles.js, starts on control.js. Updates the entrypoint; untested so far
This commit is contained in:
39
src/roles.test.js
Normal file
39
src/roles.test.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { roleCan } from './roles.js';
|
||||
|
||||
describe('roleCan', () => {
|
||||
it('should return true for admin role regardless of action', () => {
|
||||
expect(roleCan('admin', 'any-action')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true for operator role and valid action', () => {
|
||||
expect(roleCan('operator', 'set-listening-view')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for operator role and invalid action', () => {
|
||||
expect(roleCan('operator', 'invalid-action')).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for operator role and un-granted action', () => {
|
||||
expect(roleCan('operator', 'dev-tools')).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true for monitor role and valid action', () => {
|
||||
expect(roleCan('monitor', 'set-view-blurred')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for monitor role and invalid action', () => {
|
||||
expect(roleCan('monitor', 'invalid-action')).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for monitor role and un-granted action', () => {
|
||||
expect(roleCan('monitor', 'set-listening-view')).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for invalid role regardless of action', () => {
|
||||
expect(roleCan('invalid-role', 'any-action')).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for invalid role and valid action', () => {
|
||||
expect(roleCan('invalid-role', 'set-listening-view')).toBe(false);
|
||||
});
|
||||
});
|
||||
17
src/util.test.js
Normal file
17
src/util.test.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { ensureValidURL } from './util'
|
||||
|
||||
describe('ensureValidURL', () => {
|
||||
it('should not throw an error for valid http and https URLs', () => {
|
||||
expect(() => ensureValidURL('http://example.com')).not.toThrow()
|
||||
expect(() => ensureValidURL('https://example.com')).not.toThrow()
|
||||
})
|
||||
|
||||
it('should throw an error for non-http and non-https URLs', () => {
|
||||
expect(() => ensureValidURL('ftp://example.com')).toThrow()
|
||||
expect(() => ensureValidURL('file://example.com')).toThrow()
|
||||
})
|
||||
|
||||
it('should throw an error for invalid URLs', () => {
|
||||
expect(() => ensureValidURL('invalid')).toThrow()
|
||||
})
|
||||
})
|
||||
@@ -1491,13 +1491,14 @@ const TIN = styled.div`
|
||||
|
||||
function main() {
|
||||
const script = document.getElementById('main-script')
|
||||
const wsEndpoint = typeof script?.dataset?.wsEndpoint === 'string' ? script.dataset.wsEndpoint : 'defaultWsEndpoint';
|
||||
const role = typeof script?.dataset?.role === 'string' ? script.dataset.role : 'defaultRole';
|
||||
|
||||
render(
|
||||
<>
|
||||
<GlobalStyle />
|
||||
<App wsEndpoint={script.dataset.wsEndpoint} role={script.dataset.role} />
|
||||
<App wsEndpoint={wsEndpoint} role={role} />
|
||||
</>,
|
||||
document.body,
|
||||
)
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
50
src/web/control.test.js
Normal file
50
src/web/control.test.js
Normal file
@@ -0,0 +1,50 @@
|
||||
import { filterStreams, useYDoc, useStreamwallConnection } from './control.js'
|
||||
// import { renderHook, act } from '@testing-library/react-hooks'
|
||||
|
||||
describe("control test always passes", () => {
|
||||
it("always passes", () => {
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
// describe('filterStreams', () => {
|
||||
// it('should correctly filter live and other streams', () => {
|
||||
// const streams = [
|
||||
// { kind: 'video', status: 'Live' },
|
||||
// { kind: 'audio', status: 'Offline' },
|
||||
// { kind: 'video', status: 'Offline' },
|
||||
// ]
|
||||
// const [liveStreams, otherStreams] = filterStreams(streams)
|
||||
// expect(liveStreams).toHaveLength(1)
|
||||
// expect(otherStreams).toHaveLength(2)
|
||||
// })
|
||||
// })
|
||||
|
||||
// describe('useYDoc', () => {
|
||||
// it('should initialize with an empty Y.Doc', () => {
|
||||
// const { result } = renderHook(() => useYDoc(['test']))
|
||||
// expect(result.current[0]).toEqual({})
|
||||
// })
|
||||
|
||||
// it('should update docValue when doc is updated', () => {
|
||||
// const { result } = renderHook(() => useYDoc(['test']))
|
||||
// act(() => {
|
||||
// result.current[1].getMap('test').set('key', 'value')
|
||||
// })
|
||||
// expect(result.current[0]).toEqual({ test: { key: 'value' } })
|
||||
// })
|
||||
// })
|
||||
|
||||
// describe('useStreamwallConnection', () => {
|
||||
// it('should initialize with default values', () => {
|
||||
// const { result } = renderHook(() => useStreamwallConnection('ws://localhost:8080'))
|
||||
// expect(result.current.isConnected).toBe(false)
|
||||
// expect(result.current.config).toEqual({})
|
||||
// expect(result.current.streams).toEqual([])
|
||||
// expect(result.current.customStreams).toEqual([])
|
||||
// expect(result.current.views).toEqual([])
|
||||
// expect(result.current.stateIdxMap).toEqual(new Map())
|
||||
// expect(result.current.delayState).toBeUndefined()
|
||||
// expect(result.current.authState).toBeUndefined()
|
||||
// })
|
||||
// })
|
||||
3
src/web/entrypoint.js
Normal file
3
src/web/entrypoint.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import { main } from './control.js';
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user