Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jest): 75% coverage for components/mixins/UserPermissions #2402

Merged
merged 2 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions components/mixins/UserPermissions/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`index.UserPermissions.created 0 1`] = `undefined`;

exports[`index.exportForTesting.formatDevices 0 1`] = `
Array [
Object {
"text": "videoinput: FaceTime HD Camera (Built-in) ",
"value": "id=csO9c0YpAf274OuCPUA53CNE0YHlIr2yXCi+SqfBZZ8=",
},
Object {
"text": "audioinput: default (Built-in Microphone) ",
"value": "id=RKxXByjnabbADGQNNZqLVLdmXlS0YkETYCIbg+XxnvM=",
},
Object {
"text": "audioinput: Built-in Microphone ",
"value": "id=r2/xw1xUPIyZunfV1lGrKOma5wTOvCkWfZ368XCndm0=",
},
]
`;
47 changes: 47 additions & 0 deletions components/mixins/UserPermissions/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,54 @@
import * as index from '~/components/mixins/UserPermissions/index'

describe('index.UserPermissions.created', () => {
test('0', () => {
const result: any = index.UserPermissions.created()
expect(result).toMatchSnapshot()
})
})
describe('index.UserPermissions.methods.getUserPermissions', () => {
test('0', async () => {
await index.UserPermissions.methods.getUserPermissions()
})
})
describe('index.UserPermissions.methods.requestUserPermissions', () => {
test('0', async () => {
const mockObj = { a: 'b' }
window.navigator = jest.fn()
window.navigator.mediaDevices = jest.fn()
window.navigator.mediaDevices.getUserMedia = jest
.fn()
.mockReturnValueOnce(mockObj)

const result = await index.UserPermissions.methods.requestUserPermissions({
audio: true,
peerIdentity: 'identity',
preferCurrentTab: true,
video: false,
})

expect(result).toMatchObject(mockObj)
})
})
describe('index.exportForTesting.formatDevices', () => {
test('0', async () => {
const devices = [
{
label: 'videoinput: FaceTime HD Camera (Built-in) ',
deviceId: 'id=csO9c0YpAf274OuCPUA53CNE0YHlIr2yXCi+SqfBZZ8=',
},
{
label: 'audioinput: default (Built-in Microphone) ',
deviceId: 'id=RKxXByjnabbADGQNNZqLVLdmXlS0YkETYCIbg+XxnvM=',
},
{
label: 'audioinput: Built-in Microphone ',
deviceId: 'id=r2/xw1xUPIyZunfV1lGrKOma5wTOvCkWfZ368XCndm0=',
},
]

const result = await index.exportForTesting.formatDevices(devices)

expect(result).toMatchSnapshot()
})
})
4 changes: 4 additions & 0 deletions components/mixins/UserPermissions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,7 @@ export const UserPermissions = {
}

export default UserPermissions

export const exportForTesting = {
formatDevices,
}