@@ -10,6 +10,12 @@ import { TaxonomyType } from '../data/constants';
1010import { TaxonomyCard } from '.' ;
1111import { TaxonomyCardData } from './TaxonomyCard' ;
1212
13+ const mockNavigate = jest . fn ( ) ;
14+ jest . mock ( 'react-router-dom' , ( ) => ( {
15+ ...jest . requireActual ( 'react-router-dom' ) ,
16+ useNavigate : ( ) => mockNavigate ,
17+ } ) ) ;
18+
1319let store ;
1420const taxonomyId = 1 ;
1521
@@ -39,6 +45,7 @@ const TaxonomyCardComponent = ({ original }: { original: TaxonomyCardData; }) =>
3945
4046describe ( '<TaxonomyCard />' , ( ) => {
4147 beforeEach ( async ( ) => {
48+ jest . clearAllMocks ( ) ;
4249 initializeMockApp ( {
4350 authenticatedUser : {
4451 userId : 3 ,
@@ -128,6 +135,38 @@ describe('<TaxonomyCard />', () => {
128135 expect ( queryByTestId ( 'taxonomy-type-icon-competency' ) ) . not . toBeInTheDocument ( ) ;
129136 } ) ;
130137
138+ const applyCompetenciesLabel = 'Apply Competencies' ;
139+
140+ it ( 'shows a footer button that opens the competency management page of a competency taxonomy' , ( ) => {
141+ const cardData = { ...data , taxonomyType : TaxonomyType . Competency } ;
142+
143+ const { getByRole } = render ( < TaxonomyCardComponent original = { cardData } /> ) ;
144+ fireEvent . click ( getByRole ( 'button' , { name : applyCompetenciesLabel } ) ) ;
145+
146+ expect ( mockNavigate ) . toHaveBeenCalledWith ( `/taxonomy/${ taxonomyId } /competencies` ) ;
147+ } ) ;
148+
149+ it ( 'still links the card itself to the taxonomy editing page' , ( ) => {
150+ const cardData = { ...data , taxonomyType : TaxonomyType . Competency } ;
151+
152+ const { getByRole } = render ( < TaxonomyCardComponent original = { cardData } /> ) ;
153+ expect ( getByRole ( 'link' ) ) . toHaveAttribute ( 'href' , `/taxonomy/${ taxonomyId } /` ) ;
154+ } ) ;
155+
156+ it ( 'does not show the footer button on tags taxonomies' , ( ) => {
157+ const cardData = { ...data , taxonomyType : TaxonomyType . Tags } ;
158+
159+ const { queryByRole } = render ( < TaxonomyCardComponent original = { cardData } /> ) ;
160+ expect ( queryByRole ( 'button' , { name : applyCompetenciesLabel } ) ) . not . toBeInTheDocument ( ) ;
161+ } ) ;
162+
163+ it ( 'does not show the footer button to users who cannot change the taxonomy' , ( ) => {
164+ const cardData = { ...data , taxonomyType : TaxonomyType . Competency , canChangeTaxonomy : false } ;
165+
166+ const { queryByRole } = render ( < TaxonomyCardComponent original = { cardData } /> ) ;
167+ expect ( queryByRole ( 'button' , { name : applyCompetenciesLabel } ) ) . not . toBeInTheDocument ( ) ;
168+ } ) ;
169+
131170 it ( 'shows a type icon even when the taxonomy has no type, along with the read-only badge' , ( ) => {
132171 const cardData = { ...data , readOnly : true } ;
133172
0 commit comments