Commit f0a50b55 authored by Rajat Jain's avatar Rajat Jain

FE review fixes

FE review fixes
parent e4752bdf
...@@ -59,7 +59,6 @@ describe('EpicToken', () => { ...@@ -59,7 +59,6 @@ describe('EpicToken', () => {
describe('computed', () => { describe('computed', () => {
beforeEach(async () => { beforeEach(async () => {
// Milestone title with spaces is always enclosed in quotations by component.
wrapper = createComponent({ wrapper = createComponent({
data: { data: {
epics: mockEpics, epics: mockEpics,
...@@ -70,29 +69,17 @@ describe('EpicToken', () => { ...@@ -70,29 +69,17 @@ describe('EpicToken', () => {
}); });
describe('currentValue', () => { describe('currentValue', () => {
it('returns numeric `iid` when have string as value', async () => { it.each`
wrapper.setProps({ value: { data: `${mockEpics[0].title}::&${mockEpics[0].iid}` } }); data | id
await wrapper.vm.$nextTick(); ${`${mockEpics[0].title }::&${ mockEpics[0].iid}`} | ${mockEpics[0].iid}
${mockEpics[0].iid} | ${mockEpics[0].iid}
expect(wrapper.vm.currentValue).toBe(mockEpics[0].iid); ${'foobar'} | ${'foobar'}
}); `('$data returns $id', async ({ data, id }) => {
wrapper.setProps({ value: { data } });
it('returns numeric `iid` when have numeric string as value', async () => {
wrapper.setProps({
value: { data: `${mockEpics[0].iid}` },
});
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
expect(wrapper.vm.currentValue).toBe(mockEpics[0].iid); expect(wrapper.vm.currentValue).toBe(id);
});
it("returns value when it's not a numeric string", async () => {
wrapper.setProps({
value: { data: `foobar` },
});
await wrapper.vm.$nextTick();
expect(wrapper.vm.currentValue).toBe('foobar');
}); });
}); });
...@@ -101,6 +88,7 @@ describe('EpicToken', () => { ...@@ -101,6 +88,7 @@ describe('EpicToken', () => {
wrapper.setProps({ wrapper.setProps({
value: { data: `${mockEpics[0].iid}` }, value: { data: `${mockEpics[0].iid}` },
}); });
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
expect(wrapper.vm.activeEpic).toEqual(mockEpics[0]); expect(wrapper.vm.activeEpic).toEqual(mockEpics[0]);
...@@ -118,51 +106,52 @@ describe('EpicToken', () => { ...@@ -118,51 +106,52 @@ describe('EpicToken', () => {
expect(wrapper.vm.config.fetchEpics).toHaveBeenCalledWith('foo'); expect(wrapper.vm.config.fetchEpics).toHaveBeenCalledWith('foo');
}); });
it('sets response to `epics` when request is successful', () => { it('sets response to `epics` when request is successful', async () => {
jest.spyOn(wrapper.vm.config, 'fetchEpics').mockResolvedValue({ jest.spyOn(wrapper.vm.config, 'fetchEpics').mockResolvedValue({
data: mockEpics, data: mockEpics,
}); });
wrapper.vm.fetchEpicsBySearchTerm(); wrapper.vm.fetchEpicsBySearchTerm();
return waitForPromises().then(() => { await waitForPromises();
expect(wrapper.vm.epics).toEqual(mockEpics);
}); expect(wrapper.vm.epics).toEqual(mockEpics);
}); });
it('calls `createFlash` with flash error message when request fails', () => { it('calls `createFlash` with flash error message when request fails', async () => {
jest.spyOn(wrapper.vm.config, 'fetchEpics').mockRejectedValue({}); jest.spyOn(wrapper.vm.config, 'fetchEpics').mockRejectedValue({});
wrapper.vm.fetchEpicsBySearchTerm('foo'); wrapper.vm.fetchEpicsBySearchTerm('foo');
return waitForPromises().then(() => { await waitForPromises();
expect(createFlash).toHaveBeenCalledWith({
message: 'There was a problem fetching epics.', expect(createFlash).toHaveBeenCalledWith({
}); message: 'There was a problem fetching epics.',
}); });
}); });
it('sets `loading` to false when request completes', () => { it('sets `loading` to false when request completes', async () => {
jest.spyOn(wrapper.vm.config, 'fetchEpics').mockRejectedValue({}); jest.spyOn(wrapper.vm.config, 'fetchEpics').mockRejectedValue({});
wrapper.vm.fetchEpicsBySearchTerm('foo'); wrapper.vm.fetchEpicsBySearchTerm('foo');
return waitForPromises().then(() => { await waitForPromises();
expect(wrapper.vm.loading).toBe(false);
}); expect(wrapper.vm.loading).toBe(false);
}); });
}); });
describe('fetchSingleEpic', () => { describe('fetchSingleEpic', () => {
it('calls `config.fetchSingleEpic` with provided iid param', () => { it('calls `config.fetchSingleEpic` with provided iid param', async () => {
jest.spyOn(wrapper.vm.config, 'fetchSingleEpic'); jest.spyOn(wrapper.vm.config, 'fetchSingleEpic');
wrapper.vm.fetchSingleEpic(1); wrapper.vm.fetchSingleEpic(1);
expect(wrapper.vm.config.fetchSingleEpic).toHaveBeenCalledWith(1); expect(wrapper.vm.config.fetchSingleEpic).toHaveBeenCalledWith(1);
return waitForPromises().then(() => {
expect(wrapper.vm.epics).toEqual([mockEpics[0]]); await waitForPromises();
});
expect(wrapper.vm.epics).toEqual([mockEpics[0]]);
}); });
}); });
}); });
...@@ -171,7 +160,7 @@ describe('EpicToken', () => { ...@@ -171,7 +160,7 @@ describe('EpicToken', () => {
beforeEach(async () => { beforeEach(async () => {
wrapper = createComponent({ wrapper = createComponent({
value: { data: `${mockEpics[0].iid}` }, value: { data: `${mockEpics[0].iid}` },
data: { milestones: mockEpics }, data: { epics: mockEpics },
}); });
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment