Skip to content

Commit 25b0330

Browse files
committed
Add new command to mount with store and router
1 parent 777bb6e commit 25b0330

File tree

8 files changed

+97
-130
lines changed

8 files changed

+97
-130
lines changed

cypress.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default defineConfig({
1212
require(`./config/webpack.config.ada.js`) : require(`./config/webpack.config.physics.js`)
1313
},
1414
indexHtmlFile: `cypress/support/component-index-${SITE_STRING}.html`,
15-
supportFile: `cypress/support/component-${SITE_STRING}.ts`,
15+
supportFile: `cypress/support/component-${SITE_STRING}.tsx`,
1616
setupNodeEvents(on, config) {
1717
initPlugin(on, config);
1818
}

cypress/support/commands.ts renamed to cypress/support/commands.tsx

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,43 @@
3636
// }
3737
// }
3838

39-
import "@frsource/cypress-plugin-visual-regression-diff/dist/support";
39+
import {mount, MountOptions} from 'cypress/react';
40+
41+
// Augment the Cypress namespace to include type definitions for
42+
// your custom command.
43+
// Alternatively, can be defined in cypress/support/component.d.ts
44+
// with a <reference path="./component" /> at the top of your spec.
45+
declare global {
46+
// eslint-disable-next-line @typescript-eslint/no-namespace
47+
namespace Cypress {
48+
interface Chainable {
49+
mountWithStoreAndRouter(component: ReactNode, routes: string[], options: MountOptions): Chainable<Element>;
50+
}
51+
}
52+
}
53+
54+
import React, {ReactNode} from "react";
55+
import {Provider} from "react-redux";
56+
import {store} from "../../src/app/state";
57+
import {MemoryRouter} from "react-router";
58+
59+
Cypress.Commands.add('mountWithStoreAndRouter', (component, routes, options) => {
60+
mount(
61+
<Provider store={store}>
62+
<MemoryRouter initialEntries={routes}>
63+
{component}
64+
</MemoryRouter>
65+
</Provider>
66+
, options
67+
);
68+
});
69+
70+
import "@frsource/cypress-plugin-visual-regression-diff/dist/support";
71+
72+
// Skip visual regression tests in interactive mode - the results are not consistent with headless.
73+
// It may be useful to comment this out when debugging tests locally, but don't commit the snapshots.
74+
if (Cypress.config('isInteractive')) {
75+
Cypress.Commands.add('matchImage', () => {
76+
cy.log('Skipping snapshot 👀');
77+
});
78+
}

cypress/support/component-ada.ts

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

cypress/support/component-ada.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// ***********************************************************
2+
// This example support/component-ada.ts is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands';
18+
19+
// Import styles
20+
import '../../src/scss/cs/isaac.scss';
21+
22+
// Start Mock Service Worker - we use this instead of Cypress API mocking
23+
import { worker } from '../../src/mocks/browser';
24+
Cypress.on('test:before:run:async', async () => {
25+
await worker.start();
26+
});

cypress/support/component-phy.ts

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

cypress/support/component-phy.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// ***********************************************************
2+
// This example support/component-ada.ts is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands';
18+
19+
// Import styles
20+
import '../../src/scss/phy/isaac.scss';
21+
22+
// Start Mock Service Worker - we use this instead of Cypress API mocking
23+
import { worker } from '../../src/mocks/browser';
24+
Cypress.on('test:before:run:async', async () => {
25+
await worker.start();
26+
});

src/test/pages/MyAssignments.cy.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,11 @@ import React from "react";
22
import {MyAssignments} from "../../app/components/pages/MyAssignments";
33
import {mockUser} from "../../mocks/data";
44
import {PATHS} from "../../app/services";
5-
import {MemoryRouter} from "react-router";
6-
import {Provider} from "react-redux";
7-
import { store } from "../../app/state";
85

96

107
it('My Assignments should have no visual regressions', () => {
11-
cy.mount(
12-
<Provider store={store}>
13-
<MemoryRouter initialEntries={[PATHS.MY_ASSIGNMENTS]}>
14-
{
15-
// @ts-ignore
16-
<MyAssignments user={mockUser}/>
17-
}
18-
</MemoryRouter>
19-
</Provider>
20-
);
21-
8+
// @ts-ignore
9+
cy.mountWithStoreAndRouter(<MyAssignments user={mockUser}/>, [PATHS.MY_ASSIGNMENTS]);
2210
cy.get('[data-testid="loading"]').should('not.exist');
23-
2411
cy.matchImage();
2512
});

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
},
2727
"include": [
2828
"src",
29-
"node_modules/cypress/types/cypress-global-vars.d.ts"
29+
"node_modules/cypress/types/cypress-global-vars.d.ts",
30+
"cypress"
3031
]
3132
}

0 commit comments

Comments
 (0)