-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from SnowdogApps/feature/91
#91 - added shipping methods unit test
- Loading branch information
Showing
5 changed files
with
141 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ cache: | |
- node_modules | ||
script: | ||
- yarn lint | ||
- yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import Vuex from 'vuex' | ||
import { shallowMount, createLocalVue } from '@vue/test-utils' | ||
import ShippingMethods from '../view/frontend/web/js/components/ShippingMethods.vue' | ||
import VeeValidate from 'vee-validate' | ||
|
||
const localVue = createLocalVue() | ||
localVue.use(Vuex) | ||
localVue.use(VeeValidate) | ||
|
||
localVue.filter('currency', function (price) { | ||
const pattern = '$%s' | ||
price = parseFloat(price).toFixed(2) | ||
return pattern.replace('%s', price) | ||
}) | ||
|
||
describe('ShippingMethods.test.js', () => { | ||
let store | ||
let mutations | ||
let wrapper | ||
|
||
const shippingMethod = { | ||
amount: 5, | ||
available: true, | ||
base_amount: 5, | ||
carrier_code: 'flatrate', | ||
carrier_title: 'Flat Rate', | ||
error_message: '', | ||
method_code: 'flatrate', | ||
method_title: 'Fixed', | ||
price_excl_tax: 5, | ||
price_incl_tax: 5 | ||
} | ||
|
||
beforeEach(() => { | ||
mutations = { | ||
setItem: jest.fn() | ||
} | ||
store = new Vuex.Store({ | ||
mutations | ||
}) | ||
|
||
wrapper = shallowMount(ShippingMethods, { | ||
propsData: { | ||
shippingMethods: [ | ||
shippingMethod | ||
] | ||
}, | ||
store, | ||
localVue | ||
}) | ||
}) | ||
|
||
it('commits a setItem when a radiobutton is changed', () => { | ||
wrapper | ||
.find(`[data-testid="method-radiobutton-${shippingMethod.carrier_code}"]`) | ||
.trigger('change') | ||
|
||
expect(mutations.setItem.mock.calls).toHaveLength(1) | ||
expect(mutations.setItem.mock.calls[0][1]).toEqual({ | ||
item: 'selectedShippingMethod', | ||
value: shippingMethod | ||
}) | ||
}) | ||
|
||
it('renders a shipping methods list return from props', () => { | ||
expect(wrapper.contains('[data-testid="shipping-methods')).toBe(true) | ||
}) | ||
|
||
it('has the expected html structure', () => { | ||
expect(wrapper.element).toMatchSnapshot() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ShippingMethods.test.js has the expected html structure 1`] = ` | ||
<div> | ||
<h2> | ||
Shipping methods | ||
</h2> | ||
<div | ||
data-testid="shipping-methods" | ||
> | ||
<div | ||
class="input" | ||
data-testid="shipping-method" | ||
> | ||
<input | ||
data-testid="method-radiobutton-flatrate" | ||
data-vv-as="Shipping method" | ||
id="flatrate" | ||
name="shipping-method" | ||
type="radio" | ||
value="[object Object]" | ||
/> | ||
<label | ||
for="flatrate" | ||
> | ||
<span | ||
class="label__text" | ||
> | ||
Flat Rate - Fixed | ||
</span> | ||
<span | ||
class="label__price" | ||
> | ||
$5.00 | ||
</span> | ||
</label> | ||
</div> | ||
<!----> | ||
</div> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters