@@ -3,7 +3,9 @@ import { http, HttpResponse } from 'msw';
33import { Download , SignMeOthers } from '@box/blueprint-web-assets/icons/Fill/index' ;
44import { Sign } from '@box/blueprint-web-assets/icons/Line' ;
55import { expect , fn , userEvent , waitFor , within , screen } from 'storybook/test' ;
6+
67import noop from 'lodash/noop' ;
8+ import orderBy from 'lodash/orderBy' ;
79
810import ContentExplorer from '../../ContentExplorer' ;
911import { DEFAULT_HOSTNAME_API } from '../../../../constants' ;
@@ -138,17 +140,16 @@ export const metadataViewV2: Story = {
138140 args : metadataViewV2ElementProps ,
139141} ;
140142
141- // @TODO Assert that rows are actually sorted in a different order, once handleSortChange is implemented
142143export const metadataViewV2SortsFromHeader : Story = {
143144 args : metadataViewV2ElementProps ,
144145 play : async ( { canvas } ) => {
145- await waitFor ( ( ) => {
146- expect ( canvas . getByRole ( 'row' , { name : / I n d u s t r y / i } ) ) . toBeInTheDocument ( ) ;
147- } ) ;
146+ const industryHeader = await canvas . findByRole ( 'columnheader' , { name : 'Industry' } ) ;
147+ expect ( industryHeader ) . toBeInTheDocument ( ) ;
148148
149- const firstRow = canvas . getByRole ( 'row' , { name : / I n d u s t r y / i } ) ;
150- const industryHeader = within ( firstRow ) . getByRole ( 'columnheader' , { name : 'Industry' } ) ;
151- userEvent . click ( industryHeader ) ;
149+ const firstRow = await canvas . findByRole ( 'row' , { name : / C h i l d 2 / i } ) ;
150+ expect ( firstRow ) . toBeInTheDocument ( ) ;
151+
152+ await userEvent . click ( industryHeader ) ;
152153 } ,
153154} ;
154155
@@ -248,7 +249,21 @@ const meta: Meta<typeof ContentExplorer> = {
248249 parameters : {
249250 msw : {
250251 handlers : [
251- http . post ( `${ DEFAULT_HOSTNAME_API } /2.0/metadata_queries/execute_read` , ( ) => {
252+ // Note that the Metadata API backend normally handles the sorting. The mocks below simulate the sorting for specific cases, but may not 100% accurately reflect the backend behavior.
253+ http . post ( `${ DEFAULT_HOSTNAME_API } /2.0/metadata_queries/execute_read` , async ( { request } ) => {
254+ const body = await request . clone ( ) . json ( ) ;
255+ const orderByDirection = body . order_by [ 0 ] . direction ;
256+ const orderByFieldKey = body . order_by [ 0 ] . field_key ;
257+
258+ // Hardcoded case for sorting by industry
259+ if ( orderByFieldKey === `${ metadataFieldNamePrefix } .industry` && orderByDirection === 'ASC' ) {
260+ const sortedMetadata = orderBy (
261+ mockMetadata . entries ,
262+ 'metadata.enterprise_0.templateName.industry' ,
263+ 'asc' ,
264+ ) ;
265+ return HttpResponse . json ( { ...mockMetadata , entries : sortedMetadata } ) ;
266+ }
252267 return HttpResponse . json ( mockMetadata ) ;
253268 } ) ,
254269 http . get ( `${ DEFAULT_HOSTNAME_API } /2.0/metadata_templates/enterprise/templateName/schema` , ( ) => {
0 commit comments