From c6eacbe10b836e75ba40600f3e446d446dd9375c Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Fri, 1 Mar 2024 16:48:23 -0500 Subject: [PATCH] correct tests --- .../RecordingMetadata/BulkEditLabels.test.tsx | 14 +++++++-- .../Recordings/ActiveRecordingsTable.test.tsx | 6 ++-- .../ArchivedRecordingsTable.test.tsx | 29 ++++++++++++++----- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/test/RecordingMetadata/BulkEditLabels.test.tsx b/src/test/RecordingMetadata/BulkEditLabels.test.tsx index 69d73eb08..cec202ce1 100644 --- a/src/test/RecordingMetadata/BulkEditLabels.test.tsx +++ b/src/test/RecordingMetadata/BulkEditLabels.test.tsx @@ -78,7 +78,12 @@ const mockActiveLabelsNotification = { target: mockConnectUrl, recordingName: 'someActiveRecording', jvmId: mockJvmId, - metadata: { labels: { someLabel: 'someValue', someNewLabel: 'someNewValue' } }, + metadata: { + labels: [ + { key: 'someLabel', value: 'someValue' }, + { key: 'someNewLabel', value: 'someNewValue' }, + ], + }, }, } as NotificationMessage; @@ -89,7 +94,12 @@ const mockArchivedLabelsNotification = { target: mockConnectUrl, recordingName: 'someArchivedRecording_some_random', jvmId: mockJvmId, - metadata: { labels: { someLabel: 'someValue', someNewLabel: 'someNewValue' } }, + metadata: { + labels: [ + { key: 'someLabel', value: 'someValue' }, + { key: 'someNewLabel', value: 'someNewValue' }, + ], + }, }, } as NotificationMessage; diff --git a/src/test/Recordings/ActiveRecordingsTable.test.tsx b/src/test/Recordings/ActiveRecordingsTable.test.tsx index 865cefc71..1b01ac846 100644 --- a/src/test/Recordings/ActiveRecordingsTable.test.tsx +++ b/src/test/Recordings/ActiveRecordingsTable.test.tsx @@ -69,7 +69,7 @@ const mockLabelsNotification = { target: mockConnectUrl, recordingName: 'someRecording', jvmId: mockJvmId, - metadata: { labels: { someLabel: 'someUpdatedValue' } }, + metadata: { labels: [{ key: 'someLabel', value: 'someUpdatedValue' }] }, }, } as NotificationMessage; const mockStopNotification = { @@ -242,8 +242,8 @@ describe('', () => { expect(state).toBeInTheDocument(); expect(state).toBeVisible(); - Object.keys(mockRecordingLabels).forEach((key) => { - const label = screen.getByText(`${key}: ${mockRecordingLabels[key]}`); + mockRecordingLabels.forEach((entry) => { + const label = screen.getByText(`${entry.key}: ${entry.value}`); expect(label).toBeInTheDocument(); expect(label).toBeVisible(); }); diff --git a/src/test/Recordings/ArchivedRecordingsTable.test.tsx b/src/test/Recordings/ArchivedRecordingsTable.test.tsx index b8d028bf9..56dc27a9c 100644 --- a/src/test/Recordings/ArchivedRecordingsTable.test.tsx +++ b/src/test/Recordings/ArchivedRecordingsTable.test.tsx @@ -21,7 +21,13 @@ import { TargetRecordingFilters, } from '@app/Shared/Redux/Filters/RecordingFilterSlice'; import { RootState } from '@app/Shared/Redux/ReduxStore'; -import { UPLOADS_SUBDIRECTORY, ArchivedRecording, NotificationMessage, Target } from '@app/Shared/Services/api.types'; +import { + UPLOADS_SUBDIRECTORY, + ArchivedRecording, + NotificationMessage, + Target, + KeyValue, +} from '@app/Shared/Services/api.types'; import { defaultServices } from '@app/Shared/Services/Services'; import { Text } from '@patternfly/react-core'; import '@testing-library/jest-dom'; @@ -57,13 +63,22 @@ const mockUploadedRecordingLabels = [ value: 'someUpdatedValue', }, ]; +export const convertLabels = (kv: KeyValue[]): object => { + const out = {}; + for (let e of kv) { + out[e.key] = e.value; + } + return out; +}; const mockMetadataFileName = 'mock.metadata.json'; const mockMetadataFile = new File( - [JSON.stringify({ labels: { ...mockUploadedRecordingLabels } })], + [JSON.stringify({ labels: convertLabels(mockUploadedRecordingLabels) })], mockMetadataFileName, { type: 'json' }, ); -mockMetadataFile.text = jest.fn(() => Promise.resolve(JSON.stringify({ labels: { ...mockUploadedRecordingLabels } }))); +mockMetadataFile.text = jest.fn(() => + Promise.resolve(JSON.stringify({ labels: convertLabels(mockUploadedRecordingLabels) })), +); const mockRecording: ArchivedRecording = { name: 'someRecording', @@ -91,7 +106,7 @@ const mockLabelsNotification = { target: mockConnectUrl, recordingName: 'someRecording', jvmId: mockJvmId, - metadata: { labels: { someLabel: 'someUpdatedValue' } }, + metadata: { labels: [{ key: 'someLabel', value: 'someUpdatedValue' }] }, }, } as NotificationMessage; const mockDeleteNotification = { @@ -237,8 +252,8 @@ describe('', () => { expect(size).toBeInTheDocument(); expect(size).toBeVisible(); - Object.keys(mockRecordingLabels).forEach((key) => { - const label = screen.getByText(`${key}: ${mockRecordingLabels[key]}`); + mockRecordingLabels.forEach((entry) => { + const label = screen.getByText(`${entry.key}: ${entry.value}`); expect(label).toBeInTheDocument(); expect(label).toBeVisible(); }); @@ -742,7 +757,7 @@ describe('', () => { expect(uploadSpy).toHaveBeenCalled(); expect(uploadSpy).toHaveBeenCalledWith( mockFileUpload, - mockUploadedRecordingLabels, + convertLabels(mockUploadedRecordingLabels), expect.any(Function), expect.any(Subject), );