Skip to content
Snippets Groups Projects
Commit 23627841 authored by Bastien DUMONT's avatar Bastien DUMONT :angel:
Browse files

lint(tests): add testing library lint plugin

parent a58550e2
No related branches found
No related tags found
1 merge request!1280lint(tests): add testing library lint plugin
Showing
with 131 additions and 26 deletions
......@@ -83,9 +83,18 @@ module.exports = {
},
{
files: ['**/*.spec.{ts,tsx}'],
extends: ['plugin:jest/recommended'],
extends: ['plugin:jest/recommended', 'plugin:testing-library/react'],
rules: {
'jest/no-mocks-import': 0,
// Act warning -> should be fixed with "@testing-library/dom" v10 -> in another MR
'testing-library/no-unnecessary-act': 0,
// For testing View components which renders other components -> implementation tests ?
'testing-library/no-container': 0,
// Allows checking classes on containers -> could be fixed
'testing-library/no-node-access': 0,
},
},
],
......
......@@ -47,6 +47,6 @@ describe('ActionOnGoing component', () => {
await act(async () => {
await userEvent.click(screen.getByText('action.details'))
})
expect(screen.findByRole('dialog')).toBeTruthy()
expect(screen.getByRole('dialog')).toBeTruthy()
})
})
......@@ -100,8 +100,8 @@ describe('ElecHalfHourMonthlyAnalysis component', () => {
<ElecHalfHourMonthlyAnalysis perfIndicator={mockPerfIndicator} />
</Provider>
)
await waitFor(() =>
screen.getByLabelText('consumption.accessibility.button_previous_value')
await screen.findByLabelText(
'consumption.accessibility.button_previous_value'
)
await act(async () => {
await userEvent.click(
......
......@@ -44,7 +44,7 @@ describe('ChallengeCardUnlocked component', () => {
screen.getByText('challenge.card_unlocked.button_launch')
)
})
expect(screen.queryAllByRole('dialog').length).toBeTruthy()
expect(screen.getByRole('dialog')).toBeInTheDocument()
})
it('should not display ChallengeNoFluidModal and update userChallenge when launching challenge with configured fluid', async () => {
......
......@@ -15,12 +15,10 @@ describe('StepAddress component', () => {
})
describe('should change inputs', () => {
beforeEach(() => {
it('should change address value', async () => {
render(
<StepAddress sgeState={mockSgeState} onChange={mockHandleChange} />
)
})
it('should change address value', async () => {
const input = screen.getByRole('textbox', {
name: 'auth.enedissgegrandlyon.address',
})
......@@ -30,6 +28,9 @@ describe('StepAddress component', () => {
expect(mockHandleChange).toHaveBeenCalledWith('address', 't')
})
it('should change zipCode value', async () => {
render(
<StepAddress sgeState={mockSgeState} onChange={mockHandleChange} />
)
const input = screen.getByRole('spinbutton', {
name: 'auth.enedissgegrandlyon.zipCode',
})
......@@ -40,6 +41,9 @@ describe('StepAddress component', () => {
})
it('should change city value', async () => {
render(
<StepAddress sgeState={mockSgeState} onChange={mockHandleChange} />
)
const input = screen.getByRole('textbox', {
name: 'auth.enedissgegrandlyon.city',
})
......
......@@ -23,7 +23,7 @@ describe('WaterPricing component', () => {
<WaterPricing />
</Provider>
)
userEvent.click(screen.getByRole('button'))
await userEvent.click(screen.getByRole('button'))
expect(await screen.findByRole('dialog')).toBeInTheDocument()
})
})
......@@ -25,7 +25,7 @@ describe('EcogestureInitModal component', () => {
})
it('should not render the modal when open is false', () => {
const { queryByRole } = render(
render(
<Provider store={store}>
<EcogestureInitModal
open={false}
......@@ -34,7 +34,7 @@ describe('EcogestureInitModal component', () => {
/>
</Provider>
)
expect(queryByRole('dialog')).toBeNull()
expect(screen.queryByRole('dialog')).toBeNull()
})
it('should render correctly when open is true', () => {
......
......@@ -20,25 +20,27 @@ describe('EcogestureSelectionDetail component', () => {
})
describe('should click on buttons', () => {
let container: HTMLElement
beforeEach(async () => {
container = render(
it('should toggle more details', async () => {
render(
<EcogestureSelectionDetail
ecogesture={mockedEcogesturesData[0]}
validate={mockValidate}
title={mockedEcogesturesData[0].shortName}
/>
).container
await waitFor(() => null, { container })
})
it('should toggle more details', async () => {
)
await act(async () => {
await userEvent.click(screen.getByText('ecogesture_modal.show_more'))
})
expect(screen.getByText('ecogesture_modal.show_less')).toBeInTheDocument()
})
it('should call validate with objective to true', async () => {
render(
<EcogestureSelectionDetail
ecogesture={mockedEcogesturesData[0]}
validate={mockValidate}
title={mockedEcogesturesData[0].shortName}
/>
)
await act(async () => {
await userEvent.click(
screen.getByText('ecogesture_selection.button_objective')
......@@ -48,6 +50,13 @@ describe('EcogestureSelectionDetail component', () => {
})
it('should call validate with doing to true', async () => {
render(
<EcogestureSelectionDetail
ecogesture={mockedEcogesturesData[0]}
validate={mockValidate}
title={mockedEcogesturesData[0].shortName}
/>
)
await act(async () => {
await userEvent.click(
screen.getByText('ecogesture_selection.button_doing')
......@@ -57,6 +66,13 @@ describe('EcogestureSelectionDetail component', () => {
})
it('should call validate with objective and doing to false', async () => {
render(
<EcogestureSelectionDetail
ecogesture={mockedEcogesturesData[0]}
validate={mockValidate}
title={mockedEcogesturesData[0].shortName}
/>
)
await act(async () => {
await userEvent.click(
screen.getByText('ecogesture_selection.button_skip')
......
......@@ -54,12 +54,12 @@ describe('Header component', () => {
})
it('should not display desktop title text when desktopTitleKey not provided', () => {
const { queryByText } = render(
render(
<Provider store={desktopStore}>
<Header desktopTitleKey="" />
</Provider>
)
expect(queryByText(/.+/)).not.toBeInTheDocument()
expect(screen.queryByText(/.+/)).not.toBeInTheDocument()
})
it('should display title and back button when desktopTitle key provided and displayBackArrow is true', () => {
......
......@@ -62,14 +62,12 @@ describe('WelcomeModal component', () => {
})
describe('should test modal interactivity', () => {
beforeEach(() => {
it('should send mail and update profile when user click on the ok button', async () => {
render(
<Provider store={store}>
<WelcomeModal open={true} />
</Provider>
)
})
it('should send mail and update profile when user click on the ok button', async () => {
await act(async () => {
await userEvent.click(
screen.getByText('onboarding.welcomeModal.button_valid')
......@@ -85,6 +83,11 @@ describe('WelcomeModal component', () => {
})
it('should send mail and update profile when modal is closed by user', async () => {
render(
<Provider store={store}>
<WelcomeModal open={true} />
</Provider>
)
await act(async () => {
await userEvent.click(
screen.getAllByLabelText(
......
......@@ -3211,6 +3211,11 @@
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3"
integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==
 
"@types/json-schema@^7.0.9":
version "7.0.15"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841"
integrity sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==
"@types/lodash@^4.14.149", "@types/lodash@^4.14.170", "@types/lodash@^4.14.175":
version "4.14.182"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.182.tgz#05301a4d5e62963227eaafe0ce04dd77c54ea5c2"
......@@ -3334,6 +3339,11 @@
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.23.0.tgz#0a6655b3e2708eaabca00b7372fafd7a792a7b09"
integrity sha512-YIoDCTH3Af6XM5VuwGG/QL/CJqga1Zm3NkU3HZ4ZHK2fRMPYP1VczsTUqtsf43PH/iJNVlPHAo2oWX7BSdB2Hw==
 
"@types/semver@^7.3.12":
version "7.5.8"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.8.tgz#8268a8c57a3e4abd25c165ecd36237db7948a55e"
integrity sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==
"@types/semver@^7.5.0":
version "7.5.3"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.3.tgz#9a726e116beb26c24f1ccd6850201e1246122e04"
......@@ -3412,6 +3422,14 @@
"@typescript-eslint/visitor-keys" "6.19.1"
debug "^4.3.4"
 
"@typescript-eslint/scope-manager@5.62.0":
version "5.62.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.62.0.tgz#d9457ccc6a0b8d6b37d0eb252a23022478c5460c"
integrity sha512-VXuvVvZeQCQb5Zgf4HAxc04q5j+WrNAtNh9OwCsCgpKqESMTu3tF/jhZ3xG6T4NZwWl65Bg8KuS2uEvhSfLl0w==
dependencies:
"@typescript-eslint/types" "5.62.0"
"@typescript-eslint/visitor-keys" "5.62.0"
"@typescript-eslint/scope-manager@6.19.1":
version "6.19.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-6.19.1.tgz#2f527ee30703a6169a52b31d42a1103d80acd51b"
......@@ -3472,6 +3490,11 @@
debug "^4.3.4"
ts-api-utils "^1.3.0"
 
"@typescript-eslint/types@5.62.0":
version "5.62.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.62.0.tgz#258607e60effa309f067608931c3df6fed41fd2f"
integrity sha512-87NVngcbVXUahrRTqIK27gD2t5Cu1yuCXxbLcFtCzZGlfyVWWh8mLHkoxzjsB6DDNnvdL+fW8MiwPEJyGJQDgQ==
"@typescript-eslint/types@6.19.1":
version "6.19.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.19.1.tgz#2d4c9d492a63ede15e7ba7d129bdf7714b77f771"
......@@ -3497,6 +3520,19 @@
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-8.9.0.tgz#b733af07fb340b32e962c6c63b1062aec2dc0fe6"
integrity sha512-SjgkvdYyt1FAPhU9c6FiYCXrldwYYlIQLkuc+LfAhCna6ggp96ACncdtlbn8FmnG72tUkXclrDExOpEYf1nfJQ==
 
"@typescript-eslint/typescript-estree@5.62.0":
version "5.62.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.62.0.tgz#7d17794b77fabcac615d6a48fb143330d962eb9b"
integrity sha512-CmcQ6uY7b9y694lKdRB8FEel7JbU/40iSAPomu++SjLMntB+2Leay2LO6i8VnJk58MtE9/nQSFIH6jpyRWyYzA==
dependencies:
"@typescript-eslint/types" "5.62.0"
"@typescript-eslint/visitor-keys" "5.62.0"
debug "^4.3.4"
globby "^11.1.0"
is-glob "^4.0.3"
semver "^7.3.7"
tsutils "^3.21.0"
"@typescript-eslint/typescript-estree@6.19.1":
version "6.19.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.19.1.tgz#796d88d88882f12e85bb33d6d82d39e1aea54ed1"
......@@ -3589,6 +3625,20 @@
"@typescript-eslint/types" "8.8.1"
"@typescript-eslint/typescript-estree" "8.8.1"
 
"@typescript-eslint/utils@^5.62.0":
version "5.62.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.62.0.tgz#141e809c71636e4a75daa39faed2fb5f4b10df86"
integrity sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ==
dependencies:
"@eslint-community/eslint-utils" "^4.2.0"
"@types/json-schema" "^7.0.9"
"@types/semver" "^7.3.12"
"@typescript-eslint/scope-manager" "5.62.0"
"@typescript-eslint/types" "5.62.0"
"@typescript-eslint/typescript-estree" "5.62.0"
eslint-scope "^5.1.1"
semver "^7.3.7"
"@typescript-eslint/utils@^6.0.0 || ^7.0.0 || ^8.0.0":
version "8.9.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-8.9.0.tgz#748bbe3ea5bee526d9786d9405cf1b0df081c299"
......@@ -3599,6 +3649,14 @@
"@typescript-eslint/types" "8.9.0"
"@typescript-eslint/typescript-estree" "8.9.0"
 
"@typescript-eslint/visitor-keys@5.62.0":
version "5.62.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.62.0.tgz#2174011917ce582875954ffe2f6912d5931e353e"
integrity sha512-07ny+LHRzQXepkGg6w0mFY41fVUNBrL2Roj/++7V1txKugfjm/Ci/qSND03r2RhlJhJYMcTn9AhhSSqQp0Ysyw==
dependencies:
"@typescript-eslint/types" "5.62.0"
eslint-visitor-keys "^3.3.0"
"@typescript-eslint/visitor-keys@6.19.1":
version "6.19.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.19.1.tgz#2164073ed4fc34a5ff3b5e25bb5a442100454c4c"
......@@ -8437,6 +8495,13 @@ eslint-plugin-react@7.37.1:
string.prototype.matchall "^4.0.11"
string.prototype.repeat "^1.0.0"
 
eslint-plugin-testing-library@^6.4.0:
version "6.4.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-testing-library/-/eslint-plugin-testing-library-6.4.0.tgz#1ba8a7422e3e31cc315a73ff17c34908f56f9838"
integrity sha512-yeWF+YgCgvNyPNI9UKnG0FjeE2sk93N/3lsKqcmR8dSfeXJwFT5irnWo7NjLf152HkRzfoFjh3LsBUrhvFz4eA==
dependencies:
"@typescript-eslint/utils" "^5.62.0"
eslint-plugin-vue@5.2.3:
version "5.2.3"
resolved "https://registry.yarnpkg.com/eslint-plugin-vue/-/eslint-plugin-vue-5.2.3.tgz#3ee7597d823b5478804b2feba9863b1b74273961"
......@@ -16115,7 +16180,7 @@ semver@^7.3.6, semver@^7.5.4:
dependencies:
lru-cache "^6.0.0"
 
semver@^7.6.0, semver@^7.6.3:
semver@^7.3.7, semver@^7.6.0, semver@^7.6.3:
version "7.6.3"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.3.tgz#980f7b5550bc175fb4dc09403085627f9eb33143"
integrity sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==
......@@ -17599,7 +17664,7 @@ ts-pattern@^5.4.0:
resolved "https://registry.yarnpkg.com/ts-pattern/-/ts-pattern-5.4.0.tgz#efbe74d1ffbb63b80298dbc89b6ec442eab095fa"
integrity sha512-hgfOMfjlrARCnYtGD/xEAkFHDXuSyuqjzFSltyQCbN689uNvoQL20TVN2XFcLMjfNuwSsQGU+xtH6MrjIwhwUg==
 
tslib@^1.11.1, tslib@^1.9.0, tslib@^1.9.3:
tslib@^1.11.1, tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3:
version "1.14.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
......@@ -17614,6 +17679,13 @@ tslib@^2.6.2:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.3.tgz#0438f810ad7a9edcde7a241c3d80db693c8cbfe0"
integrity sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==
 
tsutils@^3.21.0:
version "3.21.0"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.21.0.tgz#b48717d394cea6c1e096983eed58e9d61715b623"
integrity sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==
dependencies:
tslib "^1.8.1"
tty-browserify@0.0.0:
version "0.0.0"
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment