NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import KitValidate from '../../stores/KitValidate';
import api from '../../api/api';
import gatewayApi from '../../api/gatewayApi';
import appState from '../../stores/appState';

describe('Test KitValidate store', () => {
let kitValidate;

beforeEach(() => {
kitValidate = new KitValidate();
});

describe('testing initializeKitValdate', () => {
it('initializes KitValidate store successfully', async () => {
const mockPartNumber = 'partNumber';
const mockRevisionCode = 'revisionCode';
const mockZPartData = [
{ partNumber: 'part1', name: 'Part 1' },
{ partNumber: 'part2', name: 'Part 2' },
];
const mockRevisionsData = [
{ title: 'REV1', description: 'REV1_DESC', revisioncode: 'REV1' },
{ title: 'REV2', description: 'REV2_DESC', revisioncode: 'REV2' },
];

api.fetchZParts = jest.fn().mockResolvedValue({ data: mockZPartData });
gatewayApi.fetchRevisions = jest.fn().mockResolvedValue({ data: mockRevisionsData });

await kitValidate.initializeKitValdate(mockPartNumber, mockRevisionCode);

expect(kitValidate.state.zParts).toHaveLength(2);
expect(kitValidate.state.revisions).toHaveLength(3);

expect(api.fetchZParts).toHaveBeenCalledTimes(1);
expect(gatewayApi.fetchRevisions).toHaveBeenCalledTimes(1);
});

it('handles initialization errors', async () => {
api.fetchZParts = jest.fn().mockRejectedValue(new Error('Error fetching Z parts'));
gatewayApi.fetchRevisions = jest.fn().mockRejectedValue(new Error('Error fetching revisions'));

await kitValidate.initializeKitValdate();

expect(appState.err).toBeTruthy();
expect(appState.isInitializing).toBeFalsy();
});
});

describe('testing updateValue', () => {
it('updates the specified value', () => {
kitValidate.updateValue({ key: 'displayConfigure', value: false });

expect(kitValidate.displayConfigure).toEqual(false);
});
});

describe('testing reset', () => {
it('resets the store state', () => {
kitValidate.reset();

expect(kitValidate.state.kits).toEqual([]);
expect(kitValidate.showQueryPanel).toBeFalsy();
expect(kitValidate.partNumber).toEqual({});
expect(kitValidate.selectedRevision).toEqual({});
expect(kitValidate.displayConfigure).toBeTruthy();
});
});

describe('testing fetchKits', () => {
it('fetches kits for validation', async () => {
const mockSelectedZPart = { value: 'partNumber', label: 'partNumber - Part Name' };
const mockSelectedRevision = { value: 'revisionCode', label: 'revisionCode - Revision Title' };
const mockValidParts = { partNumber: true };
const mockKits = [
{ optionConstraintName: 'Constraint1', casePartNumber: 'case1', casePartName: 'Case 1', bandPartNumber: 'band1', bandPartName: 'Band 1' },
];

api.validatePart = jest.fn().mockResolvedValue({ data: mockValidParts });
api.fetchKitsForValidation = jest.fn().mockResolvedValue({ data: mockKits });

await kitValidate.fetchKits(mockSelectedZPart,mockSelectedRevision);
expect(kitValidate.partNumber).toEqual(mockSelectedZPart);
expect(kitValidate.selectedRevision).toEqual(mockSelectedRevision);
expect(kitValidate.state.kits).toHaveLength(1);

expect(api.validatePart).toHaveBeenCalledTimes(1);
expect(api.fetchKitsForValidation).toHaveBeenCalledTimes(1);
});

it('handles invalid part numbers', async () => {
const mockSelectedZPart = { value: 'partNumber', label: 'partNumber - Part Name' };
const mockSelectedRevision = { value: 'revisionCode', label: 'revisionCode - Revision Title' };
const mockValidParts = { partNumber: false };

api.validatePart = jest.fn().mockResolvedValue({ data: mockValidParts });

await kitValidate.fetchKits(mockSelectedZPart, mockSelectedRevision);

expect(appState.isFetching).toBeFalsy();
expect(api.validatePart).toHaveBeenCalledTimes(1);
expect(api.fetchKitsForValidation).not.toHaveBeenCalled();
});

it('handles errors while fetching kits', async () => {
const mockSelectedZPart = { value: 'partNumber', label: 'partNumber - Part Name' };
const mockSelectedRevision = { value: 'revisionCode', label: 'revisionCode - Revision Title' };
const mockValidParts = { partNumber: true };

api.validatePart = jest.fn().mockResolvedValue({ data: mockValidParts });
api.fetchKitsForValidation = jest.fn().mockRejectedValue(new Error('Error fetching kits'));

await kitValidate.fetchKits(mockSelectedZPart, mockSelectedRevision);

expect(appState.err).toBeTruthy();
expect(appState.isFetching).toBeFalsy();
});
});
});
describe('testing initializeKitValdate fetching kits', () => {
const mockPartNumber = 'partNumber';
const mockRevisionCode = 'revisionCode';
const mockZPartData = [
{ partNumber: 'part1', name: 'Part 1' },
{ partNumber: 'part2', name: 'Part 2' },
];
const mockRevisionsData = [
{ title: 'REV1', description: 'REV1_DESC', revisioncode: 'REV1' },
{ title: 'REV2', description: 'REV2_DESC', revisioncode: 'REV2' },
];

beforeEach(() => {
api.fetchZParts = jest.fn().mockResolvedValue({ data: mockZPartData });
gatewayApi.fetchRevisions = jest.fn().mockResolvedValue({ data: mockRevisionsData });
});

it('fetches kits when both selectedZPart and selectedRevision are provided', async () => {
kitValidate.fetchKits = jest.fn();
await kitValidate.initializeKitValdate(mockPartNumber, mockRevisionCode);

expect(kitValidate.fetchKits).toHaveBeenCalledTimes(1);
});

it('does not fetch kits when selectedZPart is not provided', async () => {
kitValidate.fetchKits = jest.fn();
await kitValidate.initializeKitValdate(null, mockRevisionCode);

expect(kitValidate.fetchKits).not.toHaveBeenCalled();
});

it('does not fetch kits when selectedRevision is not provided', async () => {
kitValidate.fetchKits = jest.fn();
await kitValidate.initializeKitValdate(mockPartNumber, null);

expect(kitValidate.fetchKits).not.toHaveBeenCalled();
});

it('does not fetch kits when both selectedZPart and selectedRevision are not provided', async () => {
kitValidate.fetchKits = jest.fn();
await kitValidate.initializeKitValdate(null, null);

expect(kitValidate.fetchKits).not.toHaveBeenCalled();
});
});

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.