mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	test: move tests from cypress to rtl (#6987)
This commit is contained in:
		
							parent
							
								
									913f81b40c
								
							
						
					
					
						commit
						a45be8d10c
					
				
							
								
								
									
										1
									
								
								.github/workflows/e2e.frontend.yaml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.github/workflows/e2e.frontend.yaml
									
									
									
									
										vendored
									
									
								
							@ -10,7 +10,6 @@ jobs:
 | 
				
			|||||||
          - feature/feature.spec.ts
 | 
					          - feature/feature.spec.ts
 | 
				
			||||||
          - groups/groups.spec.ts
 | 
					          - groups/groups.spec.ts
 | 
				
			||||||
          - projects/access.spec.ts
 | 
					          - projects/access.spec.ts
 | 
				
			||||||
          - projects/overview.spec.ts
 | 
					 | 
				
			||||||
          - segments/segments.spec.ts
 | 
					          - segments/segments.spec.ts
 | 
				
			||||||
    steps:
 | 
					    steps:
 | 
				
			||||||
      - name: Dump GitHub context
 | 
					      - name: Dump GitHub context
 | 
				
			||||||
 | 
				
			|||||||
@ -1,94 +0,0 @@
 | 
				
			|||||||
///<reference path="../../global.d.ts" />
 | 
					 | 
				
			||||||
import {
 | 
					 | 
				
			||||||
    BATCH_ACTIONS_BAR,
 | 
					 | 
				
			||||||
    MORE_BATCH_ACTIONS,
 | 
					 | 
				
			||||||
    SEARCH_INPUT,
 | 
					 | 
				
			||||||
    //@ts-ignore
 | 
					 | 
				
			||||||
} from '../../../src/utils/testIds';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
describe('project overview', () => {
 | 
					 | 
				
			||||||
    const randomId = String(Math.random()).split('.')[1];
 | 
					 | 
				
			||||||
    const featureTogglePrefix = 'unleash-e2e-project-overview';
 | 
					 | 
				
			||||||
    const featureToggleName = `${featureTogglePrefix}-${randomId}`;
 | 
					 | 
				
			||||||
    const projectName = `unleash-e2e-project-overview-${randomId}`;
 | 
					 | 
				
			||||||
    const baseUrl = Cypress.config().baseUrl;
 | 
					 | 
				
			||||||
    const selectAll = '[title="Select all rows"] input[type="checkbox"]';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    before(() => {
 | 
					 | 
				
			||||||
        cy.runBefore();
 | 
					 | 
				
			||||||
        cy.login_UI();
 | 
					 | 
				
			||||||
        cy.createProject_API(projectName);
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    after(() => {
 | 
					 | 
				
			||||||
        cy.request({
 | 
					 | 
				
			||||||
            method: 'DELETE',
 | 
					 | 
				
			||||||
            url: `${baseUrl}/api/admin/projects/${projectName}/features/${featureToggleName}-A`,
 | 
					 | 
				
			||||||
            failOnStatusCode: false,
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        cy.request({
 | 
					 | 
				
			||||||
            method: 'DELETE',
 | 
					 | 
				
			||||||
            url: `${baseUrl}/api/admin/projects/${projectName}/features/${featureToggleName}-B`,
 | 
					 | 
				
			||||||
            failOnStatusCode: false,
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        cy.request({
 | 
					 | 
				
			||||||
            method: 'DELETE',
 | 
					 | 
				
			||||||
            url: `${baseUrl}/api/admin/archive/${featureToggleName}-A`,
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        cy.request({
 | 
					 | 
				
			||||||
            method: 'DELETE',
 | 
					 | 
				
			||||||
            url: `${baseUrl}/api/admin/archive/${featureToggleName}-B`,
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        cy.deleteProject_API(projectName);
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    it('can mark selected togggles as stale', () => {
 | 
					 | 
				
			||||||
        cy.login_UI();
 | 
					 | 
				
			||||||
        cy.visit(`/projects/${projectName}`);
 | 
					 | 
				
			||||||
        cy.viewport(1920, 1080);
 | 
					 | 
				
			||||||
        cy.get(`[data-testid="${SEARCH_INPUT}"]`).as('search').click();
 | 
					 | 
				
			||||||
        cy.get('@search').type(featureToggleName);
 | 
					 | 
				
			||||||
        cy.get('body').type('{esc}');
 | 
					 | 
				
			||||||
        cy.get('table tbody tr').should((elements) => {
 | 
					 | 
				
			||||||
            expect(elements).to.have.length.at.least(2);
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        cy.get(selectAll).click();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        cy.get(`[data-testid="${MORE_BATCH_ACTIONS}"]`).click();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        cy.get('[role="menuitem"]').contains('Mark as stale').click();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        cy.visit(`/projects/${projectName}/features/${featureToggleName}-A`);
 | 
					 | 
				
			||||||
        cy.get('[title="Feature toggle is deprecated."]').should('exist');
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    it('can archive selected togggles', () => {
 | 
					 | 
				
			||||||
        cy.login_UI();
 | 
					 | 
				
			||||||
        cy.visit(`/projects/${projectName}`);
 | 
					 | 
				
			||||||
        cy.viewport(1920, 1080);
 | 
					 | 
				
			||||||
        cy.get(`[data-testid="${SEARCH_INPUT}"]`).as('search').click();
 | 
					 | 
				
			||||||
        cy.get('@search').type(featureToggleName);
 | 
					 | 
				
			||||||
        cy.get('body').type('{esc}');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        cy.get('table tbody tr').should((elements) => {
 | 
					 | 
				
			||||||
            expect(elements).to.have.length.at.least(2);
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        cy.get(selectAll).click();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Ensure button is enabled
 | 
					 | 
				
			||||||
        cy.get(`[data-testid=${BATCH_ACTIONS_BAR}] button`)
 | 
					 | 
				
			||||||
            .contains('Archive')
 | 
					 | 
				
			||||||
            .should('not.have.attr', 'disabled');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Separate click action
 | 
					 | 
				
			||||||
        cy.get(`[data-testid=${BATCH_ACTIONS_BAR}] button`)
 | 
					 | 
				
			||||||
            .contains('Archive')
 | 
					 | 
				
			||||||
            .click();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        cy.get('p')
 | 
					 | 
				
			||||||
            .contains('Are you sure you want to archive ')
 | 
					 | 
				
			||||||
            .should('exist');
 | 
					 | 
				
			||||||
        cy.get('button').contains('Archive toggles').click();
 | 
					 | 
				
			||||||
        cy.get('table tbody tr').should('have.length', 0);
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
@ -8,9 +8,6 @@ const server = testServerSetup();
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
test('Display extended daily metrics', async () => {
 | 
					test('Display extended daily metrics', async () => {
 | 
				
			||||||
    testServerRoute(server, '/api/admin/ui-config', {
 | 
					    testServerRoute(server, '/api/admin/ui-config', {
 | 
				
			||||||
        flags: {
 | 
					 | 
				
			||||||
            extendedUsageMetricsUI: true,
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        versionInfo: {
 | 
					        versionInfo: {
 | 
				
			||||||
            current: { oss: 'irrelevant', enterprise: 'some value' },
 | 
					            current: { oss: 'irrelevant', enterprise: 'some value' },
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,71 @@
 | 
				
			|||||||
 | 
					import { render } from 'utils/testRenderer';
 | 
				
			||||||
 | 
					import { screen, waitFor } from '@testing-library/react';
 | 
				
			||||||
 | 
					import { ProjectFeaturesBatchActions } from './ProjectFeaturesBatchActions';
 | 
				
			||||||
 | 
					import { DELETE_FEATURE } from 'component/providers/AccessProvider/permissions';
 | 
				
			||||||
 | 
					import { testServerRoute, testServerSetup } from 'utils/testServer';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const server = testServerSetup();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const setupApi = () => {
 | 
				
			||||||
 | 
					    testServerRoute(server, '/api/admin/projects/default/stale', {}, 'post');
 | 
				
			||||||
 | 
					    testServerRoute(server, '/api/admin/ui-config', {});
 | 
				
			||||||
 | 
					    testServerRoute(
 | 
				
			||||||
 | 
					        server,
 | 
				
			||||||
 | 
					        '/api/admin/projects/default/archive/validate',
 | 
				
			||||||
 | 
					        { hasDeletedDependencies: false, parentsWithChildFeatures: [] },
 | 
				
			||||||
 | 
					        'post',
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test('batch archive', async () => {
 | 
				
			||||||
 | 
					    setupApi();
 | 
				
			||||||
 | 
					    render(
 | 
				
			||||||
 | 
					        <ProjectFeaturesBatchActions
 | 
				
			||||||
 | 
					            projectId='default'
 | 
				
			||||||
 | 
					            onChange={() => {}}
 | 
				
			||||||
 | 
					            onResetSelection={() => {}}
 | 
				
			||||||
 | 
					            selectedIds={['featureA', 'featureB']}
 | 
				
			||||||
 | 
					            data={[]}
 | 
				
			||||||
 | 
					        />,
 | 
				
			||||||
 | 
					        { permissions: [{ permission: DELETE_FEATURE }] },
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const archiveButton = screen.getByText('Archive');
 | 
				
			||||||
 | 
					    expect(archiveButton).toBeEnabled();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    archiveButton.click();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    screen.getByText('Archive feature toggles');
 | 
				
			||||||
 | 
					    screen.getByText('featureA');
 | 
				
			||||||
 | 
					    screen.getByText('featureB');
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test('batch mark as stale', async () => {
 | 
				
			||||||
 | 
					    setupApi();
 | 
				
			||||||
 | 
					    let onChangeCalled = false;
 | 
				
			||||||
 | 
					    render(
 | 
				
			||||||
 | 
					        <ProjectFeaturesBatchActions
 | 
				
			||||||
 | 
					            projectId='default'
 | 
				
			||||||
 | 
					            onChange={() => {
 | 
				
			||||||
 | 
					                onChangeCalled = true;
 | 
				
			||||||
 | 
					            }}
 | 
				
			||||||
 | 
					            onResetSelection={() => {}}
 | 
				
			||||||
 | 
					            selectedIds={['featureA', 'featureB']}
 | 
				
			||||||
 | 
					            data={[
 | 
				
			||||||
 | 
					                { name: 'featureA', stale: false },
 | 
				
			||||||
 | 
					                { name: 'featureB', stale: false },
 | 
				
			||||||
 | 
					            ]}
 | 
				
			||||||
 | 
					        />,
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const moreActions = screen.getByTitle('More bulk actions');
 | 
				
			||||||
 | 
					    moreActions.click();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const markAsStale = await screen.findByText('Mark as stale');
 | 
				
			||||||
 | 
					    expect(markAsStale).toBeEnabled();
 | 
				
			||||||
 | 
					    markAsStale.click();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    await waitFor(() => {
 | 
				
			||||||
 | 
					        expect(onChangeCalled).toBe(true);
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user