Commit 317c787e authored by Eduardo Mejía's avatar Eduardo Mejía Committed by Clement Ho

add stub to the boardsStore to spy on it and be able to use...

add stub to the boardsStore to spy on it and be able to use toHaveBeenCalledWith for the pre-defined labels test
parent 9578b7e9
<script> <script>
import { __ } from '~/locale'; import { __ } from '~/locale';
/* global ListLabel */ import ListLabel from '~/boards/models/label';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import boardsStore from '../stores/boards_store'; import boardsStore from '../stores/boards_store';
...@@ -30,13 +30,17 @@ export default { ...@@ -30,13 +30,17 @@ export default {
}); });
// Save the labels // Save the labels
gl.boardService boardsStore
.generateDefaultLists() .generateDefaultLists()
.then(res => res.data) .then(res => res.data)
.then(data => { .then(data => {
data.forEach(listObj => { data.forEach(listObj => {
const list = boardsStore.findList('title', listObj.title); const list = boardsStore.findList('title', listObj.title);
if (!list) {
return;
}
list.id = listObj.id; list.id = listObj.id;
list.label.id = listObj.label.id; list.label.id = listObj.label.id;
list.getIssues().catch(() => { list.getIssues().catch(() => {
...@@ -69,8 +73,7 @@ export default { ...@@ -69,8 +73,7 @@ export default {
<span <span
:style="{ backgroundColor: label.color }" :style="{ backgroundColor: label.color }"
class="label-color position-relative d-inline-block rounded" class="label-color position-relative d-inline-block rounded"
> ></span>
</span>
{{ label.title }} {{ label.title }}
</li> </li>
</ul> </ul>
......
---
title: Change BoardService in favor of boardsStore on board blank state of the component
board
merge_request: 30546
author: eduarmreyes
type: other
import Vue from 'vue'; import Vue from 'vue';
import boardsStore from '~/boards/stores/boards_store'; import boardsStore from '~/boards/stores/boards_store';
import BoardBlankState from '~/boards/components/board_blank_state.vue'; import BoardBlankState from '~/boards/components/board_blank_state.vue';
import { mockBoardService } from './mock_data';
describe('Boards blank state', () => { describe('Boards blank state', () => {
let vm; let vm;
...@@ -11,9 +10,10 @@ describe('Boards blank state', () => { ...@@ -11,9 +10,10 @@ describe('Boards blank state', () => {
const Comp = Vue.extend(BoardBlankState); const Comp = Vue.extend(BoardBlankState);
boardsStore.create(); boardsStore.create();
gl.boardService = mockBoardService();
spyOn(gl.boardService, 'generateDefaultLists').and.callFake( spyOn(boardsStore, 'addList').and.stub();
spyOn(boardsStore, 'removeList').and.stub();
spyOn(boardsStore, 'generateDefaultLists').and.callFake(
() => () =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
if (fail) { if (fail) {
...@@ -71,9 +71,14 @@ describe('Boards blank state', () => { ...@@ -71,9 +71,14 @@ describe('Boards blank state', () => {
vm.$el.querySelector('.btn-success').click(); vm.$el.querySelector('.btn-success').click();
setTimeout(() => { setTimeout(() => {
expect(boardsStore.state.lists.length).toBe(2); expect(boardsStore.addList).toHaveBeenCalledTimes(2);
expect(boardsStore.state.lists[0].title).toEqual('To Do'); expect(boardsStore.addList).toHaveBeenCalledWith(
expect(boardsStore.state.lists[1].title).toEqual('Doing'); jasmine.objectContaining({ title: 'To Do' }),
);
expect(boardsStore.addList).toHaveBeenCalledWith(
jasmine.objectContaining({ title: 'Doing' }),
);
done(); done();
}); });
...@@ -86,7 +91,7 @@ describe('Boards blank state', () => { ...@@ -86,7 +91,7 @@ describe('Boards blank state', () => {
setTimeout(() => { setTimeout(() => {
expect(boardsStore.welcomeIsHidden()).toBeFalsy(); expect(boardsStore.welcomeIsHidden()).toBeFalsy();
expect(boardsStore.state.lists.length).toBe(1); expect(boardsStore.removeList).toHaveBeenCalledWith(undefined, 'label');
done(); done();
}); });
......
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