|
| 1 | +/* eslint-disable camelcase */ |
| 2 | +import type { Namespace } from 'mod-arch-core'; |
| 3 | +import { mockNamespace } from '~/__mocks__/mockNamespace'; |
| 4 | +import { mockModelRegistry } from '~/__mocks__/mockModelRegistry'; |
| 5 | +import { registerAndStoreFields } from '~/__tests__/cypress/cypress/pages/modelRegistryView/registerAndStoreFields'; |
| 6 | +import { MODEL_REGISTRY_API_VERSION } from '~/__tests__/cypress/cypress/support/commands/api'; |
| 7 | +import type { ModelRegistry, RegisteredModel } from '~/app/types'; |
| 8 | +import { mockRegisteredModelList } from '~/__mocks__/mockRegisteredModelsList'; |
| 9 | + |
| 10 | +type HandlersProps = { |
| 11 | + modelRegistries?: ModelRegistry[]; |
| 12 | + namespaces?: Namespace[]; |
| 13 | + registeredModels?: RegisteredModel[]; |
| 14 | +}; |
| 15 | + |
| 16 | +const initIntercepts = ({ |
| 17 | + modelRegistries = [mockModelRegistry({ name: 'modelregistry-sample' })], |
| 18 | + namespaces = [ |
| 19 | + mockNamespace({ name: 'namespace-1' }), |
| 20 | + mockNamespace({ name: 'namespace-2' }), |
| 21 | + mockNamespace({ name: 'namespace-3' }), |
| 22 | + ], |
| 23 | + registeredModels = [], |
| 24 | +}: HandlersProps = {}) => { |
| 25 | + cy.interceptApi( |
| 26 | + 'GET /api/:apiVersion/namespaces', |
| 27 | + { |
| 28 | + path: { apiVersion: MODEL_REGISTRY_API_VERSION }, |
| 29 | + }, |
| 30 | + namespaces, |
| 31 | + ); |
| 32 | + |
| 33 | + cy.interceptApi( |
| 34 | + `GET /api/:apiVersion/model_registry`, |
| 35 | + { |
| 36 | + path: { apiVersion: MODEL_REGISTRY_API_VERSION }, |
| 37 | + }, |
| 38 | + modelRegistries, |
| 39 | + ); |
| 40 | + |
| 41 | + cy.interceptApi( |
| 42 | + 'GET /api/:apiVersion/model_registry/:modelRegistryName/registered_models', |
| 43 | + { |
| 44 | + path: { |
| 45 | + apiVersion: MODEL_REGISTRY_API_VERSION, |
| 46 | + modelRegistryName: 'modelregistry-sample', |
| 47 | + }, |
| 48 | + }, |
| 49 | + mockRegisteredModelList({ items: registeredModels }), |
| 50 | + ); |
| 51 | +}; |
| 52 | + |
| 53 | +describe('Register and Store Fields - Toggle Behavior', () => { |
| 54 | + beforeEach(() => { |
| 55 | + initIntercepts({}); |
| 56 | + registerAndStoreFields.visit(); |
| 57 | + }); |
| 58 | + |
| 59 | + it('Should display registration mode toggle when feature is enabled', () => { |
| 60 | + registerAndStoreFields.shouldHaveRegistrationModeToggle(); |
| 61 | + }); |
| 62 | + |
| 63 | + it('Should have "Register" mode selected by default', () => { |
| 64 | + registerAndStoreFields.shouldHaveRegisterModeSelected(); |
| 65 | + }); |
| 66 | + |
| 67 | + it('Should switch to "Register and store" mode', () => { |
| 68 | + registerAndStoreFields.selectRegisterAndStoreMode(); |
| 69 | + registerAndStoreFields.shouldHaveRegisterAndStoreModeSelected(); |
| 70 | + }); |
| 71 | + |
| 72 | + it('Should show namespace selector only in "Register and store" mode', () => { |
| 73 | + registerAndStoreFields.findNamespaceFormGroup().should('not.exist'); |
| 74 | + registerAndStoreFields.selectRegisterAndStoreMode(); |
| 75 | + registerAndStoreFields.findNamespaceSelector().should('exist'); |
| 76 | + }); |
| 77 | + |
| 78 | + it('Should switch back to "Register" mode and hide namespace selector', () => { |
| 79 | + registerAndStoreFields.selectRegisterAndStoreMode(); |
| 80 | + registerAndStoreFields.findNamespaceSelector().should('exist'); |
| 81 | + registerAndStoreFields.selectRegisterMode(); |
| 82 | + registerAndStoreFields.shouldHaveRegisterModeSelected(); |
| 83 | + registerAndStoreFields.findNamespaceSelector().should('not.exist'); |
| 84 | + }); |
| 85 | + |
| 86 | + it('Should reset namespace selection when switching modes', () => { |
| 87 | + registerAndStoreFields.selectRegisterAndStoreMode(); |
| 88 | + registerAndStoreFields.selectNamespace('namespace-1'); |
| 89 | + registerAndStoreFields.shouldShowSelectedNamespace('namespace-1'); |
| 90 | + registerAndStoreFields.selectRegisterMode(); |
| 91 | + registerAndStoreFields.selectRegisterAndStoreMode(); |
| 92 | + registerAndStoreFields.shouldShowPlaceholder('Select a namespace'); |
| 93 | + }); |
| 94 | +}); |
| 95 | + |
| 96 | +describe('Register and Store Fields - NamespaceSelector', () => { |
| 97 | + beforeEach(() => { |
| 98 | + initIntercepts({}); |
| 99 | + registerAndStoreFields.visit(); |
| 100 | + registerAndStoreFields.selectRegisterAndStoreMode(); |
| 101 | + }); |
| 102 | + |
| 103 | + it('Should show placeholder text instead of auto-selecting', () => { |
| 104 | + registerAndStoreFields.shouldShowPlaceholder('Select a namespace'); |
| 105 | + }); |
| 106 | + |
| 107 | + it('Should display all available namespaces in dropdown', () => { |
| 108 | + registerAndStoreFields.shouldHaveNamespaceOptions([ |
| 109 | + 'namespace-1', |
| 110 | + 'namespace-2', |
| 111 | + 'namespace-3', |
| 112 | + ]); |
| 113 | + }); |
| 114 | + |
| 115 | + it('Should hide form sections until namespace is selected', () => { |
| 116 | + registerAndStoreFields.shouldHideOriginLocationSection().shouldHideDestinationLocationSection(); |
| 117 | + }); |
| 118 | + |
| 119 | + it('Should show form sections after namespace selection', () => { |
| 120 | + registerAndStoreFields.selectNamespace('namespace-1'); |
| 121 | + |
| 122 | + registerAndStoreFields.shouldShowOriginLocationSection(); |
| 123 | + registerAndStoreFields.shouldShowDestinationLocationSection(); |
| 124 | + }); |
| 125 | + |
| 126 | + it('Should update selected namespace in dropdown', () => { |
| 127 | + registerAndStoreFields.selectNamespace('namespace-2'); |
| 128 | + registerAndStoreFields.shouldShowSelectedNamespace('namespace-2'); |
| 129 | + }); |
| 130 | + |
| 131 | + it('Should handle empty namespace list gracefully', () => { |
| 132 | + initIntercepts({ namespaces: [] }); |
| 133 | + registerAndStoreFields.visit(); |
| 134 | + registerAndStoreFields.selectRegisterAndStoreMode(); |
| 135 | + |
| 136 | + registerAndStoreFields.findNamespaceSelector().should('exist'); |
| 137 | + registerAndStoreFields.findNamespaceSelector().should('be.disabled'); |
| 138 | + |
| 139 | + registerAndStoreFields.shouldShowPlaceholder('Select a namespace'); |
| 140 | + }); |
| 141 | +}); |
0 commit comments