/**
* Cypress Component Tests for edc-management (Shell Component)
*
* Tests the shell component that integrates feature components.
* Detailed feature tests are in edc-assets-management.cy.ts and edc-policies-management.cy.ts
*/
import '../../src/components/edc-management.ts';
import { html } from 'lit';
import type { EdcManagement } from '../../src/components/edc-management.ts';
describe('edc-management (Shell Component - Integration Tests)', () => {
describe('Component Initialization', () => {
it('should mount the component successfully', () => {
cy.mount(html``);
cy.get('edc-management').should('exist');
});
it('should initialize with mock store when no API endpoint provided', () => {
cy.mount(html``);
cy.get('edc-management')
.shadow()
.find('.sidebar')
.should('exist');
});
it('should display connection info with mock status', () => {
cy.mount(html``);
cy.get('edc-management')
.shadow()
.find('.status-text')
.should('contain.text', 'Mock');
});
it('should initialize with real store when API endpoint provided', () => {
cy.mount(html`
`);
cy.get('edc-management')
.shadow()
.find('.status-text')
.should('contain.text', 'Connected');
});
});
describe('Navigation Tabs', () => {
beforeEach(() => {
cy.mount(html``);
});
it('should display all navigation tabs', () => {
cy.get('edc-management')
.shadow()
.find('.sidebar nav')
.should('exist');
cy.get('edc-management')
.shadow()
.find('.sidebar nav button')
.should('have.length.at.least', 2); // Assets, Policies, (Contracts coming)
});
it('should have Assets tab selected by default', () => {
cy.get('edc-management')
.shadow()
.find('.sidebar nav button.active')
.should('contain', 'Assets');
});
it('should switch to Policies tab when clicked', () => {
cy.get('edc-management')
.shadow()
.find('.sidebar-nav .nav-item')
.contains('Policies')
.click();
cy.get('edc-management')
.shadow()
.find('.sidebar-nav .nav-item.active .nav-label')
.should('contain.text', 'Policies');
cy.get('edc-management')
.shadow()
.find('.content-header h1')
.should('contain.text', 'Policies');
});
});
describe('Feature Component Integration', () => {
it('should load edc-assets-management component in Assets tab', () => {
cy.mount(html``);
// Assets tab is active by default
cy.get('edc-management')
.shadow()
.find('edc-assets-management')
.should('exist');
});
it('should load edc-policies-management component in Policies tab', () => {
cy.mount(html``);
// Switch to Policies tab
cy.get('edc-management')
.shadow()
.find('.sidebar-nav .nav-item')
.contains('Policies')
.click();
cy.get('edc-management')
.shadow()
.find('edc-policies-management')
.should('exist');
});
it('should pass store to feature components', () => {
cy.mount(html``);
// Verify assets component receives data (indicating store is working)
cy.get('edc-management')
.shadow()
.find('edc-assets-management')
.shadow()
.find('.asset-card', { timeout: 2000 })
.should('have.length.at.least', 1);
});
it('should display contracts placeholder in Contracts tab', () => {
cy.mount(html``);
// Switch to Contracts tab
cy.get('edc-management')
.shadow()
.find('.sidebar-nav .nav-item')
.contains('Contract Definitions')
.click();
cy.get('edc-management')
.shadow()
.find('edc-contracts-management')
.should('exist');
});
});
describe('Assets Management (Mock Mode)', () => {
beforeEach(() => {
cy.mount(html``);
});
it('should display mock assets on load', () => {
// Wait for mock data to load
cy.get('edc-management')
.shadow()
.find('.asset-card', { timeout: 2000 })
.should('have.length.at.least', 1);
});
it('should display asset details', () => {
cy.get('edc-management')
.shadow()
.find('.asset-card')
.first()
.within(() => {
cy.get('.asset-id').should('exist');
cy.get('.asset-title').should('exist');
cy.get('.asset-description').should('exist');
});
});
it('should open create asset form when Create Asset button clicked', () => {
cy.get('edc-management')
.shadow()
.find('button')
.contains('Create Asset')
.click();
cy.get('edc-management')
.shadow()
.find('.modal-overlay')
.should('exist');
cy.get('edc-management')
.shadow()
.find('.modal-header h3')
.should('contain.text', 'Create New Asset');
});
it('should create a new asset', () => {
// Open create form
cy.get('edc-management')
.shadow()
.find('button')
.contains('Create Asset')
.click();
// Wait for modal to appear
cy.get('edc-management')
.shadow()
.find('.modal-overlay')
.should('exist');
// Fill in form
cy.get('edc-management')
.shadow()
.find('input[name="assetId"]')
.type('test-asset-123', { force: true });
cy.get('edc-management')
.shadow()
.find('input[name="title"]')
.type('Test Asset', { force: true });
cy.get('edc-management')
.shadow()
.find('textarea[name="description"]')
.type('A test asset created by Cypress', { force: true });
cy.get('edc-management')
.shadow()
.find('input[name="dataAddressType"]')
.type('HttpData', { force: true });
cy.get('edc-management')
.shadow()
.find('input[name="baseUrl"]')
.type('https://example.com/data', { force: true });
// Submit form
cy.get('edc-management')
.shadow()
.find('button[type="submit"]')
.click({ force: true });
// Wait a moment for the operation to complete
cy.wait(600);
// Verify modal closed
cy.get('edc-management')
.shadow()
.find('.modal-overlay')
.should('not.exist');
// Verify new asset appears in list
cy.get('edc-management')
.shadow()
.find('.asset-card')
.contains('test-asset-123')
.should('exist');
});
it('should search assets', () => {
cy.get('edc-management')
.shadow()
.find('input[placeholder*="Search"]')
.type('Demo Asset 1');
cy.get('edc-management')
.shadow()
.find('.asset-card')
.should('have.length', 1)
.and('contain', 'Demo Asset 1');
});
it('should delete an asset', () => {
// Get the first asset ID
cy.get('edc-management')
.shadow()
.find('.asset-card .asset-id')
.first()
.invoke('text')
.then((assetId) => {
// Click delete button - need to stub window.confirm
cy.window().then((win) => {
cy.stub(win, 'confirm').returns(true);
});
cy.get('edc-management')
.shadow()
.find('.asset-card')
.first()
.find('button')
.contains('Delete')
.click({ force: true });
// Wait for deletion to complete
cy.wait(600);
// Verify asset removed from list
cy.get('edc-management')
.shadow()
.find('.asset-card')
.contains(assetId.trim())
.should('not.exist');
});
});
});
describe('Policies Management (Mock Mode)', () => {
beforeEach(() => {
cy.mount(html``);
// Switch to Policies tab
cy.get('edc-management')
.shadow()
.find('.sidebar nav button')
.contains('Policies')
.click();
});
it('should display mock policies on load', () => {
cy.get('edc-management')
.shadow()
.find('.policy-card', { timeout: 2000 })
.should('have.length.at.least', 1);
});
it('should display policy details', () => {
cy.get('edc-management')
.shadow()
.find('.policy-card')
.first()
.within(() => {
cy.get('.policy-id').should('exist');
cy.get('.policy-type').should('exist');
});
});
it('should open create policy form', () => {
cy.get('edc-management')
.shadow()
.find('button')
.contains('Create Policy')
.click();
cy.get('edc-management')
.shadow()
.find('.modal-overlay')
.should('exist');
cy.get('edc-management')
.shadow()
.find('.modal-header h3')
.should('contain.text', 'Create New ODRL Policy');
});
it('should search policies', () => {
cy.get('edc-management')
.shadow()
.find('input[placeholder*="Search"]')
.type('allow-all');
cy.get('edc-management')
.shadow()
.find('.policy-card')
.should('have.length', 1)
.and('contain', 'allow-all');
});
});
describe('Event Handling', () => {
it('should handle asset creation without errors', () => {
cy.mount(html``);
// Open create form
cy.get('edc-management')
.shadow()
.find('button')
.contains('Create Asset')
.click();
// Fill minimal data
cy.get('edc-management')
.shadow()
.find('input[name="assetId"]')
.type('event-test-asset', { force: true });
cy.get('edc-management')
.shadow()
.find('button[type="submit"]')
.click({ force: true });
// Wait for operation to complete
cy.wait(600);
// Verify asset appears in list (no errors)
cy.get('edc-management')
.shadow()
.find('.asset-card')
.contains('event-test-asset')
.should('exist');
});
it('should handle policy creation without errors', () => {
cy.mount(html``);
// Switch to Policies tab
cy.get('edc-management')
.shadow()
.find('.sidebar-nav .nav-item')
.contains('Policies')
.click();
// Wait for policies to load
cy.wait(600);
// Create policy
cy.get('edc-management')
.shadow()
.find('button')
.contains('Create Policy')
.click();
cy.get('edc-management')
.shadow()
.find('input[name="policyId"]')
.type('event-test-policy', { force: true });
cy.get('edc-management')
.shadow()
.find('button[type="submit"]')
.click({ force: true });
// Wait for operation to complete
cy.wait(600);
// Verify policy appears in list (no errors)
cy.get('edc-management')
.shadow()
.find('.policy-card')
.contains('event-test-policy')
.should('exist');
});
});
describe('Error Handling', () => {
it('should prevent submission without required asset ID', () => {
cy.mount(html``);
// Open create form
cy.get('edc-management')
.shadow()
.find('button')
.contains('Create Asset')
.click();
// Wait for modal to appear
cy.get('edc-management')
.shadow()
.find('.modal-overlay')
.should('exist');
// Check that assetId field exists and is required
cy.get('edc-management')
.shadow()
.find('input[name="assetId"]')
.should('have.attr', 'required');
// Modal should still be present
cy.get('edc-management')
.shadow()
.find('.modal-overlay')
.should('exist');
});
});
describe('Accessibility', () => {
beforeEach(() => {
cy.mount(html``);
});
it('should have proper ARIA labels on navigation buttons', () => {
cy.get('edc-management')
.shadow()
.find('.sidebar nav button')
.each(($btn) => {
cy.wrap($btn).should('have.attr', 'class');
});
});
it('should support keyboard navigation for tabs', () => {
cy.get('edc-management')
.shadow()
.find('.sidebar nav button')
.first()
.focus()
.type('{enter}');
cy.get('edc-management')
.shadow()
.find('.sidebar nav button.active')
.should('contain', 'Assets');
});
});
});