Skip to content

Commit

Permalink
feat: add immediately property
Browse files Browse the repository at this point in the history
  • Loading branch information
nakamura196 committed Jun 26, 2024
1 parent 4313723 commit 8258314
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 158 deletions.
44 changes: 21 additions & 23 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Node.js CI

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

# Sets the GITHUB_TOKEN permissions to allow deployment to GitHub Pages
permissions:
Expand All @@ -17,7 +17,7 @@ permissions:

# Allow one concurrent deployment
concurrency:
group: 'pages'
group: "pages"
cancel-in-progress: true

jobs:
Expand All @@ -29,23 +29,21 @@ jobs:
url: ${{ steps.deployment.outputs.page_url }}

steps:
- uses: actions/checkout@v3
- name: Use Node.js 16.8.x
uses: actions/setup-node@v3
with:
node-version: 16.8.x
- run: npm install -g codecov
- run: npm install
- run: npm test
- run: codecov
- run: npm run build
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
# Upload dist repository
path: './demo/dist'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
- run: npm install -g codecov
- run: npm install
- run: npm test
- run: codecov
- run: npm run build:demo
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload dist repository
path: "./demo/dist"
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
47 changes: 21 additions & 26 deletions __tests__/MiradorRotation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,47 @@ import MiradorRotationMenuItem from '../src/plugins/MiradorRotationMenuItem';

describe('MiradorRotationMenuItem', () => {
const mockUpdateWindow = jest.fn();
const mockHandleClose = jest.fn();
const windowId = 'window-1';
const t = (key) => key; // simplistic translation function for testing

it('should render lock icon when enabled', () => {
render(
<MiradorRotationMenuItem
enabled
t={t}
updateWindow={mockUpdateWindow}
windowId={windowId}
/>,
);

expect(screen.getByRole('button')).toHaveAttribute('aria-label', 'rotation');
expect(screen.getByRole('button')).toContainElement(screen.getByTestId('LockIcon'));
afterEach(() => {
jest.clearAllMocks();
});

it('should render lock open icon when not enabled', () => {
render(
it('should toggle the enabled state on click', () => {
const { rerender } = render(
<MiradorRotationMenuItem
enabled={false}
enabled
handleClose={mockHandleClose}
t={t}
updateWindow={mockUpdateWindow}
windowId={windowId}
/>,
);

expect(screen.getByRole('button')).toHaveAttribute('aria-label', 'enableZoom');
expect(screen.getByRole('button')).toContainElement(screen.getByTestId('LockOpenIcon'));
});
// First click should disable
const menuItem = screen.getByRole('menuitem');
fireEvent.click(menuItem);
expect(mockUpdateWindow).toHaveBeenCalledWith(windowId, { rotationEnabled: false });
expect(mockHandleClose).toHaveBeenCalled();

it('should toggle the enabled state on click', () => {
render(
// Reset mocks to clear call history
jest.clearAllMocks();

// Rerender with new "enabled" state as false
rerender(
<MiradorRotationMenuItem
enabled
enabled={false}
handleClose={mockHandleClose}
t={t}
updateWindow={mockUpdateWindow}
windowId={windowId}
/>,
);

const button = screen.getByRole('button');
fireEvent.click(button);
expect(mockUpdateWindow).toHaveBeenCalledWith(windowId, { rotationEnabled: false });

fireEvent.click(button);
// Second click should enable
fireEvent.click(menuItem);
expect(mockUpdateWindow).toHaveBeenCalledWith(windowId, { rotationEnabled: true });
});
});
4 changes: 2 additions & 2 deletions __tests__/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import PropTypes from 'prop-types';
import { createStore, applyMiddleware } from 'redux';
import { thunk } from 'redux-thunk';
import { createTheme, ThemeProvider, StyledEngineProvider } from '@mui/material/styles';
import createRootReducer from 'mirador/dist/es/src/state/reducers/rootReducer';
import settings from 'mirador/dist/es/src/config/settings';
import createRootReducer from '@nakamura196/mirador/dist/es/src/state/reducers/rootReducer';
import settings from '@nakamura196/mirador/dist/es/src/config/settings';

const rootReducer = createRootReducer();
const theme = createTheme(settings.theme);
Expand Down
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 '@nakamura196/mirador/dist/es/src/index';
import { miradorRotationPlugin } from '../../src';

const config = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-puppeteer": "^9.0.2",
"mirador": "4.0.0-alpha.2",
"@nakamura196/mirador": "4.0.0-alpha.2",
"puppeteer": "^21.11.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
Loading

0 comments on commit 8258314

Please sign in to comment.