Skip to content

Fixed and added test #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ type CartItemInfo = {
};

const SELECTORS = {
name: './/h2[contains(@class, "name")]',
fullPrice: './/div[contains(@class, "fullprice")]',
quantity: '[data-testid="quantity-current"]',
name: '//h2[@class="cart-item__name"]',
fullPrice: '//div[contains(@class, "fullprice")]',
quantity: '//div[@data-testid="quantity-current"]',


priceForOne: './/div[contains(@class, "price-for-one")]',
priceForOne: '//div[contains(@class, "price")]',

addOneButton: './/button[text()="+"]',
removeOneButton: './/button[text()="-"]',
addOneButton: '//button[text()="+"]',
removeOneButton: '//button[text()="-"]',

deleteItemButton: '[data-testid="delete-btn"]',
deleteItemButton: '//button[@data-testid="delete-btn"]',
};

export class CartItem extends Component {
Expand Down Expand Up @@ -63,6 +64,6 @@ export class CartItem extends Component {
}

public async delete(): Promise<void> {
await this.element.clickByCSS(SELECTORS.deleteItemButton);
await this.element.clickByXpath(SELECTORS.deleteItemButton);
}
}
6 changes: 3 additions & 3 deletions __specs__/modules/components/cartPage/cartPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { CartList } from '@Components/cartPage/cartList/cartList';
import { Container } from '@Core/container';

const SELECTORS = {
addCartItemButton: './/button[contains(text(), "Add Cart item")]',
addCartItemPopup: './/div[@class="modal" and contains(., "Add New Cart Item")]',
addCartItemButton: '//div[@class="cart__bar"]/button',
addCartItemPopup: '//div[@data-testid="form"]/@class',

cartList: './/div[@class="cart__list"]',
cartList: '//div[@class="cart__list"]',
};

export class CartPageContainer extends Container {
Expand Down
2 changes: 1 addition & 1 deletion __specs__/modules/core/doneRequest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseFormData } from '@Utils/parseFormData';
import { MockedRequest, RequestParams } from 'msw';
import type { MockedRequest, RequestParams } from 'msw';

export class DoneRequest {
private readonly req: MockedRequest;
Expand Down
4 changes: 2 additions & 2 deletions __specs__/modules/core/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { waitFor } from '@Utils/waitFor';
import axios, { AxiosResponse } from 'axios';
import { getLogger } from 'log4js';
import { MockedRequest, MockedResponse, rest } from 'msw';
import { ResponseComposition } from 'msw/lib/types/response';
import { restContext } from 'msw/lib/types/rest';
import type { ResponseComposition } from 'msw/lib/types/response';
import type { restContext } from 'msw/lib/types/rest';
import { setupServer } from 'msw/native';

export class Mock {
Expand Down
9 changes: 6 additions & 3 deletions __specs__/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"jest-allure": "^0.1.3",
"jest-date-mock": "^1.0.8",
"jest-summarizing-reporter": "^1.1.4",
"log4js": "^6.4.1",
"log4js": "^6.7.0",
"msw": "^0.20.5",
"numeral": "^2.0.6",
"p-iteration": "^1.1.8",
Expand All @@ -34,6 +34,9 @@
"ts-unused-exports": "^6.2.4",
"typescript": "4.4.2",
"wait-for-expect": "^3.0.2",
"whatwg-fetch": "^3.6.2"
}
"whatwg-fetch": "^3.6.2"
},
"dependencies": {
"axios": "^1.1.3"
}
}
115 changes: 68 additions & 47 deletions __specs__/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,15 @@ atob@^2.1.2:
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==

axios@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.1.3.tgz#8274250dada2edf53814ed7db644b9c2866c1e35"
integrity sha512-00tXVRwKx/FZr/IDVFt4C+f9FYairX517WoGCL6dpOntqLkZofjhu43F/Xl44UOpqa+9sLFDrG/XAnFsUYgkDA==
dependencies:
follow-redirects "^1.15.0"
form-data "^4.0.0"
proxy-from-env "^1.1.0"

babel-jest@^26.6.3:
version "26.6.3"
resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-26.6.3.tgz#d87d25cb0037577a0c89f82e5755c5d293c01056"
Expand Down Expand Up @@ -1389,12 +1398,12 @@ data-urls@^2.0.0:
whatwg-mimetype "^2.3.0"
whatwg-url "^8.0.0"

date-format@^4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/date-format/-/date-format-4.0.3.tgz#f63de5dc08dc02efd8ef32bf2a6918e486f35873"
integrity sha512-7P3FyqDcfeznLZp2b+OMitV9Sz2lUnsT87WaTat9nVwqsBkTzPG3lPLNwW3en6F4pHUiWzr6vb8CLhjdK9bcxQ==
date-format@^4.0.14:
version "4.0.14"
resolved "https://registry.yarnpkg.com/date-format/-/date-format-4.0.14.tgz#7a8e584434fb169a521c8b7aa481f355810d9400"
integrity sha512-39BOQLs9ZjKh0/patS9nrT8wc3ioX3/eA/zgbKNopnF2wCqJEoxywwwElATYvRsXdnOxA/OQeQoFZ3rFjVajhg==

debug@4, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.3:
debug@4, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1:
version "4.3.3"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.3.tgz#04266e0b70a98d4462e6e288e38259213332b664"
integrity sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==
Expand All @@ -1408,6 +1417,13 @@ debug@^2.2.0, debug@^2.3.3, debug@^2.6.9:
dependencies:
ms "2.0.0"

debug@^4.3.4:
version "4.3.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
dependencies:
ms "2.1.2"

decamelize@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
Expand Down Expand Up @@ -1980,10 +1996,15 @@ flatted@^2.0.0:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.2.tgz#4575b21e2bcee7434aa9be662f4b7b5f9c2b5138"
integrity sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==

flatted@^3.2.4:
version "3.2.4"
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.4.tgz#28d9969ea90661b5134259f312ab6aa7929ac5e2"
integrity sha512-8/sOawo8tJ4QOBX8YlQBMxL8+RLZfxMQOif9o0KUKTNTjMYElWPE0r/m5VNFxTRd0NSw8qSy8dajrwX4RYI1Hw==
flatted@^3.2.7:
version "3.2.7"
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.7.tgz#609f39207cb614b89d0765b477cb2d437fbf9787"
integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==

follow-redirects@^1.15.0:
version "1.15.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==

for-in@^1.0.2:
version "1.0.2"
Expand All @@ -1999,22 +2020,22 @@ form-data@^3.0.0:
combined-stream "^1.0.8"
mime-types "^2.1.12"

form-data@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
mime-types "^2.1.12"

fragment-cache@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/fragment-cache/-/fragment-cache-0.2.1.tgz#4290fad27f13e89be7f33799c6bc5a0abfff0d19"
integrity sha1-QpD60n8T6Jvn8zeZxrxaCr//DRk=
dependencies:
map-cache "^0.2.2"

fs-extra@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1"
integrity sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"

fs-extra@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-6.0.1.tgz#8abc128f7946e310135ddc93b98bddb410e7a34b"
Expand All @@ -2024,6 +2045,15 @@ fs-extra@^6.0.1:
jsonfile "^4.0.0"
universalify "^0.1.0"

fs-extra@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0"
integrity sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^4.0.0"
universalify "^0.1.0"

fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
Expand Down Expand Up @@ -3074,15 +3104,6 @@ jsonfile@^4.0.0:
optionalDependencies:
graceful-fs "^4.1.6"

jsonfile@^6.0.1:
version "6.1.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae"
integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==
dependencies:
universalify "^2.0.0"
optionalDependencies:
graceful-fs "^4.1.6"

kind-of@^3.0.2, kind-of@^3.0.3, kind-of@^3.2.0:
version "3.2.2"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64"
Expand Down Expand Up @@ -3173,16 +3194,16 @@ lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.7.0:
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==

log4js@^6.4.1:
version "6.4.1"
resolved "https://registry.yarnpkg.com/log4js/-/log4js-6.4.1.tgz#9d3a8bf2c31c1e213fe3fc398a6053f7a2bc53e8"
integrity sha512-iUiYnXqAmNKiIZ1XSAitQ4TmNs8CdZYTAWINARF3LjnsLN8tY5m0vRwd6uuWj/yNY0YHxeZodnbmxKFUOM2rMg==
log4js@^6.7.0:
version "6.7.0"
resolved "https://registry.yarnpkg.com/log4js/-/log4js-6.7.0.tgz#fff671a74b2f6e956d135c3c756c79072809a23b"
integrity sha512-KA0W9ffgNBLDj6fZCq/lRbgR6ABAodRIDHrZnS48vOtfKa4PzWImb0Md1lmGCdO3n3sbCm/n1/WmrNlZ8kCI3Q==
dependencies:
date-format "^4.0.3"
debug "^4.3.3"
flatted "^3.2.4"
date-format "^4.0.14"
debug "^4.3.4"
flatted "^3.2.7"
rfdc "^1.3.0"
streamroller "^3.0.2"
streamroller "^3.1.3"

lru-cache@^6.0.0:
version "6.0.0"
Expand Down Expand Up @@ -3775,6 +3796,11 @@ prompts@^2.0.1:
kleur "^3.0.3"
sisteransi "^1.0.4"

proxy-from-env@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==

psl@^1.1.33:
version "1.8.0"
resolved "https://registry.yarnpkg.com/psl/-/psl-1.8.0.tgz#9326f8bcfb013adcc005fdff056acce020e51c24"
Expand Down Expand Up @@ -4209,14 +4235,14 @@ statuses@^2.0.0:
resolved "https://registry.yarnpkg.com/statuses/-/statuses-2.0.0.tgz#aa7b107e018eb33e08e8aee2e7337e762dda1028"
integrity sha512-w9jNUUQdpuVoYqXxnyOakhckBbOxRaoYqJscyIBYCS5ixyCnO7nQn7zBZvP9zf5QOPZcz2DLUpE3KsNPbJBOFA==

