|
| 1 | +import { mockModArchResponse } from 'mod-arch-core'; |
| 2 | +import { createWorkspace } from '~/__tests__/cypress/cypress/pages/workspaces/createWorkspace'; |
| 3 | +import { buildMockNamespace, buildMockWorkspaceKind } from '~/shared/mock/mockBuilder'; |
| 4 | +import { NOTEBOOKS_API_VERSION } from '~/__tests__/cypress/cypress/support/commands/api'; |
| 5 | +import { navBar } from '~/__tests__/cypress/cypress/pages/components/navBar'; |
| 6 | +import type { WorkspacekindsImageConfigValue } from '~/generated/data-contracts'; |
| 7 | +import { WorkspacekindsRedirectMessageLevel } from '~/generated/data-contracts'; |
| 8 | + |
| 9 | +const buildMockImageConfigValue = ( |
| 10 | + overrides?: Partial<WorkspacekindsImageConfigValue>, |
| 11 | +): WorkspacekindsImageConfigValue => ({ |
| 12 | + id: 'default-image', |
| 13 | + displayName: 'Default Image', |
| 14 | + description: 'Default description', |
| 15 | + labels: [], |
| 16 | + hidden: false, |
| 17 | + ...overrides, |
| 18 | +}); |
| 19 | + |
| 20 | +const DEFAULT_NAMESPACE = 'default'; |
| 21 | + |
| 22 | +describe('Summary Redirect Popover - Delayed Hide Behavior', () => { |
| 23 | + let mockNamespace: ReturnType<typeof buildMockNamespace>; |
| 24 | + let mockWorkspaceKind: ReturnType<typeof buildMockWorkspaceKind>; |
| 25 | + |
| 26 | + beforeEach(() => { |
| 27 | + mockNamespace = buildMockNamespace({ name: DEFAULT_NAMESPACE }); |
| 28 | + |
| 29 | + const sourceImage = buildMockImageConfigValue({ |
| 30 | + id: 'source-image', |
| 31 | + displayName: 'Source Image v1.0', |
| 32 | + description: 'Old version image', |
| 33 | + redirect: { |
| 34 | + to: 'target-image', |
| 35 | + message: { |
| 36 | + level: WorkspacekindsRedirectMessageLevel.RedirectMessageLevelWarning, |
| 37 | + text: 'This image is deprecated. Please use the target image.', |
| 38 | + }, |
| 39 | + }, |
| 40 | + }); |
| 41 | + |
| 42 | + const targetImage = buildMockImageConfigValue({ |
| 43 | + id: 'target-image', |
| 44 | + displayName: 'Target Image v2.0', |
| 45 | + description: 'New version image', |
| 46 | + }); |
| 47 | + |
| 48 | + mockWorkspaceKind = buildMockWorkspaceKind({ |
| 49 | + name: 'test-kind', |
| 50 | + displayName: 'Test Workspace Kind', |
| 51 | + podTemplate: { |
| 52 | + ...buildMockWorkspaceKind().podTemplate, |
| 53 | + options: { |
| 54 | + ...buildMockWorkspaceKind().podTemplate.options, |
| 55 | + imageConfig: { |
| 56 | + default: 'source-image', |
| 57 | + values: [sourceImage, targetImage], |
| 58 | + }, |
| 59 | + }, |
| 60 | + }, |
| 61 | + }); |
| 62 | + |
| 63 | + cy.interceptApi( |
| 64 | + 'GET /api/:apiVersion/namespaces', |
| 65 | + { path: { apiVersion: NOTEBOOKS_API_VERSION } }, |
| 66 | + mockModArchResponse([mockNamespace]), |
| 67 | + ).as('getNamespaces'); |
| 68 | + |
| 69 | + cy.interceptApi( |
| 70 | + 'GET /api/:apiVersion/workspacekinds', |
| 71 | + { path: { apiVersion: NOTEBOOKS_API_VERSION } }, |
| 72 | + mockModArchResponse([mockWorkspaceKind]), |
| 73 | + ).as('getWorkspaceKinds'); |
| 74 | + |
| 75 | + cy.visit('/workspaces/create'); |
| 76 | + cy.wait('@getNamespaces'); |
| 77 | + navBar.selectNamespace(mockNamespace.name); |
| 78 | + cy.wait('@getWorkspaceKinds'); |
| 79 | + |
| 80 | + createWorkspace.selectKind('test-kind'); |
| 81 | + createWorkspace.clickNext(); |
| 82 | + |
| 83 | + // Need to check the showRedirected filter to see images with redirect |
| 84 | + createWorkspace.checkExtraFilter('showRedirected'); |
| 85 | + |
| 86 | + createWorkspace.selectImage('source-image'); |
| 87 | + createWorkspace.assertImageSelected('source-image'); |
| 88 | + }); |
| 89 | + |
| 90 | + describe('Pinning behavior', () => { |
| 91 | + it('should pin popover on icon click', () => { |
| 92 | + createWorkspace.clickNext(); // Pod config |
| 93 | + createWorkspace.clickNext(); // Properties |
| 94 | + |
| 95 | + createWorkspace.findRedirectSummaryIcon(1, 'current').click(); |
| 96 | + createWorkspace.assertPopoverContentVisible(1, 'current'); |
| 97 | + |
| 98 | + createWorkspace.findRedirectSummaryIcon(1, 'current').trigger('mouseleave'); |
| 99 | + createWorkspace.assertPopoverContentVisible(1, 'current'); |
| 100 | + }); |
| 101 | + |
| 102 | + it('should unpin popover on second click', () => { |
| 103 | + createWorkspace.clickNext(); // Pod config |
| 104 | + createWorkspace.clickNext(); // Properties |
| 105 | + |
| 106 | + createWorkspace.findRedirectSummaryIcon(1, 'current').click(); |
| 107 | + createWorkspace.assertPopoverContentVisible(1, 'current'); |
| 108 | + |
| 109 | + createWorkspace.findRedirectSummaryIcon(1, 'current').click(); |
| 110 | + createWorkspace.assertPopoverContentNotExist(1, 'current'); |
| 111 | + }); |
| 112 | + |
| 113 | + it('should not start delayed hide timer when popover is pinned', () => { |
| 114 | + createWorkspace.clickNext(); // Pod config |
| 115 | + createWorkspace.clickNext(); // Properties |
| 116 | + |
| 117 | + createWorkspace.findRedirectSummaryIcon(1, 'current').click(); |
| 118 | + createWorkspace.assertPopoverContentVisible(1, 'current'); |
| 119 | + |
| 120 | + createWorkspace.findRedirectSummaryIcon(1, 'current').trigger('mouseenter'); |
| 121 | + createWorkspace.findRedirectSummaryIcon(1, 'current').trigger('mouseleave'); |
| 122 | + |
| 123 | + createWorkspace.assertPopoverContentVisible(1, 'current'); |
| 124 | + }); |
| 125 | + }); |
| 126 | + |
| 127 | + describe('Keyboard accessibility', () => { |
| 128 | + it('should pin popover on Enter key', () => { |
| 129 | + createWorkspace.clickNext(); // Pod config |
| 130 | + createWorkspace.clickNext(); // Properties |
| 131 | + |
| 132 | + createWorkspace.findRedirectSummaryIcon(1, 'current').focus(); |
| 133 | + createWorkspace.findRedirectSummaryIcon(1, 'current').type('{enter}'); |
| 134 | + createWorkspace.assertPopoverContentVisible(1, 'current'); |
| 135 | + }); |
| 136 | + |
| 137 | + it('should pin popover on Space key', () => { |
| 138 | + createWorkspace.clickNext(); // Pod config |
| 139 | + createWorkspace.clickNext(); // Properties |
| 140 | + |
| 141 | + createWorkspace.findRedirectSummaryIcon(1, 'current').focus(); |
| 142 | + createWorkspace.findRedirectSummaryIcon(1, 'current').type(' '); |
| 143 | + createWorkspace.assertPopoverContentVisible(1, 'current'); |
| 144 | + }); |
| 145 | + }); |
| 146 | +}); |
0 commit comments