1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { SharingURLsComponent } from './sharing-urls-component';
7 import { ThemeProvider } from "@mui/material";
8 import { CustomTheme } from 'common/custom-theme';
9 import { Provider } from "react-redux";
10 import { configureStore } from "store/store";
11 import { createBrowserHistory } from "history";
13 describe("<SharingURLsComponent />", () => {
15 const store = configureStore(createBrowserHistory());
19 collectionUuid: 'collection-uuid',
20 sharingURLsPrefix: 'sharing-urls-prefix',
24 apiToken: 'aaaaaaaaaa',
25 expiresAt: '2009-01-03T18:15:00Z',
29 apiToken: 'bbbbbbbbbb',
30 expiresAt: '2009-01-03T18:15:01Z',
34 onDeleteSharingToken: cy.stub().as('onDeleteSharingToken'),
37 <Provider store={store}>
38 <ThemeProvider theme={CustomTheme}>
39 <SharingURLsComponent {...props} />
44 it("renders a list of sharing URLs", () => {
45 // Check number of URLs
46 cy.get('a').should('have.length', 2);
48 cy.get('a').eq(0).should('contain', `Token aaaaaaaa... expiring at: ${new Date(props.sharingTokens[0].expiresAt).toLocaleString()}`);
49 cy.get('a').eq(0).should('have.attr', 'href', `${props.sharingURLsPrefix}/c=${props.collectionUuid}/t=${props.sharingTokens[0].apiToken}/_/`);
51 cy.get('a').eq(1).should('contain', `Token bbbbbbbb... expiring at: ${new Date(props.sharingTokens[1].expiresAt).toLocaleString()}`);
52 cy.get('a').eq(1).should('have.attr', 'href', `${props.sharingURLsPrefix}/c=${props.collectionUuid}/t=${props.sharingTokens[1].apiToken}/_/`);
55 it("renders a list URLs with collection UUIDs as subdomains", () => {
56 props.sharingURLsPrefix = '*.sharing-urls-prefix';
57 const sharingPrefix = '.sharing-urls-prefix';
59 <Provider store={store}>
60 <ThemeProvider theme={CustomTheme}>
61 <SharingURLsComponent {...props} />
65 cy.get('a').eq(0).should('have.attr', 'href', `${props.collectionUuid}${sharingPrefix}/t=${props.sharingTokens[0].apiToken}/_/`);
66 cy.get('a').eq(1).should('have.attr', 'href', `${props.collectionUuid}${sharingPrefix}/t=${props.sharingTokens[1].apiToken}/_/`);
69 it("renders a list of URLs with no expiration", () => {
70 props.sharingTokens[0].expiresAt = null;
71 props.sharingTokens[1].expiresAt = null;
73 <Provider store={store}>
74 <ThemeProvider theme={CustomTheme}>
75 <SharingURLsComponent {...props} />
78 cy.get('a').eq(0).should('contain', `Token aaaaaaaa... with no expiration date`);
79 cy.get('a').eq(1).should('contain', `Token bbbbbbbb... with no expiration date`);
82 it("calls delete token handler when delete button is clicked", () => {
83 cy.get('button').eq(0).click();
84 cy.get('@onDeleteSharingToken').should('be.calledWith', props.sharingTokens[0].uuid);