Skip to content

Commit

Permalink
correct tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Mar 1, 2024
1 parent a2a8815 commit c6eacbe
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
14 changes: 12 additions & 2 deletions src/test/RecordingMetadata/BulkEditLabels.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/test/Recordings/ActiveRecordingsTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -242,8 +242,8 @@ describe('<ActiveRecordingsTable />', () => {
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();
});
Expand Down
29 changes: 22 additions & 7 deletions src/test/Recordings/ArchivedRecordingsTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -57,13 +63,22 @@ const mockUploadedRecordingLabels = [
value: 'someUpdatedValue',
},
];
export const convertLabels = (kv: KeyValue[]): object => {
const out = {};
for (let e of kv) {

Check failure on line 68 in src/test/Recordings/ArchivedRecordingsTable.test.tsx

View workflow job for this annotation

GitHub Actions / eslint-check (16.x)

'e' is never reassigned. Use 'const' instead

Check failure on line 68 in src/test/Recordings/ArchivedRecordingsTable.test.tsx

View workflow job for this annotation

GitHub Actions / eslint-check (18.x)

'e' is never reassigned. Use 'const' instead
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',
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -237,8 +252,8 @@ describe('<ArchivedRecordingsTable />', () => {
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();
});
Expand Down Expand Up @@ -742,7 +757,7 @@ describe('<ArchivedRecordingsTable />', () => {
expect(uploadSpy).toHaveBeenCalled();
expect(uploadSpy).toHaveBeenCalledWith(
mockFileUpload,
mockUploadedRecordingLabels,
convertLabels(mockUploadedRecordingLabels),
expect.any(Function),
expect.any(Subject),
);
Expand Down

0 comments on commit c6eacbe

Please sign in to comment.