Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { createComponentStub } = require('frint-test');
- const Car = require(`${__base}/components/Car/Car`);
- const { prepareDisplayData } = require(`${__base}/components/Car/Car.helpers`);
- const createCar = require(`${__base}/test/components/car/mock`);
- const CarRoot = require('../../../containers/CarRoot/CarRoot');
- const { init } = require('../../../containers/CarRoot/CarRoot.actions');
- const { showCar } = require('../../../../carsidebar/containers/CarShow/CarShow.actions');
- const mount = enzyme.mount;
- const render = enzyme.render;
- const createCarRootStub = (initAction = init, nbLegs = 2, coreUpdater = { updateCore: () => {} }) => {
- return createComponentStub(CarRoot, {
- dispatch: {
- init: initAction,
- showCar,
- },
- factories: {
- assets: {
- url(arg) {
- return arg;
- },
- },
- externalRequest: {
- send(alias, method, urlPath, body) {
- return new Promise((resolve) => {
- resolve(body || '');
- });
- },
- get(alias, urlPath) {
- return this.send(alias, 'GET', urlPath);
- },
- post(alias, urlPath, data) {
- return this.send(alias, 'POST', urlPath, data);
- },
- },
- },
- models: {
- affiliate: {
- getAffiliateCode() {
- return '';
- },
- },
- },
- services: {
- l10ns: {
- l(key) {
- return key;
- },
- getCurrentCurrency() {
- return 'EUR';
- },
- getCurrentCurrencySymbol() {
- return '€';
- },
- getCurrentCulture() {
- return 'en'
- }
- },
- sessionStorage: {
- get() {
- return null;
- },
- set() {
- return null;
- }
- },
- widgetsMediator: {
- toSidebar() {},
- toRoot() {},
- },
- tripDataMapper: {
- getTripData() {
- return Promise.resolve({
- flightDetails: {
- Legs: Array.from({ length: nbLegs }, (value, key) => ({ // eslint-disable-line
- ArrivalAirport: { Code: '' },
- ArrivalDateTime: '',
- })),
- Fares: [{
- PassengerFares: [{
- NrOfPax: 1,
- }],
- }],
- },
- checkoutContact: {
- CountryCode: '',
- },
- });
- },
- },
- carService: {
- shop() {
- return Promise.resolve({
- cars: [],
- });
- },
- },
- coreUpdater,
- },
- state: s => ({
- ...s.carRoot,
- ...s.carShow,
- }),
- });
- };
- describe('<CarRoot />', () => {
- it.only('should render carRoot widget after car is loaded', (done) => {
- const cars = [1, 2, 3].map(() => prepareDisplayData(createCar()));
- const CarRootStub = createCarRootStub();
- const wrapper = mount(<CarRootStub cars={cars} loading={false} />);
- setTimeout(() => {
- expect(wrapper.find('.car-start--state-loading')).to.have.length(0);
- expect(wrapper.find('.car-start--car-list')).to.have.length(1);
- expect(wrapper.find(Car)).to.have.property('length').to.be.equal(3);
- done();
- });
- });
- it('should call "coreUpdater" if the amount of legs is less than 2', (done) => {
- const spyInit = sinon.spy();
- const coreUpdater = {
- updateCore: () => {},
- };
- const spyCoreUpdater = sinon.spy(coreUpdater, 'updateCore');
- const CarRootStub = createCarRootStub(spyInit, 1, coreUpdater);
- mount(<CarRootStub />);
- setTimeout(() => {
- expect(spyCoreUpdater).to.have.callCount(1);
- expect(spyInit).to.have.callCount(0);
- done();
- });
- });
- it('should call "coreUpdater" if the amount of legs is more than 2', (done) => {
- const spyInit = sinon.spy();
- const coreUpdater = {
- updateCore: () => {},
- };
- const spyCoreUpdater = sinon.spy(coreUpdater, 'updateCore');
- const CarRootStub = createCarRootStub(spyInit, 3, coreUpdater);
- mount(<CarRootStub />);
- setTimeout(() => {
- expect(spyCoreUpdater).to.have.callCount(1);
- expect(spyInit).to.have.callCount(0);
- done();
- });
- });
- it('should call "init" method right after mount', (done) => {
- const spy = sinon.spy();
- const CarRootStub = createCarRootStub(spy);
- mount(<CarRootStub />);
- // because of a promise in afterMount (tripDataMapper.getTripData()), this test is async now
- setTimeout(() => {
- expect(spy).to.have.callCount(1);
- done();
- });
- });
- it('should render loading block if loading is in progress', () => {
- const CarRootStub = createCarRootStub();
- const wrapper = render(<CarRootStub loading />);
- expect(wrapper.find('.car-start--state-loading')).to.have.length(1);
- });
- it('should render error block if loading is in progress', () => {
- const CarRootStub = createCarRootStub();
- const wrapper = render(<CarRootStub error="AN_ERROR_KEY" />);
- expect(wrapper.find('.car-start--state-error')).to.have.length(1);
- });
- it('should hide if there is an error', () => {
- const CarRootStub = createCarRootStub();
- const wrapper = render(<CarRootStub loading={false} />);
- expect(wrapper.find('.car-start')).to.have.length(0);
- expect(wrapper.find('.car-start--state-loading')).to.have.length(0);
- expect(wrapper.find('.car-start--state-empty')).to.have.length(1);
- });
- it('should render selected block if there is a selected car', () => {
- const cars = [1, 2, 3].map(() => prepareDisplayData(createCar()));
- const CarRootStub = createCarRootStub();
- const wrapper = mount(<CarRootStub cars={cars} loading={false} selectedCar={prepareDisplayData(createCar())} />);
- expect(wrapper.find('.car--state-selected')).to.have.length(1);
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement