Skip to content
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

Sergei / Create test for PaymentMethod.store #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
57 changes: 38 additions & 19 deletions src/__tests__/PaymentMethod.store.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { IResidenceItem } from "../Components/types";
// import { screen } from '@testing-library/react';
import { IResidenceItem } from '../Components/types';
import PaymentMethodStore, {
selectedCountryInitValue,
} from "../store/PaymentMethod.store";
import { fake_payment_methods } from "./fakes/payment_methods";
import { fake_residence_list } from "./fakes/residence_list";
} from '../store/PaymentMethod.store';
import { fake_payment_methods } from './fakes/payment_methods';
import { fake_residence_list } from './fakes/residence_list';

describe("Store", () => {
describe('Store', () => {
let store: PaymentMethodStore;
beforeEach(() => {
store = new PaymentMethodStore();
Expand All @@ -14,38 +15,56 @@ describe("Store", () => {
store.clear();
});

it("Should have loading as false", () => {
it('Should have loading as false', () => {
expect(store.loading).toBeFalsy();
});

it("Should update country list", () => {
it('Should update country list', () => {
store.updateCountryList(fake_residence_list.residence_list);
expect(store.countryListStore).toHaveLength(
fake_residence_list.residence_list.length
);
expect(store.countryListStore).toEqual(fake_residence_list.residence_list);
});

it("Should update the selected country", () => {
expect(true).toBeFalsy();
it('Should update the selected country', () => {
store.updateCountryList(fake_residence_list.residence_list);
const selectedCountry = fake_residence_list.residence_list[1];
store.updateSelectedCountry(selectedCountry);
expect(store.selectedCountry).toEqual(selectedCountry);
});

it("Should have initial select country value on resetSelectedCountry", () => {
expect(true).toBeFalsy();
it('Should have initial select country value on resetSelectedCountry', () => {
const initialSelectedCoountry = store.selectedCountry;
store.resetSelectedCountry();
const selectedCountryAfterReset = store.selectedCountry;
expect(initialSelectedCoountry).toEqual(selectedCountryAfterReset);
});

it("Should update payment methods", () => {
expect(true).toBeFalsy();
it('Should update payment methods', () => {
expect(store.paymentMethods.length).toBe(0);
store.updatePaymentMethods(fake_payment_methods.payment_methods);
expect(store.paymentMethods).toHaveLength(
fake_payment_methods.payment_methods.length
);
expect(store.paymentMethods).toEqual(fake_payment_methods.payment_methods);
});

it("Should clear payment methods on resetPaymentMethods", () => {
expect(true).toBeFalsy();
it('Should clear payment methods on resetPaymentMethods', () => {
store.updatePaymentMethods(fake_payment_methods.payment_methods);
expect(store.paymentMethods).toHaveLength(
fake_payment_methods.payment_methods.length
);
store.clear();
expect(store.paymentMethods.length).toBe(0);
});

it("Should have loading as fulsy by default", () => {
expect(true).toBeFalsy();
it('Should have loading as fulsy by default', () => {
expect(store.loading).toBeFalsy();
});
it("Should have loading as truthy on toggleLoading", () => {
expect(true).toBeFalsy();
it('Should have loading as truthy on toggleLoading', () => {
expect(store.loading).toBeFalsy();
store.toggleLoading();
expect(store.loading).toBeTruthy();
});
});