Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions frontend/tests/App.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,63 @@ describe('App.vue', () => {
expect(wrapper.name()).toBe('App')
})

it('initRpc - method', () => {
wrapper = initComponent(App, {}, true)
wrapper.vm.rpc = {
invoke: jest.fn().mockImplementation(async () => { return { data: {} }; }),
registerMethod: jest.fn()
}

wrapper.vm.showCollections = jest.fn()

const invokeSpy = jest.spyOn(wrapper.vm.rpc, 'invoke')
const registerMethodSpy = jest.spyOn(wrapper.vm.rpc, 'registerMethod')
wrapper.vm.initRpc();

expect(registerMethodSpy).toHaveBeenCalledWith({func: wrapper.vm.showCollections, thisArg: wrapper.vm, name: 'showCollections'})
expect(invokeSpy).toHaveBeenCalledWith("getState")

invokeSpy.mockRestore()
registerMethodSpy.mockRestore()
})

it('reload - method', () => {
wrapper = initComponent(App)

wrapper.vm.rpc = {
invoke: jest.fn().mockImplementation(async () => { return { data: {} }; })
}
const invokeSpy = jest.spyOn(wrapper.vm.rpc, 'invoke')
wrapper.vm.reload();

expect(invokeSpy).toHaveBeenCalledWith("getState")

invokeSpy.mockRestore()
})

it('showCollections - method', () => {
wrapper = initComponent(App)
wrapper.vm.showCollections("collection");
expect(wrapper.vm.collections).toEqual("collection");
})

it('onAction - method', () => {
wrapper = initComponent(App, {}, true)
wrapper.vm.rpc = {
invoke: jest.fn().mockImplementation(async () => { return { data: {} }; })
}
const contextualItem = {
item: {
fqid: "fqid"
},
context: "context"
}
const invokeSpy = jest.spyOn(wrapper.vm.rpc, 'invoke')
wrapper.vm.onAction(contextualItem, 1);

expect(invokeSpy).toHaveBeenCalledWith("performAction", ["fqid", 1, "context"])

invokeSpy.mockRestore()
})

})
60 changes: 60 additions & 0 deletions frontend/tests/components/Collections.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,64 @@ describe('ICollection.vue', () => {
wrapper = initComponent(Collections, {collections: []}, true)
expect(_.keys(wrapper.props())).toHaveLength(1)
})

test('onAction - method', async () => {
wrapper = initComponent(Collections, {collections: []}, true)
const contextualItem = {
item: {
fqid: "fqid"
},
context: "context"
}
wrapper.vm.onAction(contextualItem, 1);
expect(wrapper.emitted().action).toBeTruthy();
})

test('onFilter - method', async () => {
wrapper = initComponent(Collections, {collections: []}, true)
const json = "{ \"type\": \"foodq\" }"
let filter = new Map();
const labelObj = JSON.parse(json);
filter.set(labelObj.key, labelObj.value);

wrapper.vm.onFilter(json);
expect(wrapper.vm.filter).toEqual(filter)
})

test('normalizeLabels - method', async () => {
let item1 = {
id: "id1",
fqid: "fqid",
title: "title1",
description: "description1",
action1: {
name: "name",
action: "action",
contexts: [{
project: "myProj",
context: {}
}]
},
labels: [
{ "key": "value" }
]
};
let collection1 = {
id: "collection1",
title: "title1",
description: "description1",
items: [item1]
};
let labels = new Map();
let label = new Map();
label.set("__all", {text:"<All>", value:JSON.stringify({"key":"key",value:"__all"})});
label.set("value", {text:"value", value:JSON.stringify({"key":"key",value:"value"})});
labels.set("key", label);

wrapper = initComponent(Collections, {collections: [collection1]}, true)
wrapper.vm.normalizeLabels();
expect(wrapper.vm.labels).toEqual(labels)
})


})
79 changes: 79 additions & 0 deletions frontend/tests/components/Items.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,83 @@ describe('Items.vue', () => {
wrapper = initComponent(Items, {items: [], filter: {}, bColorFlag: true}, true)
expect(_.keys(wrapper.props())).toHaveLength(3)
})

describe('onAction - method', () => {
test('no items', async () => {
wrapper = initComponent(Items, {items: [], filter: new Map(), bColorFlag: true}, true)
const contextualItem = {
item: {
fqid: "fqid"
},
context: "context"
}
wrapper.vm.onAction(contextualItem, 1);
expect(wrapper.emitted().action).toBeTruthy();
})

test('item exists', async () => {
let item = {
id: "id1",
fqid: "fqid",
title: "title1",
description: "description1",
action1: {
name: "name",
action: "action",
contexts: [{
project: "myProj",
context: {}
}]
},
labels: [
{ "Project Type": "create-grocery-list" }
]
};
wrapper = initComponent(Items, {items: [item], filter: new Map(), bColorFlag: true}, true)
let contextualItem = wrapper.vm.contextualItem;
wrapper.vm.onAction(contextualItem, 1);
expect(wrapper.emitted().action).toBeTruthy();
})
})

describe('isFiltered - method', () => {
test('no filter', async () => {
let item = {
id: "id1",
fqid: "fqid",
title: "title1",
description: "description1",
action1: {
name: "name",
action: "action"
},
labels: [
{ "Project Type": "create-grocery-list" }
]
};
wrapper = initComponent(Items, {items: [item], filter: new Map(), bColorFlag: true}, true)

const res = wrapper.vm.isFiltered("itemId");
expect(res).toBe(false);
})

test('filter exists', async () => {
let item1 = {
id: "id1",
fqid: "fqid1",
title: "title1",
description: "description1",
labels: [
{ "ProjectType": "create1" }
]
};
let filter = new Map();
filter.set("ProjectType", "create2")

wrapper = initComponent(Items, {items: [item1], filter: filter, bColorFlag: true}, true)

const res = wrapper.vm.isFiltered("fqid1");
expect(res).toBe(false);
})
})
})