From eba1aebf312dccffffaa9fe9c1aa5ff29db32e60 Mon Sep 17 00:00:00 2001 From: Matheus Ferreira Date: Wed, 9 Feb 2022 14:39:04 -0300 Subject: [PATCH 1/7] teste da tela inicial --- src/App.test.js | 8 --- .../LengthCaracters/LengthCaracters.js | 2 +- src/helpers/renderWithRedux.js | 15 ++++++ src/tests/App.test.js | 54 +++++++++++++++++++ 4 files changed, 70 insertions(+), 9 deletions(-) delete mode 100644 src/App.test.js create mode 100644 src/helpers/renderWithRedux.js create mode 100644 src/tests/App.test.js diff --git a/src/App.test.js b/src/App.test.js deleted file mode 100644 index 1f03afe..0000000 --- a/src/App.test.js +++ /dev/null @@ -1,8 +0,0 @@ -import { render, screen } from '@testing-library/react'; -import App from './App'; - -test('renders learn react link', () => { - render(); - const linkElement = screen.getByText(/learn react/i); - expect(linkElement).toBeInTheDocument(); -}); diff --git a/src/components/LengthCaracters/LengthCaracters.js b/src/components/LengthCaracters/LengthCaracters.js index 5b1e6b6..e1fed00 100644 --- a/src/components/LengthCaracters/LengthCaracters.js +++ b/src/components/LengthCaracters/LengthCaracters.js @@ -24,7 +24,7 @@ class LengthCaracters extends Component { const { lengthPassword } = this.state; return ( -
+

{`LENGTH: ${ lengthPassword }`}

4 diff --git a/src/helpers/renderWithRedux.js b/src/helpers/renderWithRedux.js new file mode 100644 index 0000000..641548c --- /dev/null +++ b/src/helpers/renderWithRedux.js @@ -0,0 +1,15 @@ +import React from 'react'; +import { Provider } from 'react-redux'; +import { createStore } from 'redux'; +import { render } from '@testing-library/react'; +import rootReducer from '../redux/reducers'; + +const renderWithRedux = ( + component, + { initialState, store = createStore(rootReducer, initialState) } = {}, +) => ({ + ...render({component}), + store, +}); + +export default renderWithRedux; diff --git a/src/tests/App.test.js b/src/tests/App.test.js new file mode 100644 index 0000000..208b338 --- /dev/null +++ b/src/tests/App.test.js @@ -0,0 +1,54 @@ +import React from 'react'; +import { screen } from '@testing-library/react'; +import App from '../App'; +import renderWithRedux from '../helpers/renderWithRedux'; + +describe('Testa a tela inicial', () => { + it('Verifica se tem um título', () => { + renderWithRedux(); + + const title = screen.getByRole('heading', { level: 1, name: /Password Generator/i }); + + expect(title).toBeInTheDocument(); + }); + + it('Verifica se tem o texto "CLICK GENERATE"', () => { + renderWithRedux(); + + const text = screen.getByText(/CLICK GENERATE/i); + + expect(text).toBeInTheDocument(); + }); + + it('Verifica se existe a opção de escolher o tamanho', () => { + renderWithRedux(); + + const optionLength = screen.getByTestId('option-length'); + + expect(optionLength).toBeInTheDocument(); + }); + + it('Verifica se existe quatro checkbox', () => { + renderWithRedux(); + + const optionUppercase = screen.getByRole('checkbox', { name: /Include Uppercase/i }); + expect(optionUppercase).toBeInTheDocument(); + + const optionLowercase = screen.getByRole('checkbox', { name: /Include Lowercase/i }); + expect(optionLowercase).toBeInTheDocument(); + + const optionNumbers = screen.getByRole('checkbox', { name: /Include Numbers/i }); + expect(optionNumbers).toBeInTheDocument(); + + const optionSymbols = screen.getByRole('checkbox', { name: /Include Symbols/i }); + expect(optionSymbols).toBeInTheDocument(); + }); + + it('Verifica se existe a opção de escolher o tamanho', () => { + renderWithRedux(); + + const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); + + expect(btnGenerate).toBeInTheDocument(); + }); +}); From 333151464e50f5f56c188d7b86d5afa500395f1c Mon Sep 17 00:00:00 2001 From: Matheus Ferreira Date: Wed, 9 Feb 2022 14:54:06 -0300 Subject: [PATCH 2/7] teste dos inputs checkbox --- src/tests/App.test.js | 9 +++++++-- src/tests/BtnGenerate.js | 15 +++++++++++++++ src/tests/Checkbox.test.js | 28 ++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/tests/BtnGenerate.js create mode 100644 src/tests/Checkbox.test.js diff --git a/src/tests/App.test.js b/src/tests/App.test.js index 208b338..6111fe2 100644 --- a/src/tests/App.test.js +++ b/src/tests/App.test.js @@ -28,9 +28,13 @@ describe('Testa a tela inicial', () => { expect(optionLength).toBeInTheDocument(); }); - it('Verifica se existe quatro checkbox', () => { + it('Verifica se existe quatro inputs do tipo checkbox', () => { renderWithRedux(); + const optionsCheckbox = screen.getAllByRole('checkbox'); + const length = 4; + expect(optionsCheckbox).toHaveLength(length); + const optionUppercase = screen.getByRole('checkbox', { name: /Include Uppercase/i }); expect(optionUppercase).toBeInTheDocument(); @@ -44,11 +48,12 @@ describe('Testa a tela inicial', () => { expect(optionSymbols).toBeInTheDocument(); }); - it('Verifica se existe a opção de escolher o tamanho', () => { + it('Verifica se existe um botão', () => { renderWithRedux(); const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); expect(btnGenerate).toBeInTheDocument(); + expect(btnGenerate.disabled).toBeTruthy(); }); }); diff --git a/src/tests/BtnGenerate.js b/src/tests/BtnGenerate.js new file mode 100644 index 0000000..ce76f08 --- /dev/null +++ b/src/tests/BtnGenerate.js @@ -0,0 +1,15 @@ +import React from 'react'; +import { screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import App from '../App'; +import renderWithRedux from '../helpers/renderWithRedux'; + +describe('Testa o botão de gerar senha', () => { + it('Verifica se ele está desabilitado ao renderizar a tela inicial', () => { + renderWithRedux(); + + const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); + + expect(btnGenerate.disabled).toBeTruthy(); + }); +}); diff --git a/src/tests/Checkbox.test.js b/src/tests/Checkbox.test.js new file mode 100644 index 0000000..6c2814b --- /dev/null +++ b/src/tests/Checkbox.test.js @@ -0,0 +1,28 @@ +import React from 'react'; +import { screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import App from '../App'; +import renderWithRedux from '../helpers/renderWithRedux'; + +describe('Testa os Checkbox', () => { + it('Verifica se ao renderizar a tela os checkbox vem desmarcado', () => { + renderWithRedux(); + + const optionsCheckbox = screen.getAllByRole('checkbox'); + optionsCheckbox.forEach((option) => { + expect(option.checked).toBeFalsy(); + }); + }); + + it('Verifica se ao clicar no checkbox ele fica marcado', () => { + renderWithRedux(); + + const optionsCheckbox = screen.getAllByRole('checkbox'); + optionsCheckbox.forEach((option) => { + userEvent.click(option); + expect(option.checked).toBeTruthy(); + userEvent.click(option); + expect(option.checked).toBeFalsy(); + }); + }); +}); From f7700740c26cb7dfa3eb7ad85bcbee6358e38bed Mon Sep 17 00:00:00 2001 From: Matheus Ferreira Date: Wed, 9 Feb 2022 14:59:53 -0300 Subject: [PATCH 3/7] =?UTF-8?q?testes=20do=20bot=C3=A3o=20done?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tests/BtnGenerate.js | 15 --------------- src/tests/BtnGenerate.test.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 15 deletions(-) delete mode 100644 src/tests/BtnGenerate.js create mode 100644 src/tests/BtnGenerate.test.js diff --git a/src/tests/BtnGenerate.js b/src/tests/BtnGenerate.js deleted file mode 100644 index ce76f08..0000000 --- a/src/tests/BtnGenerate.js +++ /dev/null @@ -1,15 +0,0 @@ -import React from 'react'; -import { screen } from '@testing-library/react'; -import userEvent from '@testing-library/user-event'; -import App from '../App'; -import renderWithRedux from '../helpers/renderWithRedux'; - -describe('Testa o botão de gerar senha', () => { - it('Verifica se ele está desabilitado ao renderizar a tela inicial', () => { - renderWithRedux(); - - const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); - - expect(btnGenerate.disabled).toBeTruthy(); - }); -}); diff --git a/src/tests/BtnGenerate.test.js b/src/tests/BtnGenerate.test.js new file mode 100644 index 0000000..95fe58b --- /dev/null +++ b/src/tests/BtnGenerate.test.js @@ -0,0 +1,29 @@ +import React from 'react'; +import { screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import App from '../App'; +import renderWithRedux from '../helpers/renderWithRedux'; + +describe('Testa o botão de gerar senha', () => { + it('Verifica se o botão está desabilitado ao renderizar a tela inicial', () => { + renderWithRedux(); + + const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); + + expect(btnGenerate.disabled).toBeTruthy(); + }); + + it('Verifica se o botão habilita ao clicar nas opções', () => { + renderWithRedux(); + + const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); + + const optionsCheckbox = screen.getAllByRole('checkbox'); + optionsCheckbox.forEach((option) => { + userEvent.click(option); + expect(btnGenerate.disabled).toBeFalsy(); + userEvent.click(option); + expect(btnGenerate.disabled).toBeTruthy(); + }); + }); +}); From 6c167dd58043e86552de0cc7e1a1bba26674e083 Mon Sep 17 00:00:00 2001 From: Matheus Ferreira Date: Wed, 9 Feb 2022 16:00:46 -0300 Subject: [PATCH 4/7] teste dos tamanhos das senhas --- src/components/Main/Main.js | 2 +- src/tests/Password.test.js | 45 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/tests/Password.test.js diff --git a/src/components/Main/Main.js b/src/components/Main/Main.js index 9dda5bd..c1fe350 100644 --- a/src/components/Main/Main.js +++ b/src/components/Main/Main.js @@ -30,7 +30,7 @@ class Main extends Component { > { btnCopy } -

{ password }

+

{ password }

) } diff --git a/src/tests/Password.test.js b/src/tests/Password.test.js new file mode 100644 index 0000000..4d99fb7 --- /dev/null +++ b/src/tests/Password.test.js @@ -0,0 +1,45 @@ +import React from 'react'; +import { screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import App from '../App'; +import renderWithRedux from '../helpers/renderWithRedux'; + +describe('Testa o password', () => { + it('Verifica se a senha é gerada como o tamanho de 17 caracteres', () => { + const length = 17; + renderWithRedux(, { initialState: { lengthPasswordReducer: { + length } } }); + + const optionUppercase = screen.getByRole('checkbox', { name: /Include Uppercase/i }); + userEvent.click(optionUppercase); + const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); + userEvent.click(btnGenerate); + const password = screen.getByTestId('password'); + expect(password.innerHTML).toHaveLength(length); + }); + + it('Verifica se a senha é gerada como o tamanho de 4 caracteres', () => { + const length = 4; + renderWithRedux(); + + const optionUppercase = screen.getByRole('checkbox', { name: /Include Uppercase/i }); + userEvent.click(optionUppercase); + const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); + userEvent.click(btnGenerate); + const password = screen.getByTestId('password'); + expect(password.innerHTML).toHaveLength(length); + }); + + it('Verifica se a senha é gerada como o tamanho de 20 caracteres', () => { + const length = 20; + renderWithRedux(, { initialState: { lengthPasswordReducer: { + length } } }); + + const optionUppercase = screen.getByRole('checkbox', { name: /Include Uppercase/i }); + userEvent.click(optionUppercase); + const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); + userEvent.click(btnGenerate); + const password = screen.getByTestId('password'); + expect(password.innerHTML).toHaveLength(length); + }); +}); From b7b01c1eda7982d2ae196ecbe79a907cdac7e02a Mon Sep 17 00:00:00 2001 From: Matheus Ferreira Date: Wed, 9 Feb 2022 17:00:33 -0300 Subject: [PATCH 5/7] =?UTF-8?q?testes=20se=20a=20senha=20est=C3=A1=20de=20?= =?UTF-8?q?acordo=20com=20cada=20op=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tests/Password.test.js | 69 +++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/src/tests/Password.test.js b/src/tests/Password.test.js index 4d99fb7..dc919a4 100644 --- a/src/tests/Password.test.js +++ b/src/tests/Password.test.js @@ -3,8 +3,9 @@ import { screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import App from '../App'; import renderWithRedux from '../helpers/renderWithRedux'; +import caracters from '../data/caracters'; -describe('Testa o password', () => { +describe('Testa o tamanho da senha', () => { it('Verifica se a senha é gerada como o tamanho de 17 caracteres', () => { const length = 17; renderWithRedux(, { initialState: { lengthPasswordReducer: { @@ -43,3 +44,69 @@ describe('Testa o password', () => { expect(password.innerHTML).toHaveLength(length); }); }); + +describe('Verifica os caracteres da senha', () => { + it('Verifica se todos os caracteres são maiúsculas', () => { + renderWithRedux(); + + const optionUppercase = screen.getByRole('checkbox', { name: /Include Uppercase/i }); + const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); + + userEvent.click(optionUppercase); + userEvent.click(btnGenerate); + + const password = screen.getByTestId('password'); + const composePassword = password.innerHTML.split(''); + const validation = composePassword + .every((character) => character === character.toUpperCase()); + expect(validation).toBeTruthy(); + }); + + it('Verifica se todos os caracteres são minúsculos', () => { + renderWithRedux(); + + const optionLowercase = screen.getByRole('checkbox', { name: /Include Lowercase/i }); + const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); + + userEvent.click(optionLowercase); + userEvent.click(btnGenerate); + + const password = screen.getByTestId('password'); + const composePassword = password.innerHTML.split(''); + const validation = composePassword + .every((character) => character === character.toLowerCase()); + expect(validation).toBeTruthy(); + }); + + it('Verifica se todos os caracteres são números', () => { + renderWithRedux(); + + const optionNumbers = screen.getByRole('checkbox', { name: /Include Numbers/i }); + const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); + + userEvent.click(optionNumbers); + userEvent.click(btnGenerate); + + const password = screen.getByTestId('password'); + const composePassword = password.innerHTML.split(''); + const validation = composePassword + .every((character) => caracters.numbers.includes(character)); + expect(validation).toBeTruthy(); + }); + + it('Verifica se todos os caracteres são símbolos', () => { + renderWithRedux(); + + const optionSymbols = screen.getByRole('checkbox', { name: /Include Symbols/i }); + const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); + + userEvent.click(optionSymbols); + userEvent.click(btnGenerate); + + const password = screen.getByTestId('password'); + const composePassword = password.innerHTML.split(''); + const validation = composePassword + .every((character) => caracters.symbols.includes(character)); + expect(validation).toBeTruthy(); + }); +}); From a19d6ef25c8d6e14428a07a58798bb52ba4ca02c Mon Sep 17 00:00:00 2001 From: Matheus Ferreira Date: Wed, 9 Feb 2022 19:54:35 -0300 Subject: [PATCH 6/7] testes concluidos --- src/data/caracters.js | 4 +- src/helpers/convertSymbols.js | 9 ++ src/tests/LengthPassword.test.js | 45 ++++++++++ ...ord.test.js => PasswordEachOption.test.js} | 68 +++----------- src/tests/PasswordMultipleOptions.test.js | 88 +++++++++++++++++++ 5 files changed, 158 insertions(+), 56 deletions(-) create mode 100644 src/helpers/convertSymbols.js create mode 100644 src/tests/LengthPassword.test.js rename src/tests/{Password.test.js => PasswordEachOption.test.js} (51%) create mode 100644 src/tests/PasswordMultipleOptions.test.js diff --git a/src/data/caracters.js b/src/data/caracters.js index 325aaa7..0c189d5 100644 --- a/src/data/caracters.js +++ b/src/data/caracters.js @@ -4,8 +4,8 @@ const caracters = { uppercase: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'], numbers: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], - symbols: ['>', '<', '@', '?', '/', '+', '-', '!', '#', '$', '%', '¨', '&', '*', - '(', ')', '_', '=', '°', '®', 'ŧ', 'ø', '[', ']', '~', '^', '}', '{', '|', '.', ',', + symbols: ['&', '<', '>', '@', '?', '/', '+', '!', '#', '-', '$', '%', '*', + '(', ')', '_', '=', '[', ']', '~', '^', '}', '{', '|', '.', ',', ':', ';'], }; diff --git a/src/helpers/convertSymbols.js b/src/helpers/convertSymbols.js new file mode 100644 index 0000000..5dfbe0b --- /dev/null +++ b/src/helpers/convertSymbols.js @@ -0,0 +1,9 @@ +const convert = (str) => { + str = str.replaceAll('&', '&'); + str = str.replaceAll('<', '<'); + str = str.replaceAll('>', '>'); + str = str.replaceAll('"', '"'); + return str; +}; + +export default convert; diff --git a/src/tests/LengthPassword.test.js b/src/tests/LengthPassword.test.js new file mode 100644 index 0000000..9734167 --- /dev/null +++ b/src/tests/LengthPassword.test.js @@ -0,0 +1,45 @@ +import React from 'react'; +import { screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import App from '../App'; +import renderWithRedux from '../helpers/renderWithRedux'; + +describe('Testa o tamanho da senha', () => { + it('Verifica se a senha é gerada como o tamanho de 17 caracteres', () => { + const length = 17; + renderWithRedux(, { initialState: { lengthPasswordReducer: { + length } } }); + + const optionUppercase = screen.getByRole('checkbox', { name: /Include Uppercase/i }); + userEvent.click(optionUppercase); + const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); + userEvent.click(btnGenerate); + const password = screen.getByTestId('password'); + expect(password.innerHTML).toHaveLength(length); + }); + + it('Verifica se a senha é gerada como o tamanho de 4 caracteres', () => { + const length = 4; + renderWithRedux(); + + const optionUppercase = screen.getByRole('checkbox', { name: /Include Uppercase/i }); + userEvent.click(optionUppercase); + const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); + userEvent.click(btnGenerate); + const password = screen.getByTestId('password'); + expect(password.innerHTML).toHaveLength(length); + }); + + it('Verifica se a senha é gerada como o tamanho de 20 caracteres', () => { + const length = 20; + renderWithRedux(, { initialState: { lengthPasswordReducer: { + length } } }); + + const optionUppercase = screen.getByRole('checkbox', { name: /Include Uppercase/i }); + userEvent.click(optionUppercase); + const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); + userEvent.click(btnGenerate); + const password = screen.getByTestId('password'); + expect(password.innerHTML).toHaveLength(length); + }); +}); diff --git a/src/tests/Password.test.js b/src/tests/PasswordEachOption.test.js similarity index 51% rename from src/tests/Password.test.js rename to src/tests/PasswordEachOption.test.js index dc919a4..9865a43 100644 --- a/src/tests/Password.test.js +++ b/src/tests/PasswordEachOption.test.js @@ -5,50 +5,12 @@ import App from '../App'; import renderWithRedux from '../helpers/renderWithRedux'; import caracters from '../data/caracters'; -describe('Testa o tamanho da senha', () => { - it('Verifica se a senha é gerada como o tamanho de 17 caracteres', () => { - const length = 17; - renderWithRedux(, { initialState: { lengthPasswordReducer: { - length } } }); - - const optionUppercase = screen.getByRole('checkbox', { name: /Include Uppercase/i }); - userEvent.click(optionUppercase); - const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); - userEvent.click(btnGenerate); - const password = screen.getByTestId('password'); - expect(password.innerHTML).toHaveLength(length); - }); - - it('Verifica se a senha é gerada como o tamanho de 4 caracteres', () => { - const length = 4; +describe('Verifica os caracteres da senha', () => { + beforeEach(() => { renderWithRedux(); - - const optionUppercase = screen.getByRole('checkbox', { name: /Include Uppercase/i }); - userEvent.click(optionUppercase); - const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); - userEvent.click(btnGenerate); - const password = screen.getByTestId('password'); - expect(password.innerHTML).toHaveLength(length); }); - it('Verifica se a senha é gerada como o tamanho de 20 caracteres', () => { - const length = 20; - renderWithRedux(, { initialState: { lengthPasswordReducer: { - length } } }); - - const optionUppercase = screen.getByRole('checkbox', { name: /Include Uppercase/i }); - userEvent.click(optionUppercase); - const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); - userEvent.click(btnGenerate); - const password = screen.getByTestId('password'); - expect(password.innerHTML).toHaveLength(length); - }); -}); - -describe('Verifica os caracteres da senha', () => { it('Verifica se todos os caracteres são maiúsculas', () => { - renderWithRedux(); - const optionUppercase = screen.getByRole('checkbox', { name: /Include Uppercase/i }); const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); @@ -56,15 +18,14 @@ describe('Verifica os caracteres da senha', () => { userEvent.click(btnGenerate); const password = screen.getByTestId('password'); - const composePassword = password.innerHTML.split(''); - const validation = composePassword + const passwordCompose = password.innerHTML.split(''); + const validation = passwordCompose .every((character) => character === character.toUpperCase()); + expect(validation).toBeTruthy(); }); it('Verifica se todos os caracteres são minúsculos', () => { - renderWithRedux(); - const optionLowercase = screen.getByRole('checkbox', { name: /Include Lowercase/i }); const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); @@ -72,15 +33,14 @@ describe('Verifica os caracteres da senha', () => { userEvent.click(btnGenerate); const password = screen.getByTestId('password'); - const composePassword = password.innerHTML.split(''); - const validation = composePassword + const passwordCompose = password.innerHTML.split(''); + const validation = passwordCompose .every((character) => character === character.toLowerCase()); + expect(validation).toBeTruthy(); }); it('Verifica se todos os caracteres são números', () => { - renderWithRedux(); - const optionNumbers = screen.getByRole('checkbox', { name: /Include Numbers/i }); const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); @@ -88,15 +48,14 @@ describe('Verifica os caracteres da senha', () => { userEvent.click(btnGenerate); const password = screen.getByTestId('password'); - const composePassword = password.innerHTML.split(''); - const validation = composePassword + const passwordCompose = password.innerHTML.split(''); + const validation = passwordCompose .every((character) => caracters.numbers.includes(character)); + expect(validation).toBeTruthy(); }); it('Verifica se todos os caracteres são símbolos', () => { - renderWithRedux(); - const optionSymbols = screen.getByRole('checkbox', { name: /Include Symbols/i }); const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); @@ -104,9 +63,10 @@ describe('Verifica os caracteres da senha', () => { userEvent.click(btnGenerate); const password = screen.getByTestId('password'); - const composePassword = password.innerHTML.split(''); - const validation = composePassword + const passwordCompose = password.innerHTML.split(''); + const validation = passwordCompose .every((character) => caracters.symbols.includes(character)); + expect(validation).toBeTruthy(); }); }); diff --git a/src/tests/PasswordMultipleOptions.test.js b/src/tests/PasswordMultipleOptions.test.js new file mode 100644 index 0000000..e20aafc --- /dev/null +++ b/src/tests/PasswordMultipleOptions.test.js @@ -0,0 +1,88 @@ +import React from 'react'; +import { screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import App from '../App'; +import renderWithRedux from '../helpers/renderWithRedux'; +import caracters from '../data/caracters'; +import convert from '../helpers/convertSymbols'; + +describe('Testa se a senha inclui as opções desejadas', () => { + beforeEach(() => { + renderWithRedux(); + }); + + it('Verifica se a senha inclui maiúsculas e minúsculas', () => { + const optionUppercase = screen.getByRole('checkbox', { name: /Include Uppercase/i }); + const optionLowercase = screen.getByRole('checkbox', { name: /Include Lowercase/i }); + const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); + + userEvent.click(optionUppercase); + userEvent.click(optionLowercase); + userEvent.click(btnGenerate); + + const password = screen.getByTestId('password'); + const passwordCompose = password.innerHTML.split(''); + const chosenOptions = passwordCompose + .every((character) => caracters.uppercase.includes(character) + || caracters.lowercase.includes(character)); + + expect(chosenOptions).toBeTruthy(); + + const unchosenOptions = passwordCompose + .every((character) => caracters.numbers.includes(character) + || caracters.symbols.includes(character)); + + expect(unchosenOptions).toBeFalsy(); + }); + + it('Verifica se a senha inclui símbolos e números', () => { + const optionNumbers = screen.getByRole('checkbox', { name: /Include Numbers/i }); + const optionSymbols = screen.getByRole('checkbox', { name: /Include Symbols/i }); + const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); + + userEvent.click(optionNumbers); + userEvent.click(optionSymbols); + userEvent.click(btnGenerate); + + const password = screen.getByTestId('password'); + const passwordConverted = convert(password.innerHTML); + const passwordCompose = passwordConverted.split(''); + + const chosenOptions = passwordCompose + .every((character) => caracters.symbols.includes(character) + || caracters.numbers.includes(character)); + + expect(chosenOptions).toBeTruthy(); + + const unchosenOptions = passwordCompose + .every((character) => caracters.uppercase.includes(character) + || caracters.lowercase.includes(character)); + + expect(unchosenOptions).toBeFalsy(); + }); + + it('Verifica se a senha inclui todas as opções', () => { + const optionUppercase = screen.getByRole('checkbox', { name: /Include Uppercase/i }); + const optionLowercase = screen.getByRole('checkbox', { name: /Include Lowercase/i }); + const optionNumbers = screen.getByRole('checkbox', { name: /Include Numbers/i }); + const optionSymbols = screen.getByRole('checkbox', { name: /Include Symbols/i }); + const btnGenerate = screen.getByRole('button', { name: /GENERATE PASSWORD/i }); + + userEvent.click(optionUppercase); + userEvent.click(optionLowercase); + userEvent.click(optionNumbers); + userEvent.click(optionSymbols); + userEvent.click(btnGenerate); + + const password = screen.getByTestId('password'); + + const { uppercase, lowercase, numbers, symbols } = caracters; + const options = [uppercase, lowercase, numbers, symbols]; + + const validation = options.every((option) => ( + option.some((character) => password.innerHTML.includes(character)) + )); + + expect(validation).toBeTruthy(); + }); +}); From 62a16c36ef4d64defb90cf28fbaedb4c4f1c62f6 Mon Sep 17 00:00:00 2001 From: Matheus Ferreira Date: Wed, 9 Feb 2022 20:12:26 -0300 Subject: [PATCH 7/7] =?UTF-8?q?repassando=20pelo=20c=C3=B3digo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tests/PasswordEachOption.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tests/PasswordEachOption.test.js b/src/tests/PasswordEachOption.test.js index 9865a43..b5ef19e 100644 --- a/src/tests/PasswordEachOption.test.js +++ b/src/tests/PasswordEachOption.test.js @@ -4,6 +4,7 @@ import userEvent from '@testing-library/user-event'; import App from '../App'; import renderWithRedux from '../helpers/renderWithRedux'; import caracters from '../data/caracters'; +import convert from '../helpers/convertSymbols'; describe('Verifica os caracteres da senha', () => { beforeEach(() => { @@ -63,7 +64,8 @@ describe('Verifica os caracteres da senha', () => { userEvent.click(btnGenerate); const password = screen.getByTestId('password'); - const passwordCompose = password.innerHTML.split(''); + const passwordConverted = convert(password.innerHTML); + const passwordCompose = passwordConverted.split(''); const validation = passwordCompose .every((character) => caracters.symbols.includes(character));