Skip to content

Commit

Permalink
test: migrate to IMA Testing Library
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipoliko committed Aug 28, 2024
1 parent 47c529a commit 0cdfe97
Show file tree
Hide file tree
Showing 14 changed files with 312 additions and 447 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
.eslintcache
*.tgz
**/.turbo
.swc/
!itl.tgz
20 changes: 20 additions & 0 deletions jest.config.itl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const {
setImaTestingLibraryServerConfig,
FALLBACK_APP_MAIN_PATH,
FALLBACK_APPLICATION_FOLDER,
} = require('@ima/testing-library/server');

const base = require('./jest.config.base.js');

setImaTestingLibraryServerConfig({
applicationFolder: FALLBACK_APPLICATION_FOLDER,
});

module.exports = {
...base,
preset: '@ima/testing-library',
moduleNameMapper: {
'app/main': FALLBACK_APP_MAIN_PATH,
},
setupFiles: ['<rootDir>/../../jestSetup.itl.js'],
};
File renamed without changes.
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"devDependencies": {
"@babel/eslint-parser": "^7.21.8",
"@babel/preset-react": "^7.22.3",
"@cfaester/enzyme-adapter-react-18": "^0.7.0",
"@changesets/cli": "^2.26.1",
"@ima/plugin-cli": "^19.1.2",
"@ima/testing-library": "itl.tgz",
Expand All @@ -46,8 +45,6 @@
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^5.59.8",
"@typescript-eslint/parser": "^5.59.8",
"enzyme": "3.11.0",
"enzyme-to-json": "^3.6.2",
"eslint": "^8.41.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
Expand Down
19 changes: 2 additions & 17 deletions packages/plugin-atoms/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
const {
setImaTestingLibraryServerConfig,
FALLBACK_APP_MAIN_PATH,
FALLBACK_APPLICATION_FOLDER,
} = require('@ima/testing-library/server');

const base = require('../../jest.config.base.js');

setImaTestingLibraryServerConfig({
applicationFolder: FALLBACK_APPLICATION_FOLDER,
});
const itl = require('../../jest.config.itl.js');

module.exports = {
...base,
preset: '@ima/testing-library',
moduleNameMapper: {
'app/main': FALLBACK_APP_MAIN_PATH,
},
setupFiles: ['./jestSetup.js'],
...itl,
};

This file was deleted.

107 changes: 0 additions & 107 deletions packages/plugin-atoms/src/__tests__/mountSpec.js

This file was deleted.

38 changes: 38 additions & 0 deletions packages/plugin-atoms/src/components/__tests__/IframeSpec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { renderWithContext, waitFor } from '@ima/testing-library';

import { Iframe, Visibility } from '../../main';

describe('Iframe', () => {
it('should render with noscript tag by default', async () => {
const { container } = await renderWithContext(
<Iframe src='example.html' />
);

expect(container.querySelector('noscript')).toBeInTheDocument();
expect(container.firstChild).toMatchSnapshot();
});

it('should render without noscript tag if visible', async () => {
const { app, container } = await renderWithContext(
<Iframe src='example.html' />
);

// Mock getBoundingClientRect to simulate visibility
container.firstChild.getBoundingClientRect = jest.fn(() => ({
width: 100,
height: 100,
top: 0,
left: 0,
bottom: 100,
right: 100,
}));
app.oc.get(Visibility).notify(); // Trigger visibility observer

// The component needs to re-render to remove noscript tag, there is no generic way to wait for it,
// so we need to wait for the noscript tag to disappear
await waitFor(() =>
expect(container.querySelector('noscript')).not.toBeInTheDocument()
);
expect(container.firstChild).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Iframe should render with noscript tag by default 1`] = `
<div
class="atm-iframe atm-overflow atm-placeholder"
style="width: auto; height: auto;"
>
<noscript>
&lt;iframe src="example.html" name="example.html" width="auto" height="auto" class="atm-fill" &gt;&lt;/iframe&gt;
</noscript>
</div>
`;

exports[`Iframe should render without noscript tag if visible 1`] = `
<div
class="atm-iframe atm-overflow"
style="width: auto; height: auto;"
>
<iframe
class="atm-fill"
name="example.html"
src="example.html"
/>
</div>
`;
9 changes: 2 additions & 7 deletions packages/plugin-select/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
const base = require('../../jest.config.base.js');
const itl = require('../../jest.config.itl.js');

module.exports = {
...base,
testEnvironment: 'jsdom',
setupFiles: ['<rootDir>/jestSetupFile.js'],
snapshotSerializers: [
'<rootDir>/../../node_modules/enzyme-to-json/serializer',
],
...itl,
};
11 changes: 0 additions & 11 deletions packages/plugin-select/jestSetupFile.js

This file was deleted.

Loading

0 comments on commit 0cdfe97

Please sign in to comment.