Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update plugin for Mirador 4 #49

Merged
merged 29 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ccebfb4
Move code from miradorImageToolsPlugin.js to the src/index.js
cbeer Mar 15, 2024
6b9dfba
Pass width down to the individual image tools
cbeer Mar 15, 2024
a233a50
Replace enzyme with react-testing-library
cbeer Mar 15, 2024
15e46ce
Use alpha instead of fade
cbeer Mar 15, 2024
1e035f0
Import the upstream babel configuration
cbeer Mar 15, 2024
8e4e9da
Replace nwb with webpack v5 directly
cbeer Mar 15, 2024
c64aee5
Update to Mirador 4 dependencies
cbeer Mar 15, 2024
a8edb1f
tell jest to ignore react-dnd dependencies
cbeer Mar 15, 2024
4bcd720
Run the MUI v5.0.0/preset-safe codemods
cbeer Mar 15, 2024
beb7e54
Don't use adaptV4Theme; upstream is using MUI5 now
cbeer Mar 15, 2024
b7e3497
Add the sizeMe placeholder for jest testing
cbeer Mar 15, 2024
c317dba
Update redux-thunk import
cbeer Mar 15, 2024
2602654
Update testing-library/react dependency
cbeer Mar 15, 2024
afc3738
Use the connected MiradorMenuButton so we don't need to pass containe…
cbeer Mar 15, 2024
bd8c03a
Update eslint
cbeer Mar 15, 2024
b077630
Handle responsive design using a placeholder container (and it's resp…
cbeer Mar 15, 2024
8d88064
Switch from mui/styles to emotion
cbeer Mar 15, 2024
6e4ef5e
Add steps to build es + cjs packages
cbeer Mar 15, 2024
8f07271
fix: convert MiradorImageTools to functional component to fix no imag…
Nov 25, 2024
00fe996
chore: bump version of mirador to alpha4
Nov 28, 2024
2a873fd
chore: remove react-sizeme leftovers and fix test
Nov 28, 2024
e709c82
refactor: alpha ordering of MiradorImageTools Props
Dec 3, 2024
2e41941
Merge pull request #52 from fstoe/mirador4-compat-clean
lutzhelm Dec 4, 2024
ff22ba6
Update Node.js version for CI
lutzhelm Dec 4, 2024
67acfd6
Update Github actions
lutzhelm Dec 4, 2024
49e8a28
Update CI, remove global codecov install
lutzhelm Dec 5, 2024
9fa41ca
Merge pull request #53 from ProjectMirador/update-nodeversion-for-ci
cbeer Dec 5, 2024
4dc61d6
USe mirador-4.0.0-alpha.5, remove es paths, withSize, withRef
lutzhelm Dec 16, 2024
f3dd01d
Merge pull request #55 from ProjectMirador/m4-alpha5
cbeer Dec 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
"globals": {
"document": true
},
"parser": "babel-eslint",
"plugins": ["babel", "jest"],
"parser": "@babel/eslint-parser",
"plugins": ["babel", "jest", "react", "react-hooks"],
"rules": {
"import/prefer-default-export": "off",
"import/no-extraneous-dependencies": "off",
"no-console": "off",
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"react/jsx-fragments": "off",
"react/jsx-props-no-spreading": "off",
"react/prefer-stateless-function": "off"
"react/prefer-stateless-function": "off",
"react/function-component-definition": "off"
}
}
16 changes: 10 additions & 6 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js 14.x
uses: actions/setup-node@v1
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: 14.x
- run: npm install -g codecov
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
- run: codecov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4

36 changes: 22 additions & 14 deletions __tests__/MiradorImageTools.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import React from 'react';
import { shallow } from 'enzyme';
import { render, screen } from './test-utils';
import { TestableImageTools as MiradorImageTools } from '../src/plugins/MiradorImageTools';
import ImageTool from '../src/plugins/ImageTool';
import ImageRotation from '../src/plugins/ImageRotation';
import ImageFlip from '../src/plugins/ImageFlip';

