Skip to content

Commit

Permalink
Added some previously omitted test files.
Browse files Browse the repository at this point in the history
  • Loading branch information
knirirr committed Jan 23, 2024
1 parent 76cdcd6 commit 6ddd3e8
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/components/Organisations/SearchOrganisationRecords.vue
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@

<script>
import TagChips from "@/components/Organisations/TagChips.vue";
import RecordStatus from "@/components/Records/Shared/RecordStatus.vue";
import TagChips from "@/components/Records/Shared/TagChips.vue";
import recordsCardUtils from "@/utils/recordsCardUtils";
import stringUtils from "@/utils/stringUtils";
Expand Down Expand Up @@ -211,8 +211,8 @@ export default {
downloadResults() {
var MIME_TYPE = "text/csv";
let data = ["name,abbreviation,URL\n"];
this.getFairSharingRecords.forEach((record) => {
data.push(`${record.name},${record.abbreviation || 'n/a'},https://fairsharing.org/${record.id}\n`);
this.organisationLinks.forEach((link) => {
data.push(`${link.fairsharingRecord.name},${link.fairsharingRecord.abbreviation || 'n/a'},https://fairsharing.org/${link.fairsharingRecord.id}\n`);
})
var blob = new Blob(data, {type: MIME_TYPE});
window.location.href = window.URL.createObjectURL(blob);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import {createLocalVue, shallowMount} from "@vue/test-utils";
import Vuetify from "vuetify"
import Vuex from "vuex";

import SearchOrganisationRecords from "@/components/Organisations/SearchOrganisationRecords.vue";

const localVue = createLocalVue();
localVue.use(Vuex);

const vuetify = new Vuetify();

let organisation = {
id: 1,
name: "4DN Data Coordination and Integration Center",
alternativeNames: [],
homepage: "http://dcic.4dnucleome.org/",
rorLink: "https://roro.roror.ror",
types: [
"Consortium"
],
urlForLogo: "/logo12345678",
childOrganisations: [],
parentOrganisations: [],
organisationLinks: [
{
id: 6057,
isLead: true,
relation: "maintains",
fairsharingRecord: {
id: 872,
name: "Pairs file format",
abbreviation: ".pairs",
type: "model_and_format",
registry: "Standard",
status: "ready"
},
"grant": null
}
],
users: [],
countries: []
}

describe("SearchOrganisationRecords.vue", function(){
let wrapper;

beforeEach(() => {
wrapper = shallowMount(SearchOrganisationRecords, {
localVue,
vuetify,
propsData: { organisation: organisation },
stubs: ['router-link', 'router-view']
})
});

it("can be instantiated", () => {
expect(wrapper.vm.$options.name).toMatch("SearchOrganisationRecords");
});

it('gets abbreviations', () => {
let record = {
name: 'name'
};
expect(wrapper.vm.getAbbr(record)).toBe('');
record.abbreviation = 'n';
expect(wrapper.vm.getAbbr(record)).toEqual('(n)');
});

it('reformats links', () => {
let before = [
{
isLead: true,
relation: true,
fairsharingRecord: {
name: 'test'
}
}
]
let after = [
{
isLead: true,
relation: true,
name: 'test'
}
]
expect(wrapper.vm.reformatLinks(before)).toStrictEqual(after);
});

});
109 changes: 109 additions & 0 deletions tests/unit/components/Records/Shared/TagChips.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import {createLocalVue, shallowMount} from "@vue/test-utils";
import Vuetify from "vuetify"

import TagChips from "@/components/Records/Shared/TagChips.vue"

let $route = {
name: "search",
query: {}
};

const $router = {
push: jest.fn(),
};

describe("TagChips.vue", function () {
let wrapper;
const vuetify = new Vuetify();
const localVue = createLocalVue();

beforeEach(() => {
wrapper = shallowMount(TagChips, {
localVue,
vuetify,
propsData: {
record: {
name: 'test record',
subjects: [
{
label: 'first chip',
active: false
}
],
domains: [
{
label: 'second chip',
active: false
}
],
taxonomies: [
{
label: 'third chip',
active: false
},
{
label: 'fourth chip',
active: false
},
{
label: 'fifth chip',
active: false
},
{
label: 'sixth chip',
active: false
},
{
label: 'seventh chip',
active: false
},
{
label: 'eighth chip',
active: false
},
{
label: 'ninth chip',
active: false
}
],
user_defined_tags: [
{
label: 'a tag'
}
]
}
/*
type: 'domains',
chips: [
{
label: 'first chip',
active: false
}
]
*/
},
mocks: {$route, $router}
});
});

it("can be instantiated", () => {
expect(wrapper.vm.$options.name).toMatch("TagChips");
});

it("getChipColor", () => {
let chip = {type: 'subjects'};
expect(wrapper.vm.getChipColor(chip)).toEqual('subject_color');
chip = {type: 'domains'};
expect(wrapper.vm.getChipColor(chip)).toEqual('domain_color');
chip = {type: 'taxonomies'};
expect(wrapper.vm.getChipColor(chip)).toEqual('taxonomic_color');
chip = {type: 'userDefinedTags'};
expect(wrapper.vm.getChipColor(chip)).toEqual('tags_color');
});

it("capitalises words properly", () => {
expect(wrapper.vm.capitaliseText('this that', 'taxonomy')).toEqual('This that');
expect(wrapper.vm.capitaliseText('this that', 'other')).toEqual('This That');
});

});

0 comments on commit 6ddd3e8

Please sign in to comment.