Skip to content

Commit

Permalink
chore: add cypress tests (#1851)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Bouquillon authored Dec 6, 2023
1 parent 8c01037 commit 2728e72
Show file tree
Hide file tree
Showing 20 changed files with 1,403 additions and 37 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/review-auto.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,31 @@ jobs:
name: "🇫🇷 SocialGouv"
uses: socialgouv/workflows/.github/workflows/use-ks-gh-review-auto.yaml@v1
secrets: inherit
e2e:
runs-on: ubuntu-latest
needs: [socialgouv]
name: "Test e2e"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
uses: cypress-io/github-action@v5
with:
# just perform install
runTests: false
- name: Env
id: env
uses: socialgouv/kontinuous/.github/actions/env@v1
- name: Set env
run: |
echo "SITE_URL=https://${{ steps.env.outputs.subdomain }}.dev.fabrique.social.gouv.fr" >> $GITHUB_ENV
echo "$SITE_URL"
- name: Cypress run
uses: cypress-io/github-action@v5
with:
install: false
working-directory: ./packages/app
config: "pageLoadTimeout=100000,baseUrl=${{ env.SITE_URL }}"
wait-on: "${{ env.SITE_URL }}"
34 changes: 34 additions & 0 deletions .github/workflows/review.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,37 @@ jobs:
name: "🇫🇷 SocialGouv"
uses: socialgouv/workflows/.github/workflows/use-ks-gh-review.yaml@v1
secrets: inherit
e2e:
runs-on: ubuntu-latest
needs: [socialgouv]
name: "Test e2e"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
uses: cypress-io/github-action@v5
with:
# just perform install
runTests: false
- name: Env
id: env
uses: socialgouv/kontinuous/.github/actions/env@v1
- name: Set env
run: |
echo "SITE_URL=https://${{ steps.env.outputs.subdomain }}.dev.fabrique.social.gouv.fr" >> $GITHUB_ENV
echo "$SITE_URL"
- name: Cypress run
uses: cypress-io/github-action@v5
with:
install: false
working-directory: ./packages/app
config: "pageLoadTimeout=100000,baseUrl=${{ env.SITE_URL }},viewportWidth=1600,viewportHeight=1400"
wait-on: "${{ env.SITE_URL }}"
- uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-screenshots
path: ./packages/app/cypress/screenshots
if-no-files-found: ignore # 'warn' or 'error' are also available, defaults to `warn`
4 changes: 3 additions & 1 deletion .kontinuous/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
projectName: egapro
ciNamespace: ci-egapro

repositoryName: egapro

dependencies:
fabrique:
import: SocialGouv/kontinuous/plugins/fabrique
extends:
- name: buildkit-service
2 changes: 1 addition & 1 deletion .kontinuous/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ app:
- /api/auth(/|$)(.*)
- /index-egapro/recherche(/|$)(.*)
annotations:
~tpl~nginx.ingress.kubernetes.io/configuration-snippet: *headers
nginx.ingress.kubernetes.io/configuration-snippet: *headers
certSecretName: api-crt
envFrom:
- secretRef:
Expand Down
13 changes: 13 additions & 0 deletions packages/app/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from "cypress";

// eslint-disable-next-line import/no-default-export
export default defineConfig({
defaultCommandTimeout: 30000,
experimentalStudio: true,
e2e: {
baseUrl: "http://localhost:3000",
setupNodeEvents(_on, _config) {
// implement node event listeners here
},
},
});
15 changes: 15 additions & 0 deletions packages/app/cypress/e2e/homepage.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
describe("Homepage", () => {
it("Affiche les informations élémentaires", () => {
cy.visit("/");
cy.contains("Bienvenue sur Egapro");
cy.contains(".fr-btn", "Calculer - Déclarer mon Index");
cy.contains(".fr-btn", "Consulter l'Index");
cy.contains(".fr-btn", "Déclarer mes Écarts");
cy.contains(".fr-btn", "Consulter les Écarts");
cy.contains(".fr-btn", "Se connecter");
});
it("Affiche la popup RGPD", () => {
cy.visit("/");
cy.contains("À propos des cookies");
});
});
585 changes: 585 additions & 0 deletions packages/app/cypress/e2e/test-28.spec.cy.ts

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions packages/app/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
37 changes: 37 additions & 0 deletions packages/app/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
27 changes: 27 additions & 0 deletions packages/app/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import "./commands";

// Alternatively you can use CommonJS syntax:
// require('./commands')

Cypress.on("uncaught:exception", (err, runnable) => {
// returning false here prevents Cypress from
// failing the test
console.log("browser exception: ", err);
return false;
});
1 change: 1 addition & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"@typescript-eslint/parser": "^6.7.2",
"babel-loader": "^9.1.3",
"concurrently": "^8.2.0",
"cypress": "^13.6.0",
"dotenv": "^16.0.1",
"eslint": "^8.50.0",
"eslint-config-next": "^14.0.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/app/src/app/(default)/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export const Navigation = () => {
{
text: "Index",
isActive: segment === "index-egapro",
buttonProps: {
id: "main-navigation-index-link",
},
menuLinks: [
{
text: "À propos de l'index",
Expand All @@ -39,6 +42,7 @@ export const Navigation = () => {
text: "Calculer mon index",
linkProps: {
href: "/index-egapro/simulateur/commencer",
id: "main-navigation-calculate-index-link",
},
isActive: segments.includes("simulateur") && segments.includes("index-egapro"),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export const EffectifsForm = () => {
},
}),
value: workforceRange,
"data-cy": `workforceRange.${workforceRange}`,
},
}))}
/>
Expand Down Expand Up @@ -288,6 +289,7 @@ export const EffectifsForm = () => {
...register(`csp.${category}.ageRanges.${ageRange}.women`, {
setValueAs: setValueAsFloatOrEmptyString,
}),
id: `csp.${category}.ageRanges.${ageRange}.women`,
type: "number",
min: 0,
},
Expand All @@ -300,6 +302,7 @@ export const EffectifsForm = () => {
...register(`csp.${category}.ageRanges.${ageRange}.men`, {
setValueAs: setValueAsFloatOrEmptyString,
}),
id: `csp.${category}.ageRanges.${ageRange}.men`,
type: "number",
min: 0,
},
Expand Down Expand Up @@ -342,6 +345,9 @@ export const EffectifsForm = () => {
href: simulateurPath(effectifsNav.prev()),
},
}}
nextProps={{
id: "simu-workforce-next",
}}
nextDisabled={!isValid || !total}
/>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export const Indic1Form = () => {
nativeInputProps: {
...field,
value: mode,
"data-cy": `mode.${mode}`,
defaultChecked: field.value === mode,
onChange() {
field.onChange(mode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export const OtherModesTable = ({ computer, staff, defaultRemunerations }: Other
stateRelatedMessage={errors.remunerations?.[remunerationsFieldIndex]?.name?.message}
nativeInputProps={{
...register(`remunerations.${remunerationsFieldIndex}.name`),
id: `remunerations.${remunerationsFieldIndex}.name`,
}}
/>
</TooltipWrapper>
Expand All @@ -113,6 +114,7 @@ export const OtherModesTable = ({ computer, staff, defaultRemunerations }: Other
setValueAs: setValueAsFloatOrEmptyString,
deps: `remunerations.${remunerationsFieldIndex}.category.${ageRange}.menCount`,
}),
id: `remunerations.${remunerationsFieldIndex}.category.${ageRange}.womenCount`,
type: "number",
min: 0,
},
Expand All @@ -130,6 +132,7 @@ export const OtherModesTable = ({ computer, staff, defaultRemunerations }: Other
setValueAs: setValueAsFloatOrEmptyString,
deps: `remunerations.${remunerationsFieldIndex}.category.${ageRange}.womenCount`,
}),
id: `remunerations.${remunerationsFieldIndex}.category.${ageRange}.menCount`,
type: "number",
min: 0,
},
Expand Down Expand Up @@ -177,6 +180,7 @@ export const OtherModesTable = ({ computer, staff, defaultRemunerations }: Other
priority="secondary"
iconId="fr-icon-add-line"
className={fr.cx("fr-mb-4w")}
id={`add-hierarchical-level`}
onClick={() => {
appendRemunerations({ name: "", category: {} } as ExternalRemunerations[number], {
shouldFocus: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export const getCommonBodyColumns = ({
setValueAs: setValueAsFloatOrEmptyString,
deps: `remunerations.${categoryIndex}.category.${ageRange}.menSalary`,
}),
id: `remunerations.${categoryIndex}.category.${ageRange}.womenSalary`,
},
},
{
Expand All @@ -127,6 +128,7 @@ export const getCommonBodyColumns = ({
setValueAs: setValueAsFloatOrEmptyString,
deps: `remunerations.${categoryIndex}.category.${ageRange}.womenSalary`,
}),
id: `remunerations.${categoryIndex}.category.${ageRange}.menSalary`,
},
},
(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const CommencerPage = async () => {
nextProps={{
linkProps: {
href: "/index-egapro/simulateur/effectifs",
id: "begin-button",
},
}}
/>
Expand Down
15 changes: 1 addition & 14 deletions packages/app/src/app/AuthHeaderItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const LoginLogoutHeaderItem = () => {
/>
);

case "unauthenticated":
default: // loading
return (
<HeaderQuickAccessItem
key="hqai-unauthenticated-login"
Expand All @@ -79,18 +79,5 @@ export const LoginLogoutHeaderItem = () => {
}}
/>
);
default: // loading
return (
<HeaderQuickAccessItem
key="hqai-authloading-fake-button"
quickAccessItem={{
iconId: "fr-icon-lock-line",
text: <Skeleton width={110} />,
buttonProps: {
className: fr.cx("fr-btn--secondary"),
},
}}
/>
);
}
};
4 changes: 3 additions & 1 deletion packages/app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
".next/types/**/*.ts"
],
"exclude": [
"node_modules"
"node_modules",
"cypress.config.ts",
"cypress"
]
}
Loading

0 comments on commit 2728e72

Please sign in to comment.