Skip to content

Commit 3becb79

Browse files
committed
test: add unit tests for auth domain functionality
1 parent 6da29a9 commit 3becb79

File tree

1 file changed

+69
-13
lines changed

1 file changed

+69
-13
lines changed

src/components/snapshot/SnapshotAccess.test.tsx

Lines changed: 69 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ThemeProvider } from '@mui/material/styles';
44
import { Provider } from 'react-redux';
55
import React from 'react';
66
import createMockStore from 'redux-mock-store';
7+
import { ManagedGroupMembershipEntry } from 'src/models/group';
78
import history from '../../modules/hist';
89
import globalTheme from '../../modules/theme';
910
import SnapshotAccess from './SnapshotAccess';
@@ -37,21 +38,34 @@ const initialState = {
3738
},
3839
};
3940

41+
const mountSnapshotAccess = (userGroups: Array<ManagedGroupMembershipEntry>) => {
42+
const state = {
43+
...initialState,
44+
user: {
45+
userGroups,
46+
},
47+
};
48+
49+
const mockStore = createMockStore([]);
50+
const store = mockStore(state);
51+
52+
cy.intercept('GET', 'https://sam.dsde-dev.broadinstitute.org/api/groups/v1').as('getUserGroups');
53+
54+
mount(
55+
<Router history={history}>
56+
<Provider store={store}>
57+
<ThemeProvider theme={globalTheme}>
58+
<SnapshotAccess />
59+
</ThemeProvider>
60+
</Provider>
61+
</Router>,
62+
);
63+
};
64+
4065
describe('Snapshot access info', () => {
41-
beforeEach(() => {
42-
const mockStore = createMockStore([]);
43-
const store = mockStore(initialState);
44-
mount(
45-
<Router history={history}>
46-
<Provider store={store}>
47-
<ThemeProvider theme={globalTheme}>
48-
<SnapshotAccess />
49-
</ThemeProvider>
50-
</Provider>
51-
</Router>,
52-
);
53-
});
5466
it('Displays snapshot policies and emails', () => {
67+
mountSnapshotAccess([]);
68+
5569
cy.get('[data-cy="snapshot-stewards"]')
5670
.should('contain.text', 'Stewards')
5771
.within(() => {
@@ -81,4 +95,46 @@ describe('Snapshot access info', () => {
8195
});
8296
});
8397
});
98+
99+
it('Displays authorization domain section', () => {
100+
mountSnapshotAccess([]);
101+
102+
cy.get('label[for="authorization-domain"]')
103+
.should('contain.text', 'Authorization Domain')
104+
.should('contain.text', '(optional)');
105+
});
106+
107+
it('Shows authorization domain dropdown with options when user groups exist', () => {
108+
const userGroups = [
109+
{ groupEmail: 'email1', groupName: 'group1', role: 'READER' },
110+
{ groupEmail: 'email2', groupName: 'group2', role: 'READER' },
111+
];
112+
mountSnapshotAccess(userGroups);
113+
114+
cy.get('#authorization-domain-select')
115+
.should('exist')
116+
.should('not.be.disabled')
117+
.should('have.value', '');
118+
119+
cy.get('#authorization-domain-select').parent().click();
120+
cy.get('[data-cy^=menuItem]').should('have.length', userGroups.length);
121+
});
122+
123+
it('Select an authorization domain when user groups exist', () => {
124+
const userGroups = [
125+
{ groupEmail: 'email1', groupName: 'group1', role: 'READER' },
126+
{ groupEmail: 'email2', groupName: 'group2', role: 'READER' },
127+
];
128+
mountSnapshotAccess(userGroups);
129+
130+
cy.get('#authorization-domain-select').parent().click();
131+
cy.get('[data-cy=menuItem-group2]').click();
132+
cy.get('#authorization-domain-select').should('have.value', 'group2');
133+
});
134+
135+
it('Disables authorization domain dropdown when insufficient user groups', () => {
136+
const userGroups = [{ groupEmail: 'default', groupName: 'default', role: 'READER' }];
137+
mountSnapshotAccess(userGroups);
138+
cy.get('#authorization-domain-select').should('be.disabled');
139+
});
84140
});

0 commit comments

Comments
 (0)