Skip to content

Commit

Permalink
Merge branch 'react-18-#1205' into migrate-to-vite-#1379
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvdavies committed Nov 21, 2024
2 parents 5923c81 + d4b02e0 commit 4e7d733
Show file tree
Hide file tree
Showing 16 changed files with 443 additions and 269 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,32 @@ jobs:
run: yarn e2e

docker:
# This job triggers only if all the other jobs succeed. It builds the Docker image and if successful,
# it pushes it to Harbor.
# This job triggers only if all the other jobs succeed. It builds the Docker image to ensure it builds correctly.
needs: [test]
name: Docker
runs-on: ubuntu-20.04
steps:
- name: Checkout repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Login to Harbor
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ${{ secrets.HARBOR_URL }}
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
- name: Extract metadata (tags, labels, annotations) for Docker
id: meta
uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175 # v4.6.0
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
with:
images: ${{ secrets.HARBOR_URL }}/scigateway

- name: Build and push Docker image to Harbor
uses: docker/build-push-action@0a97817b6ade9f46837855d676c4cca3a2471fc9 # v4.2.1
- name: Build Docker image
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
with:
context: .
push: true
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
40 changes: 40 additions & 0 deletions .github/workflows/docker-release-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Docker Release Build
on:
push:
tags: '*'

jobs:
docker:
# This job builds the Docker image and if successful, it pushes it to Harbor.
name: Docker
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Login to Harbor
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ${{ secrets.HARBOR_URL }}
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
with:
images: ${{ secrets.HARBOR_URL }}/scigateway
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=ref,event=tag,pattern={{ref}}
- name: Build and push Docker image to Harbor
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"eslint-config-prettier": "9.1.0",
"eslint-plugin-cypress": "2.15.1",
"eslint-plugin-prettier": "5.1.3",
"express": "4.19.2",
"express": "4.20.0",
"husky": "9.0.6",
"i18next": "23.8.2",
"i18next-browser-languagedetector": "7.2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { act, fireEvent, render, screen } from '@testing-library/react';
import axios from 'axios';
import { createRoot } from 'react-dom/client';
import App, { AppSansHoc } from './App';
import { flushPromises } from './testUtils';
import { RegisterRouteType } from './state/scigateway.types';
import { flushPromises } from './testUtils';

vi.mock('./state/actions/loadMicroFrontends', () => ({
init: vi.fn(() => Promise.resolve()),
Expand Down
105 changes: 85 additions & 20 deletions src/adminPage/adminPage.component.test.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import React from 'react';
import { StyledEngineProvider, ThemeProvider } from '@mui/material';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { createLocation, createMemoryHistory, History } from 'history';
import React from 'react';
import { Provider } from 'react-redux';
import { Router } from 'react-router';
import configureStore from 'redux-mock-store';
import { thunk } from 'redux-thunk';
import TestAuthProvider from '../authentication/testAuthProvider';
import { authState, initialState } from '../state/reducers/scigateway.reducer';
import { StateType } from '../state/state.types';
import { PluginConfig } from '../state/scigateway.types';
import configureStore from 'redux-mock-store';
import AdminPage from './adminPage.component';
import { Provider } from 'react-redux';
import { StateType } from '../state/state.types';
import { buildTheme } from '../theming';
import TestAuthProvider from '../authentication/testAuthProvider';
import { thunk } from 'redux-thunk';
import { Router } from 'react-router';
import { StyledEngineProvider, ThemeProvider } from '@mui/material';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { getPluginRoutes } from './adminPage.component';
import AdminPage, { getAdminPluginRoutes } from './adminPage.component';

describe('Admin page component', () => {
let mockStore;
Expand Down Expand Up @@ -50,9 +49,24 @@ describe('Admin page component', () => {
);
}

afterEach(() => {
vi.clearAllMocks();
});

it('should render maintenance page correctly', () => {
history.replace('/admin/maintenance');
state.scigateway.adminPageDefaultTab = 'download';
state.scigateway.plugins = [
...state.scigateway.plugins,
{
order: 1,
plugin: 'datagateway-download',
link: '/admin/download',
section: 'Admin',
displayName: 'Admin Download',
admin: true,
},
];
history.replace('/admin/maintenance');

render(<AdminPage />, { wrapper: Wrapper });

Expand Down Expand Up @@ -131,9 +145,58 @@ describe('Admin page component', () => {
).toBeInTheDocument();
});

it("falls back to 'maintenance' when adminPageDefaultTab is not provided", () => {
state.scigateway.adminPageDefaultTab = undefined;
history.replace('/admin');

render(<AdminPage />, { wrapper: Wrapper });

// Assert that the `maintenance` tab is selected by default
expect(screen.getByRole('tab', { name: 'Maintenance' })).toHaveAttribute(
'aria-selected',
'true'
);
});

it("falls back to 'maintenance' when on an invalid route", () => {
state.scigateway.plugins = [
{
order: 1,
plugin: 'datagateway-download',
link: '/admin/download',
section: 'Admin',
displayName: 'Admin Download',
admin: true,
},
];
state.scigateway.adminPageDefaultTab = 'maintenance';
history.replace('/admin/test');

render(<AdminPage />, { wrapper: Wrapper });

// Assert that the `maintenance` tab is selected by default
expect(screen.getByRole('tab', { name: 'Maintenance' })).toHaveAttribute(
'aria-selected',
'true'
);
});

it("falls back to 'maintenance' when adminPageDefaultTab doesn't match any key in adminRoutes", () => {
state.scigateway.adminPageDefaultTab = 'nonexistentTab';
history.replace('/admin');

render(<AdminPage />, { wrapper: Wrapper });

// Assert that the `maintenance` tab is selected by default
expect(screen.getByRole('tab', { name: 'Maintenance' })).toHaveAttribute(
'aria-selected',
'true'
);
});

it('should return an empty object when given an empty plugins array', () => {
const plugins = [];
const result = getPluginRoutes(plugins);
const result = getAdminPluginRoutes({ plugins });
expect(result).toEqual({});
});

Expand Down Expand Up @@ -164,9 +227,9 @@ describe('Admin page component', () => {
order: 3,
},
];
const result = getPluginRoutes(plugins, true); // Admin user
const result = getAdminPluginRoutes({ plugins }); // Admin user
expect(result).toEqual({
PluginA: ['/admin/pluginA', '/admin/pluginA2'],
PluginA: { pluginA: '/admin/pluginA', pluginA2: '/admin/pluginA2' },
});
});

Expand All @@ -175,23 +238,25 @@ describe('Admin page component', () => {
{
plugin: 'PluginA',
admin: true,
link: '/admin/pluginA',
link: '/admin/pluginALink',
section: 'A',
displayName: 'A',
order: 1,
},
{
plugin: 'PluginB',
admin: false,
link: '/public/pluginB',
link: '/public/pluginBLink',
section: 'B',
displayName: 'B',
order: 2,
},
];
const result = getPluginRoutes(plugins, false); // Non-admin user
const result = getAdminPluginRoutes({ plugins }); // Non-admin user
expect(result).toEqual({
PluginB: ['/public/pluginB'],
PluginA: {
pluginALink: '/admin/pluginALink',
},
});
});
});
Loading

0 comments on commit 4e7d733

Please sign in to comment.