NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import { runInAction } from 'mobx';
import api from '../api/api';
import appState from './appState';
import KitCompatibility from './kitCompatibility';

describe('Test KitCompatibility store', () => {
let kitCompatibility;

beforeEach(() => {
kitCompatibility = new KitCompatibility();
});

describe('testing updateValue', () => {
it('updates the specified value', () => {
kitCompatibility.updateValue({ key: 'eventTypeSelectZpart', value: 'test' });

expect(kitCompatibility.eventTypeSelectZpart).toEqual('test');
});
});

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

expect(kitCompatibility.state).toEqual(KitCompatibility.initialState);
expect(kitCompatibility.eventTypeSelectZpart).toEqual('');
expect(kitCompatibility.selectedConstraints).toEqual({});
});
});

describe('testing initializeKitCompatibility', () => {
it('initializes KitCompatibility store successfully', async () => {
// Prepare mock data
// ...

// Mock API calls
api.fetchZParts = jest.fn().mockResolvedValue({ data: mockZPartsData });
api.fetchConstraints = jest.fn().mockResolvedValue({ data: mockConstraintsData });

// Call function and test
// ...
});

it('handles initialization errors', async () => {
// Mock API calls with errors
// ...

// Call function and test
// ...
});
});

describe('testing fetchKitsForConstraintsResults', () => {
it('fetches kits for constraints results', async () => {
// Prepare mock data
// ...

// Mock API calls
api.fetchConstraints = jest.fn().mockResolvedValue({ data: mockConstraintsData });

// Call function and test
// ...
});

it('handles errors while fetching kits for constraints results', async () => {
// Mock API calls with errors
// ...

// Call function and test
// ...
});
});

describe('testing deleteConstraints', () => {
it('deletes constraints successfully', async () => {
// Prepare mock data
// ...

// Mock API calls
api.deleteConstraints = jest.fn().mockResolvedValue({});

// Call function and test
// ...
});

it('handles errors while deleting constraints', async () => {
// Mock API calls with errors
// ...

// Call function and test
// ...
});
});

describe('testing deleteListViewConstraints', () => {
it('deletes list view constraints successfully', async () => {
// Prepare mock data
// ...

// Mock API calls
api.deleteListViewWatchPairs = jest.fn().mockResolvedValue({});

// Call function and test
// ...
});

it('handles errors while deleting list view constraints', async () => {
// Mock API calls with errors
// ...

// Call function and test
// ...
});
});

describe('testing revertConstraintsToProduction', () => {
it('reverts constraints to production successfully', async () => {
// Prepare mock data
// ...

// Mock API calls
api.revertToProduction = jest.fn().mockResolvedValue({});

// Call function and test
// ...
});

it('handles errors while reverting constraints to production', async () => {
// Mock API calls with errors
// ...

// Call function and test
// ...

});
});

// Add more test cases if needed

});

// Prepare mock data for testing
const mockZPartsData = [
{
partNumber: '123',
name: 'Part 1',
},
{
partNumber: '456',
name: 'Part 2',
},
];

const mockConstraintsData = {
constraints: [],
zpartModifiedDate: new Date(),
revision: {},
disableRevertToProd: false,
};

// Helper function to reset appState
const resetAppState = () => {
runInAction(() => {
appState.handleNotification = jest.fn();
appState.updateValue = jest.fn();
appState.isInitializing = false;
appState.isFetching = false;
appState.isDeleting = false;
appState.err = false;
});
};

describe('testing initializeKitCompatibility', () => {
it('initializes KitCompatibility store successfully', async () => {
api.fetchZParts = jest.fn().mockResolvedValue({ data: mockZPartsData });
kitCompatibility.initializeKitCompatibility = jest.fn().mockResolvedValue();

await kitCompatibility.initializeKitCompatibility();

expect(kitCompatibility.state.zParts).toHaveLength(2);
expect(api.fetchZParts).toHaveBeenCalledTimes(1);
});

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

await kitCompatibility.initializeKitCompatibility();

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

describe('testing fetchKitsForConstraintsResults', () => {
it('fetches kits for constraints successfully', async () => {
api.fetchConstraints = jest.fn().mockResolvedValue({ data: mockConstraintsData });
kitCompatibility.fetchKitsForConstraintsResults = jest.fn().mockResolvedValue();

await kitCompatibility.fetchKitsForConstraintsResults();

expect(api.fetchConstraints).toHaveBeenCalledTimes(1);
});

it('handles errors while fetching kits', async () => {
api.fetchConstraints = jest.fn().mockRejectedValue(new Error('Error fetching constraints'));

await kitCompatibility.fetchKitsForConstraintsResults();

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

describe('testing deleteConstraints', () => {
it('deletes constraints successfully', async () => {
api.deleteConstraints = jest.fn().mockResolvedValue();
kitCompatibility.deleteConstraints = jest.fn().mockResolvedValue();

await kitCompatibility.deleteConstraints();

expect(api.deleteConstraints).toHaveBeenCalledTimes(1);
});

it('handles errors while deleting constraints', async () => {
api.deleteConstraints = jest.fn().mockRejectedValue(new Error('Error deleting constraints'));

await kitCompatibility.deleteConstraints();

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

describe('testing deleteListViewConstraints', () => {
it('deletes list view constraints successfully', async () => {
api.deleteListViewWatchPairs = jest.fn().mockResolvedValue();
kitCompatibility.deleteListViewConstraints = jest.fn().mockResolvedValue();

await kitCompatibility.deleteListViewConstraints();

expect(api.deleteListViewWatchPairs).toHaveBeenCalledTimes(1);
});

it('handles errors while deleting list view constraints', async () => {
api.deleteListViewWatchPairs = jest.fn().mockRejectedValue(new Error('Error deleting list view constraints'));

await kitCompatibility.deleteListViewConstraints();

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

describe('testing revertConstraintsToProduction', () => {
it('reverts constraints to production successfully', async () => {
api.revertToProduction = jest.fn().mockResolvedValue();
kitCompatibility.revertConstraintsToProduction = jest.fn().mockResolvedValue();

await kitCompatibility.revertConstraintsToProduction();

expect(api.revertToProduction).toHaveBeenCalledTimes(1);
});

it('handles errors while reverting constraints to production', async () => {
api.revertToProduction = jest.fn().mockRejectedValue(new Error('Error reverting to production'));

await kitCompatibility.revertConstraintsToProduction();

expect(appState.err).toBeTruthy();
});
});
     
 
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.