Skip to content

Commit

Permalink
Merge branch 'develop' into nested-routes-for-manufacturers-#1154
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuadkitenge committed Dec 19, 2024
2 parents 0aebbf1 + 9784bcc commit 555d4fa
Show file tree
Hide file tree
Showing 30 changed files with 2,022 additions and 1,638 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- name: Upload coverage reports to Codecov
if: success()
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4
uses: codecov/codecov-action@1e68e06f1dbfde0e4cefc87efeba9e4643565303 # v5
with:
token: ${{ secrets.CODECOV_TOKEN }}

Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:

- name: Upload Cypress screenshots
if: failure()
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4
with:
name: Inventory management system Screenshots
path: cypress/screenshots
Expand All @@ -74,7 +74,7 @@ jobs:

steps:
- name: Clone api repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
uses: actions/checkout@cbb722410c2e876e24abbe8de2cc27693e501dcb
with:
repository: ral-facilities/inventory-management-system-api
ref: develop
Expand Down Expand Up @@ -146,7 +146,7 @@ jobs:

- name: Upload Cypress screenshots
if: failure()
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4
with:
name: Inventory management system (with api) Screenshots
path: cypress/screenshots
Expand All @@ -170,12 +170,12 @@ jobs:

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
with:
images: ${{ secrets.HARBOR_URL }}/ims

- name: Build and push Docker image to Harbor
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 # v6.10.0
with:
context: .
file: ./Dockerfile.prod
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
with:
images: ${{ secrets.HARBOR_URL }}/ims
tags: |
Expand All @@ -34,7 +34,7 @@ jobs:
latest=false
- name: Build and push Docker image to Harbor
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 # v6.10.0
with:
context: .
file: ./Dockerfile.prod
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Specify a base image
FROM node:20.17.0-alpine3.20@sha256:2d07db07a2df6830718ae2a47db6fedce6745f5bcd174c398f2acdda90a11c03
FROM node:22.12.0-alpine3.20@sha256:96cc8323e25c8cc6ddcb8b965e135cfd57846e8003ec0d7bcec16c5fd5f6d39f

# Set the working directory
WORKDIR /inventory-management-system-run
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Dockerfile to build and serve inventory management system

# Build stage
FROM node:20.17.0-alpine3.20@sha256:2d07db07a2df6830718ae2a47db6fedce6745f5bcd174c398f2acdda90a11c03 as builder
FROM node:22.12.0-alpine3.20@sha256:96cc8323e25c8cc6ddcb8b965e135cfd57846e8003ec0d7bcec16c5fd5f6d39f as builder

WORKDIR /inventory-management-system-build

Expand Down
46 changes: 44 additions & 2 deletions cypress/e2e/with_mock_data/items.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -893,9 +893,51 @@ describe('Items', () => {

cy.findByTestId('galleryLightBox').should('not.exist');
});

it('deletes an image', () => {
cy.findByText('5YUQDDjKpz2z').click();
cy.findByText(
'High-resolution cameras for beam characterization. 1'
).should('exist');

cy.findByText('Gallery').click();

cy.findAllByAltText('test').first().click();
cy.findByTestId('galleryLightBox').within(() => {
cy.findByText('File name: stfc-logo-blue-text.png').should('exist');
cy.findByText('Title: stfc-logo-blue-text').should('exist');
cy.findByText('test').should('exist');

cy.findByAltText('test').should('exist');

cy.findByAltText('test')
.should('have.attr', 'src')
.and(
'include',
'http://localhost:3000/images/stfc-logo-blue-text.png?text=1'
);

cy.findByLabelText('Image Actions').click();
});

cy.findAllByText('Delete').last().click();

cy.startSnoopingBrowserMockedRequest();

cy.findByRole('button', { name: 'Continue' }).click();

cy.findBrowserMockedRequests({
method: 'DELETE',
url: '/images/:id',
}).should((patchRequests) => {
expect(patchRequests.length).equal(1);
const request = patchRequests[0];
expect(request.url.toString()).to.contain('1');
});
});
});

