Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit ea1c87e

Browse files
committed
LangPicker spec's. Fix sinon-chai usage.
1 parent 85c4e0f commit ea1c87e

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

test/unit/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import Vue from 'vue';
22
import Vuex from 'vuex';
33
import VueResource from 'vue-resource';
4+
import chai from 'chai';
5+
import sinonChai from 'sinon-chai';
6+
7+
chai.use(sinonChai);
48

59
/* eslint-disable no-extend-native, no-param-reassign, func-names */
610
if (!String.prototype.endsWith) {

test/unit/specs/common/cd-text-direction-wrapper.spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import vueUnitHelper from 'vue-unit-helper';
22
import TextDirectionWrapper from '@/common/cd-text-direction-wrapper';
33

4-
describe.only('Text Direction Wrapper', () => {
4+
describe('Text Direction Wrapper', () => {
55

66
describe('computed.textDirection', () => {
77
context('when chosen language specifies a direction', () => {
@@ -41,5 +41,4 @@ describe.only('Text Direction Wrapper', () => {
4141
});
4242
});
4343
});
44-
4544
});

test/unit/specs/locale/cd-lang-picker.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import vueUnitHelper from 'vue-unit-helper';
22
import LangPicker from '!!vue-loader?inject!@/locale/cd-lang-picker';
3+
import { expect } from 'chai';
34

45
describe('Lang Picker', () => {
56
let CookieMock;
67
let LocaleServiceMock;
78
let MomentMock;
89
let LangPickerWithMocks;
10+
let StoreMock;
911

1012
beforeEach(() => {
1113
CookieMock = {
@@ -23,6 +25,10 @@ describe('Lang Picker', () => {
2325
'./service': LocaleServiceMock,
2426
moment: MomentMock,
2527
});
28+
29+
StoreMock = {
30+
dispatch: sinon.stub(),
31+
};
2632
});
2733

2834
afterEach(() => {
@@ -74,6 +80,7 @@ describe('Lang Picker', () => {
7480
};
7581
LocaleServiceMock.getStrings.withArgs('es_ES').returns(Promise.resolve({ body: stringsMock }));
7682
sinon.stub(vm, 'setMomentLocale');
83+
vm.$store = StoreMock;
7784

7885
// ACT
7986
vm.$watchers.lang('es_ES');
@@ -89,6 +96,7 @@ describe('Lang Picker', () => {
8996
foo: 'foo',
9097
});
9198
expect(vm.$i18n.locale).to.equal('es_ES');
99+
expect(StoreMock.dispatch.calledOnce).to.eq(true);
92100
done();
93101
});
94102
});
@@ -99,6 +107,7 @@ describe('Lang Picker', () => {
99107
it('should recover languages from the API', async () => {
100108
// ARRANGE
101109
const vm = vueUnitHelper(LangPickerWithMocks);
110+
vm.$store = StoreMock;
102111
CookieMock.get.withArgs('NG_TRANSLATE_LANG_KEY').returns('"es_ES"');
103112
vm.getAvailableLanguages = sinon.stub().resolves({ body: ['a'] });
104113
// ACT
@@ -115,16 +124,19 @@ describe('Lang Picker', () => {
115124
CookieMock.get.withArgs('NG_TRANSLATE_LANG_KEY').returns('"es_ES"');
116125
vm.getAvailableLanguages = sinon.stub().resolves({ body: [{ code: 'es_ES' }] });
117126

127+
vm.$store = StoreMock;
118128
// ACT
119129
await vm.$lifecycleMethods.created();
120130

121131
// ASSERT
122132
expect(vm.lang).to.equal('es_ES');
133+
expect(StoreMock.dispatch.calledOnce).to.eq(true);
123134
});
124135

125136
it('should set lang to the browser locale if no cookie, and locale matches an available one', async () => {
126137
// ARRANGE
127138
const vm = vueUnitHelper(LangPickerWithMocks);
139+
vm.$store = StoreMock;
128140
CookieMock.get.withArgs('NG_TRANSLATE_LANG_KEY').returns(undefined);
129141
vm.getAvailableLanguages = sinon.stub().resolves({ body: [{ code: 'it_IT' }] });
130142
Object.defineProperty(window.navigator, 'language', { value: 'it-IT', configurable: true });
@@ -134,11 +146,13 @@ describe('Lang Picker', () => {
134146

135147
// ASSERT
136148
expect(vm.lang).to.equal('it_IT');
149+
expect(StoreMock.dispatch.calledOnce).to.eq(true);
137150
});
138151

139152
it('should set lang to en_US if no cookie and browser locale doesnt match available lang', async () => {
140153
// ARRANGE
141154
const vm = vueUnitHelper(LangPickerWithMocks);
155+
vm.$store = StoreMock;
142156
vm.getAvailableLanguages = sinon.stub().resolves({ body: [{ code: 'en_US' }] });
143157
CookieMock.get.withArgs('NG_TRANSLATE_LANG_KEY').returns(undefined);
144158
Object.defineProperty(window.navigator, 'language', { value: 'zh-CN', configurable: true });
@@ -148,6 +162,7 @@ describe('Lang Picker', () => {
148162

149163
// ASSERT
150164
expect(vm.lang).to.equal('en_US');
165+
expect(StoreMock.dispatch.calledOnce).to.eq(true);
151166
});
152167
});
153168
});

0 commit comments

Comments
 (0)