Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tags abilities e2e tests #2747

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion assets/js/common/Tags/Tags.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ const tagValidationDefaultMessage = (
</>
);

function ExistingTag({ onClick, disabled }) {
function ExistingTag({ onClick, disabled, tag }) {
return (
<span
data-test-id={`tag-${tag}`}
aria-hidden="true"
className={classNames('cursor-pointer group-hover:opacity-60', {
'opacity-50 pointer-events-none': disabled,
Expand Down Expand Up @@ -102,6 +103,7 @@ function Tags({
tooltipWrap
>
<ExistingTag
tag={tag}
onClick={() => {
const newTagsList = renderedTags.reduce(
(acc, current) => (current === tag ? acc : [...acc, current]),
Expand Down
41 changes: 41 additions & 0 deletions test/e2e/cypress/e2e/clusters_overview.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
unhealthyClusterScenario,
} from '../fixtures/clusters-overview/available_clusters';

import { createUserRequestFactory } from '@lib/test-utils/factories';
CDimonaco marked this conversation as resolved.
Show resolved Hide resolved

const clusterIdByName = (clusterName) =>
availableClusters.find(({ name }) => name === clusterName).id;

Expand Down Expand Up @@ -181,3 +183,42 @@ context('Clusters Overview', () => {
});
});
});

describe('Forbidden action', () => {
beforeEach(() => {
cy.deleteAllUsers();
cy.logout();
const user = createUserRequestFactory.build({
password,
password_confirmation: password,
});
cy.wrap(user).as('user');
});

const password = 'password';
it('it should prevent a tag update when the user abilities are not compliant', () => {
CDimonaco marked this conversation as resolved.
Show resolved Hide resolved
CDimonaco marked this conversation as resolved.
Show resolved Hide resolved
cy.get('@user').then((user) => {
cy.createUserWithAbilities(user, []);
cy.login(user.username, password);
});

cy.visit('/clusters');

cy.contains('span', 'Add Tag').should('have.class', 'opacity-50');
cy.get('[data-test-id="tag-env1"]').should('have.class', 'opacity-50');
});

it('it should allow a tag update when the user abilities are compliant', () => {
cy.get('@user').then((user) => {
cy.createUserWithAbilities(user, [
{ name: 'all', resource: 'cluster_tags' },
]);
cy.login(user.username, password);
});

cy.visit('/clusters');

cy.contains('span', 'Add Tag').should('not.have.class', 'opacity-50');
cy.get('[data-test-id="tag-env1"]').should('not.have.class', 'opacity-50');
});
});
34 changes: 34 additions & 0 deletions test/e2e/cypress/e2e/databases_overview.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,40 @@ context('Databases Overview', () => {
cy.wrap(user).as('user');
});

describe('Tag creation', () => {
before(() => {
cy.addTagByColumnValue('HDQ', 'env1');
});
it('it should prevent a tag update when the user abilities are not compliant', () => {
cy.get('@user').then((user) => {
cy.createUserWithAbilities(user, []);
cy.login(user.username, password);
});

cy.visit('/databases');

cy.contains('span', 'Add Tag').should('have.class', 'opacity-50');
cy.get('[data-test-id="tag-env1"]').should('have.class', 'opacity-50');
});

it('it should allow a tag update when the user abilities are compliant', () => {
cy.get('@user').then((user) => {
cy.createUserWithAbilities(user, [
{ name: 'all', resource: 'database_tags' },
]);
cy.login(user.username, password);
});

cy.visit('/databases');

cy.contains('span', 'Add Tag').should('not.have.class', 'opacity-50');
cy.get('[data-test-id="tag-env1"]').should(
'not.have.class',
'opacity-50'
);
});
});

describe('Database instance clean up', () => {
before(() => {
cy.loadScenario('sap-systems-overview-HDD-10-present');
Expand Down
31 changes: 31 additions & 0 deletions test/e2e/cypress/e2e/hosts_overview.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,37 @@ context('Hosts Overview', () => {
cy.wrap(user).as('user');
});

describe('Tag creation', () => {
it('it should prevent a tag update when the user abilities are not compliant', () => {
cy.get('@user').then((user) => {
cy.createUserWithAbilities(user, []);
cy.login(user.username, password);
});

cy.visit('/hosts');

cy.contains('span', 'Add Tag').should('have.class', 'opacity-50');
cy.get('[data-test-id="tag-tag1"]').should('have.class', 'opacity-50');
});

it('it should allow a tag update when the user abilities are compliant', () => {
cy.get('@user').then((user) => {
cy.createUserWithAbilities(user, [
{ name: 'all', resource: 'host_tags' },
]);
cy.login(user.username, password);
});

cy.visit('/hosts');

cy.contains('span', 'Add Tag').should('not.have.class', 'opacity-50');
cy.get('[data-test-id="tag-tag1"]').should(
'not.have.class',
'opacity-50'
);
});
});

describe('Clean up', () => {
it('should forbid host clean up', () => {
cy.get('@user').then((user) => {
Expand Down
31 changes: 31 additions & 0 deletions test/e2e/cypress/e2e/sap_systems_overview.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,37 @@ context('SAP Systems Overview', () => {
cy.wrap(user).as('user');
});

describe('Tag creation', () => {
it('it should prevent a tag update when the user abilities are not compliant', () => {
cy.get('@user').then((user) => {
cy.createUserWithAbilities(user, []);
cy.login(user.username, password);
});

cy.visit('/sap_systems');

cy.contains('span', 'Add Tag').should('have.class', 'opacity-50');
cy.get('[data-test-id="tag-env3"]').should('have.class', 'opacity-50');
});

it('it should allow a tag update when the user abilities are compliant', () => {
cy.get('@user').then((user) => {
cy.createUserWithAbilities(user, [
{ name: 'all', resource: 'sap_system_tags' },
]);
cy.login(user.username, password);
});

cy.visit('/sap_systems');

cy.contains('span', 'Add Tag').should('not.have.class', 'opacity-50');
cy.get('[data-test-id="tag-env3"]').should(
'not.have.class',
'opacity-50'
);
});
});

describe('Application instance clean up', () => {
before(() => {
cy.loadScenario('sap-systems-overview-NWD-00-absent');
Expand Down
Loading