const mockPalette = {
palette: {
Expand All @@ -12,8 +9,12 @@ const mockPalette = {
},
};

jest.mock('@custom-react-hooks/use-element-size', () => ({
useElementSize: () => ([undefined, { width: 100, height: 200 }]),
}));

function createWrapper(props) {
return shallow(
return render(
<MiradorImageTools
classes={{}}
viewer={{}}
Expand All @@ -22,24 +23,31 @@ function createWrapper(props) {
windowId="x"
width="sm"
theme={mockPalette}
t={() => {}}
t={(k) => k}
{...props}
/>,
);
}

describe('MiradorImageTools', () => {
let wrapper;
it('renders ImageTools', () => {
wrapper = createWrapper();
expect(wrapper.find(ImageTool).length).toBe(5);
it('renders buttons', async () => {
createWrapper();

expect(screen.getByRole('button', { name: 'brightness' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'contrast' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'saturation' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'greyscale' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'invert' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'revert' })).toBeInTheDocument();
});
it('renders ImageRotation', () => {
wrapper = createWrapper();
expect(wrapper.find(ImageRotation).length).toBe(2);
createWrapper();

expect(screen.getByRole('button', { name: 'rotateLeft' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'rotateRight' })).toBeInTheDocument();
});
it('renders ImageFlip', () => {
wrapper = createWrapper();
expect(wrapper.find(ImageFlip).length).toBe(1);
createWrapper();
expect(screen.getByRole('button', { name: 'flip' })).toBeInTheDocument();
});
});
54 changes: 54 additions & 0 deletions __tests__/test-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
import { Provider } from 'react-redux';
import { render } from '@testing-library/react';
import PropTypes from 'prop-types';
import { createStore, applyMiddleware } from 'redux';
import { thunk } from 'redux-thunk';
import { createTheme, ThemeProvider, StyledEngineProvider } from '@mui/material/styles';
import { rootReducer as createRootReducer, settings } from 'mirador';

const rootReducer = createRootReducer();
const theme = createTheme(settings.theme);

/**
* Hook up our rendered object to redux
*/
function renderWithProviders(
ui,
{
preloadedState = {},
// Automatically create a store instance if no store was passed in
store = createStore(rootReducer, preloadedState, applyMiddleware(thunk)),
...renderOptions
} = {},
) {
/** :nodoc: */
function Wrapper({ children }) {
return (
<StyledEngineProvider injectFirst>
<ThemeProvider theme={theme}>
<Provider store={store}>{children}</Provider>
</ThemeProvider>
</StyledEngineProvider>
);
}

Wrapper.propTypes = {
children: PropTypes.node.isRequired,
};

const rendered = render(ui, { wrapper: Wrapper, ...renderOptions });

// Return an object with the store and all of RTL's query functions
return {
store,
...rendered,
rerender: (newUi, options) => render(
newUi,
{ container: rendered.container, wrapper: Wrapper, ...options },
),
};
}

export * from '@testing-library/react';
export { renderWithProviders as render };
90 changes: 85 additions & 5 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,93 @@
module.exports = {
const moduleFormatMap = {
cjs: 'commonjs',
es: false,
};

module.exports = (api) => ({
presets: [
[
api.env('test') && [
'@babel/preset-env',
{
modules: 'commonjs',
targets: {
node: 'current',
},
},
],
'@babel/preset-react',
],
};
(api.env('production') || api.env('development')) && [
'@babel/preset-env',
{
corejs: 3,
exclude: ['transform-typeof-symbol'],
forceAllTransforms: true,
modules: moduleFormatMap[process.env.MODULE_FORMAT] || false,
useBuiltIns: 'entry',
},
],
[
'@babel/preset-react',
{
development: api.env('development') || api.env('test'),
runtime: 'automatic',
useBuiltIns: true,
},
],
].filter(Boolean),
plugins: [
'babel-plugin-macros',
'@babel/plugin-transform-destructuring',
[
'@babel/plugin-proposal-class-properties',
{
loose: true,
},
],
['@babel/plugin-proposal-private-property-in-object', { loose: true }],
['@babel/plugin-proposal-private-methods', { loose: true }],
[
'@babel/plugin-proposal-object-rest-spread',
{
useBuiltIns: true,
},
],
[
'@babel/plugin-transform-runtime',
{
corejs: false,
helpers: false, // Needed to support IE/Edge
regenerator: true,
},
],
[
'@babel/plugin-transform-regenerator',
{
async: false,
},
],
['transform-react-remove-prop-types',
{
ignoreFilenames: ['node_modules'],
removeImport: true,
},
],
[
"@emotion",
{
importMap: {
"@mui/system": {
styled: {
canonicalImport: ["@emotion/styled", "default"],
styledBaseImport: ["@mui/system", "styled"]
}
},
"@mui/material/styles": {
styled: {
canonicalImport: ["@emotion/styled", "default"],
styledBaseImport: ["@mui/material/styles", "styled"]
}
}
}
}
]
].filter(Boolean)
});
14 changes: 14 additions & 0 deletions demo/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
</head>

<body>
<div id="demo"></div>
</body>

</html>
2 changes: 1 addition & 1 deletion demo/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Mirador from 'mirador/dist/es/src/index';
import Mirador from 'mirador';
import { miradorImageToolsPlugin } from '../../src';

const config = {
Expand Down
8 changes: 6 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ module.exports = {

// The directory where Jest should output its coverage files
coverageDirectory: 'coverage',
setupFiles: [
setupFilesAfterEnv: [
'<rootDir>/setupJest.js',
],
// Ignore Mirador code from jest transforms
transformIgnorePatterns: [
'<rootDir>/node_modules/(?!mirador)',
'<rootDir>/node_modules/(?!mirador|@react-dnd|react-dnd|dnd-core|react-dnd-html5-backend|dnd-multi-backend|rdndmb-html5-to-touch)',
],
testEnvironment: "jsdom",
testPathIgnorePatterns: [
"<rootDir>/__tests__/test-utils.js",
],
};
23 changes: 0 additions & 23 deletions nwb.config.js

This file was deleted.

Loading
Loading