@@ -23,6 +23,11 @@ let axiosMock;
2323const blockId = '123' ;
2424const handleCreateNewCourseXBlockMock = jest . fn ( ) ;
2525
26+ // Mock ComponentPicker to call onComponentSelected on load
27+ jest . mock ( '../../library-authoring/component-picker' , ( ) => ( {
28+ ComponentPicker : ( props ) => props . onComponentSelected ( { usageKey : 'test-usage-key' , blockType : 'html' } ) ,
29+ } ) ) ;
30+
2631const renderComponent = ( props ) => render (
2732 < AppProvider store = { store } >
2833 < IntlProvider locale = "en" >
@@ -59,11 +64,19 @@ describe('<AddComponent />', () => {
5964 const componentTemplates = courseSectionVerticalMock . component_templates ;
6065
6166 expect ( getByRole ( 'heading' , { name : messages . title . defaultMessage } ) ) . toBeInTheDocument ( ) ;
62- Object . keys ( componentTemplates ) . map ( ( component ) => (
63- expect ( getByRole ( 'button' , {
64- name : new RegExp ( `${ messages . buttonText . defaultMessage } ${ componentTemplates [ component ] . display_name } ` , 'i' ) ,
65- } ) ) . toBeInTheDocument ( )
66- ) ) ;
67+ Object . keys ( componentTemplates ) . forEach ( ( component ) => {
68+ const btn = getByRole ( 'button' , {
69+ name : new RegExp (
70+ `${ componentTemplates [ component ] . type
71+ } ${ messages . buttonText . defaultMessage } ${ componentTemplates [ component ] . display_name } `,
72+ 'i' ,
73+ ) ,
74+ } ) ;
75+ expect ( btn ) . toBeInTheDocument ( ) ;
76+ if ( component . beta ) {
77+ expect ( within ( btn ) . queryByText ( 'Beta' ) ) . toBeInTheDocument ( ) ;
78+ }
79+ } ) ;
6780 } ) ;
6881
6982 it ( 'AddComponent component doesn\'t render when there aren\'t componentTemplates' , async ( ) => {
@@ -111,7 +124,11 @@ describe('<AddComponent />', () => {
111124 }
112125
113126 return expect ( getByRole ( 'button' , {
114- name : new RegExp ( `${ messages . buttonText . defaultMessage } ${ componentTemplates [ component ] . display_name } ` , 'i' ) ,
127+ name : new RegExp (
128+ `${ componentTemplates [ component ] . type
129+ } ${ messages . buttonText . defaultMessage } ${ componentTemplates [ component ] . display_name } `,
130+ 'i' ,
131+ ) ,
115132 } ) ) . toBeInTheDocument ( ) ;
116133 } ) ;
117134 } ) ;
@@ -176,7 +193,7 @@ describe('<AddComponent />', () => {
176193 const { getByRole } = renderComponent ( ) ;
177194
178195 const discussionButton = getByRole ( 'button' , {
179- name : new RegExp ( `${ messages . buttonText . defaultMessage } Problem` , 'i' ) ,
196+ name : new RegExp ( `problem ${ messages . buttonText . defaultMessage } Problem` , 'i' ) ,
180197 } ) ;
181198
182199 userEvent . click ( discussionButton ) ;
@@ -187,6 +204,22 @@ describe('<AddComponent />', () => {
187204 } , expect . any ( Function ) ) ;
188205 } ) ;
189206
207+ it ( 'calls handleCreateNewCourseXBlock with correct parameters when Problem bank xblock create button is clicked' , ( ) => {
208+ const { getByRole } = renderComponent ( ) ;
209+
210+ const problemBankBtn = getByRole ( 'button' , {
211+ name : new RegExp ( `${ messages . buttonText . defaultMessage } Problem Bank` , 'i' ) ,
212+ } ) ;
213+
214+ userEvent . click ( problemBankBtn ) ;
215+ expect ( handleCreateNewCourseXBlockMock ) . toHaveBeenCalled ( ) ;
216+ expect ( handleCreateNewCourseXBlockMock ) . toHaveBeenCalledWith ( {
217+ parentLocator : '123' ,
218+ type : COMPONENT_TYPES . itembank ,
219+ category : 'itembank' ,
220+ } ) ;
221+ } ) ;
222+
190223 it ( 'calls handleCreateNewCourseXBlock with correct parameters when Video xblock create button is clicked' , ( ) => {
191224 const { getByRole } = renderComponent ( ) ;
192225
@@ -206,7 +239,7 @@ describe('<AddComponent />', () => {
206239 const { getByRole } = renderComponent ( ) ;
207240
208241 const libraryButton = getByRole ( 'button' , {
209- name : new RegExp ( `${ messages . buttonText . defaultMessage } Library Content` , 'i' ) ,
242+ name : new RegExp ( `${ messages . buttonText . defaultMessage } Legacy Library Content` , 'i' ) ,
210243 } ) ;
211244
212245 userEvent . click ( libraryButton ) ;
@@ -379,6 +412,22 @@ describe('<AddComponent />', () => {
379412 } ) ;
380413 } ) ;
381414
415+ it ( 'shows library picker on clicking v2 library content btn' , async ( ) => {
416+ const { findByRole } = renderComponent ( ) ;
417+ const libBtn = await findByRole ( 'button' , {
418+ name : new RegExp ( `${ messages . buttonText . defaultMessage } Library content` , 'i' ) ,
419+ } ) ;
420+
421+ userEvent . click ( libBtn ) ;
422+ expect ( handleCreateNewCourseXBlockMock ) . toHaveBeenCalled ( ) ;
423+ expect ( handleCreateNewCourseXBlockMock ) . toHaveBeenCalledWith ( {
424+ type : COMPONENT_TYPES . libraryV2 ,
425+ parentLocator : '123' ,
426+ category : 'html' ,
427+ libraryContentKey : 'test-usage-key' ,
428+ } ) ;
429+ } ) ;
430+
382431 describe ( 'component support label' , ( ) => {
383432 it ( 'component support label is hidden if component support legend is disabled' , async ( ) => {
384433 const supportLevels = [ 'fs' , 'ps' ] ;
0 commit comments