From 0849793f75b8af122ddbd057e3bebc215704853d Mon Sep 17 00:00:00 2001 From: hamza-deriv Date: Fri, 6 Jan 2023 10:06:37 +0800 Subject: [PATCH] Test for PaymentMethods store --- src/__tests__/PaymentMethod.store.test.tsx | 40 ++++++++++++++++------ 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/__tests__/PaymentMethod.store.test.tsx b/src/__tests__/PaymentMethod.store.test.tsx index 0f0006c..f84549e 100644 --- a/src/__tests__/PaymentMethod.store.test.tsx +++ b/src/__tests__/PaymentMethod.store.test.tsx @@ -15,37 +15,57 @@ describe("Store", () => { }); it("Should have loading as false", () => { - expect(store.loading).toBeFalsy(); + const storeLoading = store.loading; + expect(storeLoading).toBeFalsy(); }); it("Should update country list", () => { store.updateCountryList(fake_residence_list.residence_list); - expect(store.countryListStore).toHaveLength( + const countryListStore = store.countryListStore; + expect(countryListStore).toHaveLength( fake_residence_list.residence_list.length ); - expect(store.countryListStore).toEqual(fake_residence_list.residence_list); + expect(countryListStore).toEqual(fake_residence_list.residence_list); }); it("Should update the selected country", () => { - expect(true).toBeFalsy(); + store.updateSelectedCountry(fake_residence_list.residence_list[0]); + const selectedCountry = store.selectedCountry; + expect(selectedCountry).toEqual( + fake_residence_list.residence_list[0] + ); }); it("Should have initial select country value on resetSelectedCountry", () => { - expect(true).toBeFalsy(); + const selectedCountry = store.selectedCountry; + expect(selectedCountry).toEqual(selectedCountryInitValue); }); it("Should update payment methods", () => { - expect(true).toBeFalsy(); + // First check for Empty + expect(store.paymentMethods).toHaveLength(0); + + store.updatePaymentMethods(fake_payment_methods.payment_methods); + expect(store.paymentMethods).toEqual(fake_payment_methods.payment_methods); + // Now Check for Non-empty + expect(store.paymentMethods).toHaveLength(1); }); it("Should clear payment methods on resetPaymentMethods", () => { - expect(true).toBeFalsy(); + store.updatePaymentMethods(fake_payment_methods.payment_methods); + expect(store.paymentMethods).toEqual(fake_payment_methods.payment_methods); + store.resetPaymentMethods(); + expect(store.paymentMethods).toHaveLength(0); }); - it("Should have loading as fulsy by default", () => { - expect(true).toBeFalsy(); + it("Should have loading as falsy by default", () => { + // test case on line 17 and this one are similar? + const storeLoading = store.loading; + expect(storeLoading).toBeFalsy(); }); it("Should have loading as truthy on toggleLoading", () => { - expect(true).toBeFalsy(); + const toggleLoading = store.toggleLoading(); + const storeLoading = store.loading; + expect(storeLoading).toBeTruthy(); }); });