From: Lucas Di Pentima Date: Tue, 23 Feb 2021 20:52:58 +0000 (-0300) Subject: 16848: Adds unit tests. X-Git-Tag: 2.1.2.1~10^2~8 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/a51a9c10678118004ca3c4fb0af38c5c85d050eb 16848: Adds unit tests. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- diff --git a/src/views-components/token-dialog/token-dialog.test.tsx b/src/views-components/token-dialog/token-dialog.test.tsx index e8df29b8..519d9354 100644 --- a/src/views-components/token-dialog/token-dialog.test.tsx +++ b/src/views-components/token-dialog/token-dialog.test.tsx @@ -20,15 +20,44 @@ describe('', () => { beforeEach(() => { props = { classes: {}, - data: { - currentToken: '123123123123', - }, + token: 'xxxtokenxxx', + apiHost: 'example.com', open: true, dispatch: jest.fn(), }; }); - describe('copy to clipboard', () => { + describe('Get API Token dialog', () => { + beforeEach(() => { + wrapper = mount(); + }); + + it('should include API host and token', () => { + expect(wrapper.html()).toContain('export ARVADOS_API_HOST=example.com'); + expect(wrapper.html()).toContain('export ARVADOS_API_TOKEN=xxxtokenxxx'); + }); + + it('should show the token expiration if present', () => { + expect(props.tokenExpiration).toBeUndefined(); + expect(wrapper.html()).not.toContain('Expires at:'); + + const someDate = '2140-01-01T00:00:00.000Z' + props.tokenExpiration = new Date(someDate); + wrapper = mount(); + expect(wrapper.html()).toContain('Expires at:'); + }); + + it('should show a create new token button when allowed', () => { + expect(props.canCreateNewTokens).toBeFalsy(); + expect(wrapper.html()).not.toContain('GET NEW TOKEN'); + + props.canCreateNewTokens = true; + wrapper = mount(); + expect(wrapper.html()).toContain('GET NEW TOKEN'); + }); + }); + + describe('copy to clipboard button', () => { beforeEach(() => { wrapper = mount(); });