|
1 | 1 | import { describe, expect, it } from 'vitest'; |
2 | 2 | import { screen } from '@testing-library/react'; |
3 | | -import testRender, { createMockUserContext } from '../../../../utils/tests/test-render'; |
| 3 | +import testRender from '../../../../utils/tests/test-render'; |
4 | 4 | import StixDomainObjectTabsBox from './StixDomainObjectTabsBox'; |
5 | 5 |
|
6 | 6 | const TABS_TEST_DATA = [ |
@@ -43,161 +43,4 @@ describe('StixDomainObjectTabsBox', () => { |
43 | 43 | ); |
44 | 44 | expect(screen.getByText(/some extra action/i)).toBeInTheDocument(); |
45 | 45 | }); |
46 | | - |
47 | | - describe('when CUSTOM_VIEW feature flag is disabled', () => { |
48 | | - it('does not render another tab when custom view available', () => { |
49 | | - const customViewDisplayName = 'My custom view'; |
50 | | - const customViewPath = 'some-path'; |
51 | | - testRender( |
52 | | - <StixDomainObjectTabsBox |
53 | | - entityType="Intrusion-Set" |
54 | | - tabs={[]} |
55 | | - basePath="" |
56 | | - />, |
57 | | - { |
58 | | - userContext: createMockUserContext({ |
59 | | - settings: { |
60 | | - platform_feature_flags: [{ |
61 | | - id: 'CUSTOM_VIEW', |
62 | | - enable: false, |
63 | | - }], |
64 | | - }, |
65 | | - customViews: [{ |
66 | | - entity_type: 'Intrusion-Set', |
67 | | - custom_views_info: [{ |
68 | | - id: '1504f07b-ee3f-4c09-ae66-b9550eb3abe3', |
69 | | - name: customViewDisplayName, |
70 | | - path: customViewPath, |
71 | | - }], |
72 | | - }], |
73 | | - }), |
74 | | - }, |
75 | | - ); |
76 | | - expect(screen.queryByRole('tab', { |
77 | | - name: new RegExp(customViewDisplayName, 'i'), |
78 | | - })).not.toBeInTheDocument(); |
79 | | - expect(screen.queryByRole('tab', { |
80 | | - name: /Custom view/i, |
81 | | - })).not.toBeInTheDocument(); |
82 | | - }); |
83 | | - }); |
84 | | - |
85 | | - describe('when CUSTOM_VIEW feature flag is enabled', () => { |
86 | | - it('renders another tab when custom view available', () => { |
87 | | - const customViewDisplayName = 'My custom view'; |
88 | | - const customViewPath = 'some-path'; |
89 | | - testRender( |
90 | | - <StixDomainObjectTabsBox |
91 | | - entityType="Intrusion-Set" |
92 | | - tabs={[]} |
93 | | - basePath="" |
94 | | - />, |
95 | | - { |
96 | | - userContext: createMockUserContext({ |
97 | | - settings: { |
98 | | - platform_feature_flags: [{ |
99 | | - id: 'CUSTOM_VIEW', |
100 | | - enable: true, |
101 | | - }], |
102 | | - }, |
103 | | - customViews: [{ |
104 | | - entity_type: 'Intrusion-Set', |
105 | | - custom_views_info: [{ |
106 | | - id: '1504f07b-ee3f-4c09-ae66-b9550eb3abe3', |
107 | | - name: customViewDisplayName, |
108 | | - path: customViewPath, |
109 | | - }], |
110 | | - }], |
111 | | - }), |
112 | | - }, |
113 | | - ); |
114 | | - const tabElem = screen.getByRole('tab', { name: new RegExp(customViewDisplayName, 'i') }); |
115 | | - expect(tabElem).toBeInTheDocument(); |
116 | | - expect(tabElem).toHaveAttribute( |
117 | | - 'href', |
118 | | - expect.stringMatching(new RegExp(`${customViewPath}$`)), |
119 | | - ); |
120 | | - }); |
121 | | - |
122 | | - it('renders a "Custom view" tab when multiple custom views available', async () => { |
123 | | - const { user } = testRender( |
124 | | - <StixDomainObjectTabsBox |
125 | | - entityType="Intrusion-Set" |
126 | | - tabs={[]} |
127 | | - basePath="" |
128 | | - />, |
129 | | - { |
130 | | - userContext: createMockUserContext({ |
131 | | - settings: { |
132 | | - platform_feature_flags: [{ |
133 | | - id: 'CUSTOM_VIEW', |
134 | | - enable: true, |
135 | | - }], |
136 | | - }, |
137 | | - customViews: [{ |
138 | | - entity_type: 'Intrusion-Set', |
139 | | - custom_views_info: [{ |
140 | | - id: '1504f07b-ee3f-4c09-ae66-b9550eb3abe3', |
141 | | - name: 'My first custom view', |
142 | | - path: 'some-path', |
143 | | - }, { |
144 | | - id: '90ebf22f-2c36-4836-b21a-e114ed4ca2ab', |
145 | | - name: 'My second custom view', |
146 | | - path: 'some-other-path', |
147 | | - }], |
148 | | - }], |
149 | | - }), |
150 | | - }, |
151 | | - ); |
152 | | - const tabElem = screen.getByRole('tab', { name: /Custom view/i }); |
153 | | - expect(tabElem).toBeInTheDocument(); |
154 | | - await user.click(tabElem); |
155 | | - const firstLinkElem = screen.getByRole('link', { name: /My first custom view/i }); |
156 | | - expect(firstLinkElem).toHaveAttribute( |
157 | | - 'href', |
158 | | - expect.stringMatching(/some-path$/), |
159 | | - ); |
160 | | - const secondLinkElem = screen.getByRole('link', { name: /My second custom view/i }); |
161 | | - expect(secondLinkElem).toHaveAttribute( |
162 | | - 'href', |
163 | | - expect.stringMatching(/some-other-path$/), |
164 | | - ); |
165 | | - }); |
166 | | - |
167 | | - it('does not renders another tab when custom view available but for other entity type', () => { |
168 | | - const customViewDisplayName = 'My custom view'; |
169 | | - const customViewPath = 'some-path'; |
170 | | - testRender( |
171 | | - <StixDomainObjectTabsBox |
172 | | - entityType="Case-Rft" |
173 | | - tabs={[]} |
174 | | - basePath="" |
175 | | - />, |
176 | | - { |
177 | | - userContext: createMockUserContext({ |
178 | | - settings: { |
179 | | - platform_feature_flags: [{ |
180 | | - id: 'CUSTOM_VIEW', |
181 | | - enable: true, |
182 | | - }], |
183 | | - }, |
184 | | - customViews: [{ |
185 | | - entity_type: 'Intrusion-Set', |
186 | | - custom_views_info: [{ |
187 | | - id: '1504f07b-ee3f-4c09-ae66-b9550eb3abe3', |
188 | | - name: customViewDisplayName, |
189 | | - path: customViewPath, |
190 | | - }], |
191 | | - }], |
192 | | - }), |
193 | | - }, |
194 | | - ); |
195 | | - expect(screen.queryByRole('tab', { |
196 | | - name: new RegExp(customViewDisplayName, 'i'), |
197 | | - })).not.toBeInTheDocument(); |
198 | | - expect(screen.queryByRole('tab', { |
199 | | - name: /Custom view/i, |
200 | | - })).not.toBeInTheDocument(); |
201 | | - }); |
202 | | - }); |
203 | 46 | }); |
0 commit comments