instantjob-recruiter-client
Version:
a set of tools for creating an instantjob recruiter react client
100 lines (85 loc) • 3.26 kB
JSX
import {
get_missions, get_mission_users, get_displayed_deals, get_default_deal, get_mission_proposals,
get_deals, deal_status, get_proposals,
} from 'selectors/missions'
import state from './state.js'
import {array_from_set, set_from_array, array_from_hash, for_all} from 'common/utilities'
import expect from 'expect'
const user_statuses = ['available', 'impossible', 'new', 'accepted', 'rejected', 'assigned']
describe("get_missions", () => {
let missions = get_missions(state)
it("should compute mission status", () => {
expect(missions[1].status).toEqual('draft')
expect(missions[2].status).toEqual('sent')
expect(missions[3].status).toEqual('assigned')
expect(missions[4].status).toEqual('pending_assignement')
expect(missions[5].status).toEqual('pending_selection')
})
it("should keep the number of missions", () => {
expect(array_from_hash(missions).length).toEqual(array_from_hash(state.missions.missions).length)
})
it("should keep ids", () => {
expect(for_all(Object.keys(missions), (id) => missions[id].id == id)).toBeTruthy()
})
user_statuses.forEach((user_status) => {
array_from_hash(missions).slice(0, 5).forEach((mission) => {
it(`grouped_users_status should have distinct values for mission status ${mission.status} and user status ${user_status}`, () => {
let has_distinct_elements = (array) => array_from_set(set_from_array(array)).length == array.length
expect(has_distinct_elements(mission.grouped_users_status[user_status])).toBeTruthy();
})
})
})
})
describe("get_mission_users", () => {
user_statuses.forEach((user_status) => {
array_from_hash(get_missions(state)).slice(0, 5).forEach((mission) => {
it(`should preserve user count for mission status ${mission.status} and user status ${user_status}`, () => {
expect(array_from_hash(get_mission_users(mission.id, user_status)(state)).length).toEqual(mission.grouped_users_status[user_status].length)
})
})
if (user_status == "available") {
it("should compute all available users", () => {
expect(array_from_hash(get_mission_users(6, "available")(state)).length).toEqual(1)
})
}
})
})
describe("get_displayed_deals", () => {
it("should not include default deals", () => {
let deals = get_displayed_deals(state)
expect(deals[state.recruiters.recruiters[1].default_deal_id]).toNotExist()
})
})
describe("get_default_deal", () => {
it("should return default deal", () => {
expect(get_default_deal(state)).toMatch({
id: 6,
})
})
})
describe("get_mission_proposals", () => {
it("should find deleted missions", () => {
expect(get_mission_proposals(state)[14]).toMatch({
id: 14,
})
})
})
describe("get_deals", () => {
it("should not include deleted missions", () => {
expect(get_deals(state)[6].missions.length).toEqual(1)
})
it("should compute deals status", () => {
const status = deal_status([
{status: 'assigned'},
{status: 'sent'},
])
expect(status).toEqual('sent')
})
})
describe("get_proposals", () => {
it("should return proposals", () => {
expect(get_proposals(3)(state)).toMatch([
{id: 1, user: {id: 1}, fields: []},
])
})
})