it('delete an item', () => {
it('deletes an item', () => {
cy.findAllByLabelText('Row Actions').first().click();
cy.findByText('Delete').click();

Expand All @@ -915,7 +957,7 @@ describe('Items', () => {
});
});

it('duplicate an item', () => {
it('duplicates an item', () => {
cy.findAllByLabelText('Row Actions').first().click();
cy.findByText('Duplicate').click();

Expand Down
50 changes: 25 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@reduxjs/toolkit": "^2.2.5",
"@tanstack/react-query": "^5.40.0",
"@tanstack/react-query-devtools": "^5.40.0",
"@types/node": "^20.14.0",
"@types/node": "^22.0.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/uuid": "^10.0.0",
Expand All @@ -37,15 +37,15 @@
"loglevel": "^1.9.1",
"lz-string": "^1.5.0",
"material-react-table": "^2.13.0",
"msw": "2.4.11",
"msw": "2.6.9",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-hook-form": "^7.52.0",
"react-redux": "^9.1.2",
"react-router-dom": "^6.23.1",
"single-spa-react": "6.0.2",
"typescript": "^5.4.5",
"uuid": "^10.0.0",
"uuid": "^11.0.0",
"vite": "^5.2.12",
"vite-plugin-css-injected-by-js": "^3.5.2",
"zod": "^3.23.8"
Expand Down Expand Up @@ -78,39 +78,39 @@
],
"packageManager": "[email protected]",
"devDependencies": {
"@babel/eslint-parser": "7.25.8",
"@eslint/compat": "1.2.0",
"@eslint/js": "9.12.0",
"@tanstack/eslint-plugin-query": "5.59.7",
"@babel/eslint-parser": "7.25.9",
"@eslint/compat": "1.2.4",
"@eslint/js": "9.17.0",
"@tanstack/eslint-plugin-query": "5.62.1",
"@testing-library/cypress": "10.0.2",
"@testing-library/dom": "10.4.0",
"@testing-library/jest-dom": "6.5.0",
"@testing-library/react": "16.0.1",
"@testing-library/jest-dom": "6.6.3",
"@testing-library/react": "16.1.0",
"@testing-library/user-event": "14.5.2",
"@types/eslint-plugin-jsx-a11y": "6.9.0",
"@types/eslint-plugin-jsx-a11y": "6.10.0",
"@types/eslint__js": "8.42.3",
"@types/react-router-dom": "5.3.3",
"@vitest/coverage-v8": "2.1.3",
"@vitest/coverage-v8": "2.1.8",
"cross-env": "7.0.3",
"cypress": "13.15.0",
"eslint": "9.12.0",
"cypress": "13.16.1",
"eslint": "9.17.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-cypress": "4.0.0",
"eslint-plugin-jsx-a11y": "6.10.0",
"eslint-plugin-cypress": "4.1.0",
"eslint-plugin-jsx-a11y": "6.10.2",
"eslint-plugin-no-only-tests": "3.3.0",
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-react": "7.37.1",
"eslint-plugin-react-hooks": "5.0.0",
"eslint-plugin-testing-library": "6.4.0",
"express": "4.21.1",
"globals": "15.11.0",
"eslint-plugin-react": "7.37.2",
"eslint-plugin-react-hooks": "5.1.0",
"eslint-plugin-testing-library": "7.1.1",
"express": "4.21.2",
"globals": "15.13.0",
"jsdom": "25.0.1",
"prettier": "3.3.3",
"serve": "14.2.3",
"prettier": "3.4.2",
"serve": "14.2.4",
"serve-static": "1.16.2",
"start-server-and-test": "2.0.8",
"typescript-eslint": "8.10.0",
"vitest": "2.1.3"
"start-server-and-test": "2.0.9",
"typescript-eslint": "8.18.0",
"vitest": "2.1.8"
},
"msw": {
"workerDirectory": "public"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ exports[`Units > renders table correctly 1`] = `
Rows per page
</label>
<div
class="MuiInputBase-root MuiInput-root MuiInputBase-colorPrimary css-1mmm5cp-MuiInputBase-root-MuiInput-root-MuiSelect-root"
class="MuiInputBase-root MuiInput-root MuiInputBase-colorPrimary css-1mmm5cp-MuiInputBase-root-MuiInput-root-MuiSelect-root"
>
<div
aria-controls=":rn:"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ exports[`Usage statuses > renders table correctly 1`] = `
Rows per page
</label>
<div
class="MuiInputBase-root MuiInput-root MuiInputBase-colorPrimary css-1mmm5cp-MuiInputBase-root-MuiInput-root-MuiSelect-root"
class="MuiInputBase-root MuiInput-root MuiInputBase-colorPrimary css-1mmm5cp-MuiInputBase-root-MuiInput-root-MuiSelect-root"
>
<div
aria-controls=":rq:"
Expand Down
1 change: 0 additions & 1 deletion src/api/api.types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ export interface AttachmentPostMetadataResponse
}

// ------------------------------------ IMAGES ------------------------------------------------

export interface ImagePost {
entity_id: string;
file_name: string;
Expand Down
36 changes: 34 additions & 2 deletions src/api/images.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { renderHook, waitFor } from '@testing-library/react';
import ImagesJSON from '../mocks/Images.json';
import { hooksWrapperWithProviders } from '../testUtils';
import { useGetImage, useGetImages } from './images';
import {
CREATED_MODIFIED_TIME_VALUES,
hooksWrapperWithProviders,
} from '../testUtils';
import { APIImage } from './api.types';
import { useDeleteImage, useGetImage, useGetImages } from './images';

describe('images api functions', () => {
afterEach(() => {
Expand Down Expand Up @@ -62,4 +66,32 @@ describe('images api functions', () => {
});
});
});

describe('useDeleteImage', () => {
let mockDataView: APIImage;
beforeEach(() => {
mockDataView = {
id: '1',
file_name: 'Image A',
entity_id: '2',
title: '2',
description: 'a description',
primary: false,
thumbnail_base64: 'base64_thumbnail_test',
...CREATED_MODIFIED_TIME_VALUES,
};
});

it('posts a request to delete a manufacturer and return a successful response', async () => {
const { result } = renderHook(() => useDeleteImage(), {
wrapper: hooksWrapperWithProviders(),
});
expect(result.current.isIdle).toBe(true);
result.current.mutate(mockDataView.id);
await waitFor(() => {
expect(result.current.isSuccess).toBeTruthy();
});
expect(result.current.data).toEqual('');
});
});
});
30 changes: 29 additions & 1 deletion src/api/images.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { useQuery, UseQueryResult } from '@tanstack/react-query';
import {
useMutation,
UseMutationResult,
useQuery,
useQueryClient,
UseQueryResult,
} from '@tanstack/react-query';

import { AxiosError } from 'axios';
import { storageApi } from './api';
import { APIImage, APIImageWithURL } from './api.types';
Expand Down Expand Up @@ -43,3 +50,24 @@ export const useGetImages = (
enabled: !!entityId,
});
};

const deleteImage = async (id: string): Promise<void> => {
return storageApi
.delete(`/images/${id}`, {})
.then((response) => response.data);
};

export const useDeleteImage = (): UseMutationResult<
void,
AxiosError,
string
> => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (id: string) => deleteImage(id),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: [`Images`] });
queryClient.removeQueries({ queryKey: [`Image`] });
},
});
};
31 changes: 31 additions & 0 deletions src/catalogue/category/catalogueCardView.component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,35 @@ describe('CardView', () => {

expect(clearFiltersButton).toBeDisabled();
});

it('renders the multi-select filter mode dropdown correctly', async () => {
createView();

await user.click(screen.getByText('Show Filters'));

const dropdownButtons = await screen.findAllByTestId('FilterListIcon');

expect(dropdownButtons[3]).toBeInTheDocument();

await user.click(dropdownButtons[3]);

const includeAnyText = await screen.findByRole('menuitem', {
name: 'Includes any',
});
const excludeAnyText = await screen.findByRole('menuitem', {
name: 'Excludes any',
});

const includeAllText = await screen.findByRole('menuitem', {
name: 'Includes all',
});
const excludeAllText = await screen.findByRole('menuitem', {
name: 'Excludes all',
});

expect(includeAnyText).toBeInTheDocument();
expect(excludeAnyText).toBeInTheDocument();
expect(includeAllText).toBeInTheDocument();
expect(excludeAllText).toBeInTheDocument();
});
});
Loading

0 comments on commit 555d4fa

Please sign in to comment.