diff options
Diffstat (limited to 'spec/frontend/authentication/webauthn/util_spec.js')
-rw-r--r-- | spec/frontend/authentication/webauthn/util_spec.js | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/spec/frontend/authentication/webauthn/util_spec.js b/spec/frontend/authentication/webauthn/util_spec.js index bc44b47d0ba..831d1636b8c 100644 --- a/spec/frontend/authentication/webauthn/util_spec.js +++ b/spec/frontend/authentication/webauthn/util_spec.js @@ -1,4 +1,9 @@ -import { base64ToBuffer, bufferToBase64, base64ToBase64Url } from '~/authentication/webauthn/util'; +import { + base64ToBuffer, + bufferToBase64, + base64ToBase64Url, + supported, +} from '~/authentication/webauthn/util'; const encodedString = 'SGVsbG8gd29ybGQh'; const stringBytes = [72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33]; @@ -31,4 +36,28 @@ describe('Webauthn utils', () => { expect(base64ToBase64Url(argument)).toBe(expectedResult); }); }); + + describe('supported', () => { + afterEach(() => { + global.navigator.credentials = undefined; + window.PublicKeyCredential = undefined; + }); + + it.each` + credentials | PublicKeyCredential | expected + ${undefined} | ${undefined} | ${false} + ${{}} | ${undefined} | ${false} + ${{ create: true }} | ${undefined} | ${false} + ${{ create: true, get: true }} | ${undefined} | ${false} + ${{ create: true, get: true }} | ${true} | ${true} + `( + 'returns $expected when credentials is $credentials and PublicKeyCredential is $PublicKeyCredential', + ({ credentials, PublicKeyCredential, expected }) => { + global.navigator.credentials = credentials; + window.PublicKeyCredential = PublicKeyCredential; + + expect(supported()).toBe(expected); + }, + ); + }); }); |