Skip to content

Commit 0cdfe97

Browse files
committed
test: migrate to IMA Testing Library
1 parent 47c529a commit 0cdfe97

File tree

14 files changed

+312
-447
lines changed

14 files changed

+312
-447
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
.eslintcache
1010
*.tgz
1111
**/.turbo
12+
.swc/
1213
!itl.tgz

jest.config.itl.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const {
2+
setImaTestingLibraryServerConfig,
3+
FALLBACK_APP_MAIN_PATH,
4+
FALLBACK_APPLICATION_FOLDER,
5+
} = require('@ima/testing-library/server');
6+
7+
const base = require('./jest.config.base.js');
8+
9+
setImaTestingLibraryServerConfig({
10+
applicationFolder: FALLBACK_APPLICATION_FOLDER,
11+
});
12+
13+
module.exports = {
14+
...base,
15+
preset: '@ima/testing-library',
16+
moduleNameMapper: {
17+
'app/main': FALLBACK_APP_MAIN_PATH,
18+
},
19+
setupFiles: ['<rootDir>/../../jestSetup.itl.js'],
20+
};
File renamed without changes.

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"devDependencies": {
3333
"@babel/eslint-parser": "^7.21.8",
3434
"@babel/preset-react": "^7.22.3",
35-
"@cfaester/enzyme-adapter-react-18": "^0.7.0",
3635
"@changesets/cli": "^2.26.1",
3736
"@ima/plugin-cli": "^19.1.2",
3837
"@ima/testing-library": "itl.tgz",
@@ -46,8 +45,6 @@
4645
"@types/react-dom": "^18.3.0",
4746
"@typescript-eslint/eslint-plugin": "^5.59.8",
4847
"@typescript-eslint/parser": "^5.59.8",
49-
"enzyme": "3.11.0",
50-
"enzyme-to-json": "^3.6.2",
5148
"eslint": "^8.41.0",
5249
"eslint-config-prettier": "^8.8.0",
5350
"eslint-plugin-import": "^2.27.5",

packages/plugin-atoms/jest.config.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
const {
2-
setImaTestingLibraryServerConfig,
3-
FALLBACK_APP_MAIN_PATH,
4-
FALLBACK_APPLICATION_FOLDER,
5-
} = require('@ima/testing-library/server');
6-
7-
const base = require('../../jest.config.base.js');
8-
9-
setImaTestingLibraryServerConfig({
10-
applicationFolder: FALLBACK_APPLICATION_FOLDER,
11-
});
1+
const itl = require('../../jest.config.itl.js');
122

133
module.exports = {
14-
...base,
15-
preset: '@ima/testing-library',
16-
moduleNameMapper: {
17-
'app/main': FALLBACK_APP_MAIN_PATH,
18-
},
19-
setupFiles: ['./jestSetup.js'],
4+
...itl,
205
};

packages/plugin-atoms/src/__tests__/__snapshots__/mountSpec.js.snap

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/plugin-atoms/src/__tests__/mountSpec.js

Lines changed: 0 additions & 107 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { renderWithContext, waitFor } from '@ima/testing-library';
2+
3+
import { Iframe, Visibility } from '../../main';
4+
5+
describe('Iframe', () => {
6+
it('should render with noscript tag by default', async () => {
7+
const { container } = await renderWithContext(
8+
<Iframe src='example.html' />
9+
);
10+
11+
expect(container.querySelector('noscript')).toBeInTheDocument();
12+
expect(container.firstChild).toMatchSnapshot();
13+
});
14+
15+
it('should render without noscript tag if visible', async () => {
16+
const { app, container } = await renderWithContext(
17+
<Iframe src='example.html' />
18+
);
19+
20+
// Mock getBoundingClientRect to simulate visibility
21+
container.firstChild.getBoundingClientRect = jest.fn(() => ({
22+
width: 100,
23+
height: 100,
24+
top: 0,
25+
left: 0,
26+
bottom: 100,
27+
right: 100,
28+
}));
29+
app.oc.get(Visibility).notify(); // Trigger visibility observer
30+
31+
// The component needs to re-render to remove noscript tag, there is no generic way to wait for it,
32+
// so we need to wait for the noscript tag to disappear
33+
await waitFor(() =>
34+
expect(container.querySelector('noscript')).not.toBeInTheDocument()
35+
);
36+
expect(container.firstChild).toMatchSnapshot();
37+
});
38+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Iframe should render with noscript tag by default 1`] = `
4+
<div
5+
class="atm-iframe atm-overflow atm-placeholder"
6+
style="width: auto; height: auto;"
7+
>
8+
<noscript>
9+
&lt;iframe src="example.html" name="example.html" width="auto" height="auto" class="atm-fill" &gt;&lt;/iframe&gt;
10+
</noscript>
11+
</div>
12+
`;
13+
14+
exports[`Iframe should render without noscript tag if visible 1`] = `
15+
<div
16+
class="atm-iframe atm-overflow"
17+
style="width: auto; height: auto;"
18+
>
19+
<iframe
20+
class="atm-fill"
21+
name="example.html"
22+
src="example.html"
23+
/>
24+
</div>
25+
`;

packages/plugin-select/jest.config.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
const base = require('../../jest.config.base.js');
1+
const itl = require('../../jest.config.itl.js');
22

33
module.exports = {
4-
...base,
5-
testEnvironment: 'jsdom',
6-
setupFiles: ['<rootDir>/jestSetupFile.js'],
7-
snapshotSerializers: [
8-
'<rootDir>/../../node_modules/enzyme-to-json/serializer',
9-
],
4+
...itl,
105
};

packages/plugin-select/jestSetupFile.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)