Skip to content

Commit

Permalink
fix refresh role and group history displays no history (#2739)
Browse files Browse the repository at this point in the history
Signed-off-by: aporss <[email protected]>
  • Loading branch information
ArtjomsPorss committed Sep 29, 2024
1 parent c97c1b5 commit dd281b3
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ exports[`GroupRow should render 1`] = `
class="emotion-12"
data-testid="icon"
height="1.25em"
id=""
id="group-history-icon-testui"
viewBox="0 0 1024 1024"
width="1.25em"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ exports[`GroupTable should render 1`] = `
class="emotion-34"
data-testid="icon"
height="1.25em"
id=""
id="group-history-icon-a"
viewBox="0 0 1024 1024"
width="1.25em"
>
Expand Down Expand Up @@ -532,7 +532,7 @@ exports[`GroupTable should render 1`] = `
class="emotion-34"
data-testid="icon"
height="1.25em"
id=""
id="group-history-icon-b"
viewBox="0 0 1024 1024"
width="1.25em"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ exports[`RoleRow should render 1`] = `
class="emotion-12"
data-testid="icon"
height="1.25em"
id=""
id="ztssia_cert_rotate-history-role-button"
viewBox="0 0 1024 1024"
width="1.25em"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ exports[`RoleTable should render 1`] = `
class="emotion-36"
data-testid="icon"
height="1.25em"
id=""
id="a-history-role-button"
viewBox="0 0 1024 1024"
width="1.25em"
>
Expand Down Expand Up @@ -482,7 +482,7 @@ exports[`RoleTable should render 1`] = `
class="emotion-36"
data-testid="icon"
height="1.25em"
id=""
id="b-history-role-button"
viewBox="0 0 1024 1024"
width="1.25em"
>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/__tests__/redux/reducers/groups.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('Groups Reducer', () => {
});
it('should load group into the store', () => {
const initialState = {
groups: {},
// not creating groups field here - expecting it to be created by the tested function
domainName: domainName,
expiry: expiry,
};
Expand Down
1 change: 1 addition & 0 deletions ui/src/__tests__/redux/reducers/roles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ describe('Roles Reducer', () => {
};
const expectedState = AppUtils.deepClone(initialState);
expectedState.roles['singlerole'] = AppUtils.deepClone(singleStoreRole);
delete initialState.roles; // if initial state doesn't have roles field, it should be created
const newState = roles(initialState, action);
expect(_.isEqual(newState, expectedState)).toBeTruthy();
});
Expand Down
90 changes: 90 additions & 0 deletions ui/src/__tests__/spec/tests/groups.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright The Athenz Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


describe('group screen tests', () => {
it('group history should be visible when navigating to it and after page refresh', async () => {
// open browser
await browser.newUser();
await browser.url(`/`);
// select domain
let domain = 'athenz.dev.functional-test';
let testDomain = await $(`a*=${domain}`);
await testDomain.click();

// ADD test group
// navigate to groups page
let groups = await $('div*=Groups');
await groups.click();
// open Add Group screen
let addGroupButton = await $('button*=Add Group');
await addGroupButton.click();
// add group info
let inputGroupName = await $('#group-name-input');
let groupName = 'history-test-group';
await inputGroupName.addValue(groupName);
// add user
let addMemberInput = await $('[name="member-name"]'); //TODO rename the field
await addMemberInput.addValue('unix.yahoo');
let userOption = await $('div*=unix.yahoo');
await userOption.click();
// submit role
let buttonSubmit = await $('button*=Submit');
await buttonSubmit.click();

// Verify history entry of added group member is present
// open history
let historySvg = await $('.//*[local-name()="svg" and @id="group-history-icon-history-test-group"]');
await historySvg.click();
// find row with 'ADD'
let addTd = await $('td=ADD');
await expect(addTd).toHaveText('ADD');
// find row with 'unix.yahoo' present
let spanUnix = await $('span*=unix.yahoo');
await expect(spanUnix).toHaveText('unix.yahoo');

// Verify history is displayed after page refresh
// refresh page
await browser.refresh();
// find row with 'ADD'
addTd = await $('td=ADD');
await expect(addTd).toHaveText('ADD');
// find row with 'unix.yahoo' present
spanUnix = await $('span*=unix.yahoo');
await expect(spanUnix).toHaveText('unix.yahoo');
});

// after - runs after the last test in order of declaration
after(async() => {
// open browser
await browser.newUser();
await browser.url(`/`);
// select domain
let domain = 'athenz.dev.functional-test';
let testDomain = await $(`a*=${domain}`);
await testDomain.click();

// navigate to groups page
let groups = await $('div*=Groups');
await groups.click();

// delete the group used in the test
let buttonDeleteGroup = await $('.//*[local-name()="svg" and @id="delete-group-icon-history-test-group"]');
await buttonDeleteGroup.click();
let modalDeleteButton = await $('button*=Delete');
await modalDeleteButton.click();
});
})
83 changes: 83 additions & 0 deletions ui/src/__tests__/spec/tests/roles.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright The Athenz Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


describe('role screen tests', () => {
it('role history should be visible when navigating to it and after page refresh', async () => {
// open browser
await browser.newUser();
await browser.url(`/`);
// select domain
let domain = 'athenz.dev.functional-test';
let testDomain = await $(`a*=${domain}`);
await testDomain.click();

// ADD test role
// open Add Role screen
let addiRoleButton = await $('button*=Add Role');
await addiRoleButton.click();
// add group info
let inputRoleName = await $('#role-name-input');
let roleName = 'history-test-role';
await inputRoleName.addValue(roleName);
// add user
let addMemberInput = await $('[name="member-name"]');
await addMemberInput.addValue('unix.yahoo');
let userOption = await $('div*=unix.yahoo');
await userOption.click();
// submit role
let buttonSubmit = await $('button*=Submit');
await buttonSubmit.click();

// Verify history entry of added role member is present
// open history
let historySvg = await $('.//*[local-name()="svg" and @id="history-test-role-history-role-button"]');
await historySvg.click();
// find row with 'ADD'
let addTd = await $('td=ADD');
await expect(addTd).toHaveText('ADD');
// find row with 'unix.yahoo' present
let spanUnix = await $('span*=unix.yahoo');
await expect(spanUnix).toHaveText('unix.yahoo');

// Verify history is displayed after page refresh
// refresh page
await browser.refresh();
// find row with 'ADD'
addTd = await $('td=ADD');
await expect(addTd).toHaveText('ADD');
// find row with 'unix.yahoo' present
spanUnix = await $('span*=unix.yahoo');
await expect(spanUnix).toHaveText('unix.yahoo');
});

// after - runs after the last test in order of declaration
after(async() => {
// open browser
await browser.newUser();
await browser.url(`/`);
// select domain
let domain = 'athenz.dev.functional-test';
let testDomain = await $(`a*=${domain}`);
await testDomain.click();

// delete the role used in the test
let buttonDeleteRole = await $('.//*[local-name()="svg" and @id="history-test-role-delete-role-button"]');
await buttonDeleteRole.click();
let modalDeleteButton = await $('button*=Delete');
await modalDeleteButton.click();
});
})
1 change: 1 addition & 0 deletions ui/src/components/group/GroupRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ class GroupRow extends React.Component {
trigger={
<span>
<Icon
id={`group-history-icon-${this.state.name}`}
icon={'time-history'}
onClick={clickHistory}
color={colors.icons}
Expand Down
1 change: 1 addition & 0 deletions ui/src/components/role/RoleRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ class RoleRow extends React.Component {
trigger={
<span>
<Icon
id={`${this.state.name}-history-role-button`}
icon={'time-history'}
onClick={clickHistory}
color={colors.icons}
Expand Down
9 changes: 5 additions & 4 deletions ui/src/redux/reducers/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ export const groups = (state = {}, action) => {
return newState;
}
case LOAD_GROUP: {
const { groupData, groupName } = payload;
let newState = produce(state, (draft) => {
draft.groups[groupName] = groupData;
return produce(state, (draft) => {
if (!!!draft.groups) {
draft.groups = {};
}
draft.groups[payload.groupName] = payload.groupData;
});
return newState;
}
case UPDATE_SETTING_TO_STORE: {
const { collectionName, collectionSettings, category } = payload;
Expand Down
9 changes: 5 additions & 4 deletions ui/src/redux/reducers/roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ export const roles = (state = {}, action) => {
return newState;
}
case LOAD_ROLE: {
const { roleData, roleName } = payload;
let newState = produce(state, (draft) => {
draft.roles[roleName] = roleData;
return produce(state, (draft) => {
if (!!!draft.roles) {
draft.roles = {};
}
draft.roles[payload.roleName] = payload.roleData;
});
return newState;
}
case LOAD_ROLES_TO_REVIEW: {
const { rolesToReview } = payload;
Expand Down

0 comments on commit dd281b3

Please sign in to comment.