streamroller@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/streamroller/-/streamroller-3.0.2.tgz#30418d0eee3d6c93ec897f892ed098e3a81e68b7"
integrity sha512-ur6y5S5dopOaRXBuRIZ1u6GC5bcEXHRZKgfBjfCglMhmIf+roVCECjvkEYzNQOXIN2/JPnkMPW/8B3CZoKaEPA==
streamroller@^3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/streamroller/-/streamroller-3.1.3.tgz#d95689a8c29b30d093525d0baffe6616fd62ca7e"
integrity sha512-CphIJyFx2SALGHeINanjFRKQ4l7x2c+rXYJ4BMq0gd+ZK0gi4VT8b+eHe2wi58x4UayBAKx4xtHpXT/ea1cz8w==
dependencies:
date-format "^4.0.3"
debug "^4.1.1"
fs-extra "^10.0.0"
date-format "^4.0.14"
debug "^4.3.4"
fs-extra "^8.1.0"

string-length@^4.0.1:
version "4.0.1"
Expand Down Expand Up @@ -4552,11 +4578,6 @@ universalify@^0.1.0, universalify@^0.1.2:
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66"
integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==

universalify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"
integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==

unset-value@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unset-value/-/unset-value-1.0.0.tgz#8376873f7d2335179ffb1e6fc3a8ed0dfc8ab559"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@types/ramda": "^0.28.13",
"@types/react": "^17.0.6",
"@types/react-dom": "^17.0.5",
"axios": "^0.27.2",
"axios": "^1.1.3",
"final-form": "^4.20.2",
"node-sass": "^6.0.0",
"normalize.css": "^8.0.1",
Expand Down
43 changes: 41 additions & 2 deletions src/component/Form/Form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('form test', () => {
queryByText('This field should be greater then 0')
).toBeInTheDocument();
expect(
queryByText('This field should be greater or equal then 1')
queryByText('This field should be greater or equal then 1 and less then 10')
).toBeInTheDocument();

expect(props.addItem).toBeCalledTimes(0);
Expand All @@ -107,12 +107,51 @@ describe('form test', () => {

//Shouldn't be error
expect(
queryByText('This field should be greater or equal then 1')
queryByText('This field should be greater or equal then 1 and less then 10')
).not.toBeInTheDocument();
expect(
queryByText('This field should be greater then 0')
).not.toBeInTheDocument();

expect(props.addItem).toBeCalledTimes(1);
});

it('test max value validation for price and quantity', () => {
const { getByTestId, getByText, queryByText } = render(<Form {...props} />);

const inputName = getByTestId('input-name');
const inputPrice = getByTestId('input-price');
const inputQuantity = getByTestId('input-quantity');

const button = getByText('Создать');

fireEvent.change(inputName, { target: { value: 'Name new item' } });
fireEvent.change(inputPrice, { target: { value: 0 } });
fireEvent.change(inputQuantity, { target: { value: 0 } });

fireEvent.click(button);

//Should be error min value
expect(
queryByText('This field should be greater then 0')
).toBeInTheDocument();
expect(
queryByText('This field should be greater or equal then 1 and less then 10')
).toBeInTheDocument();

expect(props.addItem).toBeCalledTimes(0);

fireEvent.change(inputPrice, { target: { value: 0.1 } });
fireEvent.change(inputQuantity, { target: { value: 10 } });
fireEvent.click(button);

//Shouldn't be error
expect(
queryByText('This field should be greater or equal then 1 and less then 10')
).toBeInTheDocument();
expect(
queryByText('This field should be greater then 0')
).not.toBeInTheDocument();

});
});
2 changes: 1 addition & 1 deletion src/component/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const Form: React.FC<FormP> = ({ addItem }) => {
if (String(value).trim().length === 0) return 'This field is required';
switch (name) {
case 'quantity':
if (value < 1) return 'This field should be greater or equal then 1';
if (value < 1 || value > 9) return 'This field should be greater or equal then 1 and less then 10';
break;
case 'price':
if (value <= 0) return 'This field should be greater then 0';
Expand Down
7 changes: 7 additions & 0 deletions src/component/QuantitySwitcher/QuantitySwitcher.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,11 @@ describe('quantity switcher', () => {
fireEvent.click(getByText('-'));
expect(props.decrementQuantity).not.toBeCalled();
});

it('plus btn should be disabled if current quantity equal 10', () => {
const { getByText } = render(<QuantitySwitcher {...props} quantity={10} />);
expect(getByText('+')).toBeDisabled();
fireEvent.click(getByText('+'));
expect(props.incrementQuantity).not.toBeCalled();
});
});
1 change: 1 addition & 0 deletions src/component/QuantitySwitcher/QuantitySwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const QuantitySwitcher = ({
type={'button'}
className="quantity-switcher__btn btn btn_small"
onClick={incrementQuantity}
disabled={quantity >= 10}
>
+
</button>
Expand Down
Loading