1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { TokenDialogComponent } from './token-dialog';
7 import { ThemeProvider } from "@mui/material";
8 import { CustomTheme } from 'common/custom-theme';
9 import { combineReducers, createStore } from "redux";
10 import { Provider } from "react-redux";
12 describe('<CurrentTokenDialog />', () => {
20 apiHost: 'example.com',
22 dispatch: cy.spy().as('dispatch'),
25 const initialAuthState = {
26 localCluster: "zzzzz",
27 remoteHostsConfig: {},
31 store = createStore(combineReducers({
32 auth: (state = initialAuthState, action) => state,
36 describe('Get API Token dialog', () => {
39 <Provider store={store}>
40 <ThemeProvider theme={CustomTheme}>
41 <TokenDialogComponent {...props} />
46 it('should include API host and token', () => {
47 cy.get('pre').contains('export ARVADOS_API_HOST=example.com');
48 cy.get('pre').contains('export ARVADOS_API_TOKEN=xxxtokenxxx');
51 it('should show the token expiration if present', () => {
52 expect(props.tokenExpiration).to.be.undefined;
53 cy.get('[data-cy=details-attribute-value]').contains('This token does not have an expiration date');
55 const someDate = '2140-01-01T00:00:00.000Z'
56 props.tokenExpiration = new Date(someDate);
58 <Provider store={store}>
59 <ThemeProvider theme={CustomTheme}>
60 <TokenDialogComponent {...props} />
63 cy.get('[data-cy=details-attribute-value]').contains(props.tokenExpiration.toLocaleString());
66 it('should show a create new token button when allowed', () => {
67 expect(!!props.canCreateNewTokens).to.equal(false);
68 cy.contains('GET NEW TOKEN').should('not.exist');
70 props.canCreateNewTokens = true;
72 <Provider store={store}>
73 <ThemeProvider theme={CustomTheme}>
74 <TokenDialogComponent {...props} />
77 cy.contains('GET NEW TOKEN').should('exist');
81 describe('Copy link to clipboard button', () => {
84 <Provider store={store}>
85 <ThemeProvider theme={CustomTheme}>
86 <TokenDialogComponent {...props} />
91 it('should copy API TOKEN to the clipboard', () => {
92 cy.get('button').contains('Copy').click();
93 cy.get('@dispatch').should('be.calledWith', {
97 message: 'Shell code block copied',
99 type: 'OPEN_SNACKBAR',