Updates for computed unit tests
This commit is contained in:
parent
dc29175f1e
commit
ad4ec7209c
2 changed files with 232 additions and 100 deletions
|
|
@ -15,7 +15,7 @@ jest.mock('@/helpers/cms-content-helper', () => ({
|
||||||
fetchCmsContentForPage: jest.fn(),
|
fetchCmsContentForPage: jest.fn(),
|
||||||
processIfStatements: jest.fn()
|
processIfStatements: jest.fn()
|
||||||
}));
|
}));
|
||||||
const wordingText = 'wording Text {custom:address}';
|
const wordingText = 'wording text {custom:address}';
|
||||||
|
|
||||||
const mockMixin = {
|
const mockMixin = {
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -67,6 +67,55 @@ const initialStore = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const sessionStorage = {
|
||||||
|
schedule: {
|
||||||
|
date: '2024-03-01',
|
||||||
|
startTime: '09:00',
|
||||||
|
endTime: '10:00',
|
||||||
|
jobMinMinutes: 60,
|
||||||
|
jobMaxMinutes: 90
|
||||||
|
},
|
||||||
|
serviceLocation: {
|
||||||
|
address: '123 Test Way',
|
||||||
|
address2: '#1',
|
||||||
|
city: 'Mesa',
|
||||||
|
state: 'AZ',
|
||||||
|
zipCode: '12345',
|
||||||
|
appointmentType: 'Inshop',
|
||||||
|
provider: {
|
||||||
|
address: {
|
||||||
|
streetAddress: '123 Safelite Street',
|
||||||
|
city: 'Mesa',
|
||||||
|
state: 'AZ',
|
||||||
|
zipCode: '12345'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const sessionStorageMock = (() => {
|
||||||
|
let sessionStore = {};
|
||||||
|
|
||||||
|
return {
|
||||||
|
getItem(key) {
|
||||||
|
return sessionStore[key] || null;
|
||||||
|
},
|
||||||
|
setItem(key, value) {
|
||||||
|
sessionStore[key] = value.toString();
|
||||||
|
},
|
||||||
|
removeItem(key) {
|
||||||
|
delete sessionStore[key];
|
||||||
|
},
|
||||||
|
clear() {
|
||||||
|
sessionStore = {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
Object.defineProperty(window, 'sessionStorage', {
|
||||||
|
value: sessionStorageMock
|
||||||
|
});
|
||||||
|
|
||||||
function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRun = () => {}) {
|
function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRun = () => {}) {
|
||||||
const mountOptions = getMountOptions({
|
const mountOptions = getMountOptions({
|
||||||
router: {
|
router: {
|
||||||
|
|
@ -191,8 +240,15 @@ describe('OrderConfirmation.vue', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('Computed properties', () => {
|
describe('Computed properties', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
window.sessionStorage.clear();
|
||||||
|
});
|
||||||
|
afterEach(() => {
|
||||||
|
window.sessionStorage.removeItem('submittedOrder');
|
||||||
|
});
|
||||||
test('appointmentDateFormatted should return date in expected format', () => {
|
test('appointmentDateFormatted should return date in expected format', () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
window.sessionStorage.setItem('submittedOrder', JSON.stringify(sessionStorage));
|
||||||
const { wrapper } = getMountedComponent(initialStore);
|
const { wrapper } = getMountedComponent(initialStore);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -203,19 +259,18 @@ describe('OrderConfirmation.vue', () => {
|
||||||
});
|
});
|
||||||
test('appointmentTimeFormatted should return Mobile time in expected format', () => {
|
test('appointmentTimeFormatted should return Mobile time in expected format', () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const testStore = {
|
const testSessionStorage = {
|
||||||
order: {
|
schedule: {
|
||||||
schedule: {
|
date: '2019-01-01',
|
||||||
date: '2019-01-01',
|
startTime: '09:00',
|
||||||
startTime: '09:00',
|
endTime: '10:00'
|
||||||
endTime: '10:00'
|
},
|
||||||
},
|
serviceLocation: {
|
||||||
serviceLocation: {
|
appointmentType: 'Mobile'
|
||||||
appointmentType: 'Mobile'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const { wrapper } = getMountedComponent(testStore);
|
window.sessionStorage.setItem('submittedOrder', JSON.stringify(testSessionStorage));
|
||||||
|
const { wrapper } = getMountedComponent();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const testValue = wrapper.vm.appointmentTimeFormatted;
|
const testValue = wrapper.vm.appointmentTimeFormatted;
|
||||||
|
|
@ -225,19 +280,26 @@ describe('OrderConfirmation.vue', () => {
|
||||||
});
|
});
|
||||||
test('appointmentTimeFormatted should return Drop Off time in expected format', () => {
|
test('appointmentTimeFormatted should return Drop Off time in expected format', () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const testStore = {
|
const testSessionStorage = {
|
||||||
order: {
|
schedule: {
|
||||||
schedule: {
|
date: '2019-01-01',
|
||||||
date: '2019-01-01',
|
startTime: '09:00',
|
||||||
startTime: '09:00',
|
endTime: '10:00'
|
||||||
endTime: '10:00'
|
},
|
||||||
},
|
serviceLocation: {
|
||||||
serviceLocation: {
|
appointmentType: 'Dropoff',
|
||||||
appointmentType: 'Dropoff'
|
provider: {
|
||||||
|
address: {
|
||||||
|
streetAddress: '123 Safelite Street',
|
||||||
|
city: 'Mesa',
|
||||||
|
state: 'AZ',
|
||||||
|
zipCode: '12345'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const { wrapper } = getMountedComponent(testStore);
|
window.sessionStorage.setItem('submittedOrder', JSON.stringify(testSessionStorage));
|
||||||
|
const { wrapper } = getMountedComponent();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const testValue = wrapper.vm.appointmentTimeFormatted;
|
const testValue = wrapper.vm.appointmentTimeFormatted;
|
||||||
|
|
@ -247,6 +309,7 @@ describe('OrderConfirmation.vue', () => {
|
||||||
});
|
});
|
||||||
test('appointmentTimeFormatted should return In Shop time in expected format', () => {
|
test('appointmentTimeFormatted should return In Shop time in expected format', () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
window.sessionStorage.setItem('submittedOrder', JSON.stringify(sessionStorage));
|
||||||
const { wrapper } = getMountedComponent(initialStore);
|
const { wrapper } = getMountedComponent(initialStore);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -257,111 +320,162 @@ describe('OrderConfirmation.vue', () => {
|
||||||
});
|
});
|
||||||
test('appointmentWordingText should return Mobile text in expected format', () => {
|
test('appointmentWordingText should return Mobile text in expected format', () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const testStore = {
|
const testSessionStorage = {
|
||||||
order: {
|
schedule: {
|
||||||
schedule: {
|
date: '2019-01-01',
|
||||||
date: '2019-01-01',
|
startTime: '09:00',
|
||||||
startTime: '09:00',
|
endTime: '10:00'
|
||||||
endTime: '10:00'
|
},
|
||||||
},
|
serviceLocation: {
|
||||||
serviceLocation: {
|
address: '123 Test Way',
|
||||||
address: '123 Test Way',
|
address2: '#1',
|
||||||
address2: '#1',
|
city: 'Mesa',
|
||||||
city: 'Mesa',
|
state: 'AZ',
|
||||||
state: 'AZ',
|
zipCode: '12345',
|
||||||
zipCode: '12345',
|
appointmentType: 'Mobile'
|
||||||
appointmentType: 'Mobile'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const { wrapper } = getMountedComponent(testStore);
|
window.sessionStorage.setItem('submittedOrder', JSON.stringify(testSessionStorage));
|
||||||
|
const { wrapper } = getMountedComponent();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const testValue = wrapper.vm.appointmentWordingText;
|
const testValue = wrapper.vm.appointmentWordingText;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(testValue).toEqual('wording Text <br/>123 Test Way, #1,<br/> Mesa, AZ 12345<br/>');
|
expect(testValue).toEqual('wording text 123 Test Way, #1,<br/> Mesa, AZ 12345');
|
||||||
});
|
});
|
||||||
test('appointmentWordingText should return Drop Off text in expected format', () => {
|
test('appointmentWordingText should return Drop Off text in expected format', () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const testStore = {
|
const testSessionStorage = {
|
||||||
order: {
|
schedule: {
|
||||||
schedule: {
|
date: '2019-01-01',
|
||||||
date: '2019-01-01',
|
startTime: '09:00',
|
||||||
startTime: '09:00',
|
endTime: '10:00'
|
||||||
endTime: '10:00'
|
},
|
||||||
|
serviceLocation: {
|
||||||
|
provider: {
|
||||||
|
address: {
|
||||||
|
streetAddress: '123 Safelite Street',
|
||||||
|
city: 'Mesa',
|
||||||
|
state: 'AZ',
|
||||||
|
zipCode: '12345'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
serviceLocation: {
|
appointmentType: 'Dropoff'
|
||||||
provider: {
|
|
||||||
address: {
|
|
||||||
streetAddress: '123 Safelite Street',
|
|
||||||
city: 'Mesa',
|
|
||||||
state: 'AZ',
|
|
||||||
zipCode: '12345'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
appointmentType: 'Dropoff'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const { wrapper } = getMountedComponent(testStore);
|
window.sessionStorage.setItem('submittedOrder', JSON.stringify(testSessionStorage));
|
||||||
|
const { wrapper } = getMountedComponent();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const testValue = wrapper.vm.appointmentWordingText;
|
const testValue = wrapper.vm.appointmentWordingText;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(testValue).toEqual('wording Text <br/>123 Safelite Street,<br/> Mesa, AZ 12345<br/>');
|
expect(testValue).toEqual('wording text 123 Safelite Street,<br/> Mesa, AZ 12345');
|
||||||
});
|
});
|
||||||
test('appointmentWordingText should return In Shop text in expected format', () => {
|
test('appointmentWordingText should return In Shop text in expected format', () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = getMountedComponent(initialStore);
|
const testSessionStorage = {
|
||||||
|
schedule: {
|
||||||
|
date: '2019-01-01',
|
||||||
|
startTime: '09:00',
|
||||||
|
endTime: '10:00'
|
||||||
|
},
|
||||||
|
serviceLocation: {
|
||||||
|
provider: {
|
||||||
|
address: {
|
||||||
|
streetAddress: '123 Safelite Street',
|
||||||
|
city: 'Mesa',
|
||||||
|
state: 'AZ',
|
||||||
|
zipCode: '12345'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
appointmentType: 'Inshop'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.sessionStorage.setItem('submittedOrder', JSON.stringify(testSessionStorage));
|
||||||
|
const { wrapper } = getMountedComponent();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const testValue = wrapper.vm.appointmentWordingText;
|
const testValue = wrapper.vm.appointmentWordingText;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(testValue).toEqual('wording Text <br/>123 Safelite Street,<br/> Mesa, AZ 12345<br/>');
|
expect(testValue).toEqual('wording text 123 Safelite Street,<br/> Mesa, AZ 12345');
|
||||||
});
|
});
|
||||||
test('serviceLocationFullAddress should return text in expected format', () => {
|
test('serviceLocationFullAddress should return text in expected format', () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = getMountedComponent(initialStore);
|
const testSessionStorage = {
|
||||||
|
schedule: {
|
||||||
|
date: '2019-01-01',
|
||||||
|
startTime: '09:00',
|
||||||
|
endTime: '10:00'
|
||||||
|
},
|
||||||
|
serviceLocation: {
|
||||||
|
address: '123 Test Way',
|
||||||
|
address2: '#1',
|
||||||
|
city: 'Mesa',
|
||||||
|
state: 'AZ',
|
||||||
|
zipCode: '12345',
|
||||||
|
appointmentType: 'Mobile'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.sessionStorage.setItem('submittedOrder', JSON.stringify(testSessionStorage));
|
||||||
|
const { wrapper } = getMountedComponent();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const testValue = wrapper.vm.serviceLocationFullAddress;
|
const testValue = wrapper.vm.serviceLocationFullAddress;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(testValue).toEqual('<br/>123 Test Way, #1,<br/> Mesa, AZ 12345<br/>');
|
expect(testValue).toEqual('123 Test Way, #1,<br/> Mesa, AZ 12345');
|
||||||
});
|
});
|
||||||
test('providerFullAddress should return text in expected format', () => {
|
test('providerFullAddress should return text in expected format', () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = getMountedComponent(initialStore);
|
const testSessionStorage = {
|
||||||
|
schedule: {
|
||||||
|
date: '2019-01-01',
|
||||||
|
startTime: '09:00',
|
||||||
|
endTime: '10:00'
|
||||||
|
},
|
||||||
|
serviceLocation: {
|
||||||
|
provider: {
|
||||||
|
address: {
|
||||||
|
streetAddress: '123 Safelite Street',
|
||||||
|
city: 'Mesa',
|
||||||
|
state: 'AZ',
|
||||||
|
zipCode: '12345'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
appointmentType: 'Inshop'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.sessionStorage.setItem('submittedOrder', JSON.stringify(testSessionStorage));
|
||||||
|
const { wrapper } = getMountedComponent();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const testValue = wrapper.vm.providerFullAddress;
|
const testValue = wrapper.vm.providerFullAddress;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(testValue).toEqual('<br/>123 Safelite Street,<br/> Mesa, AZ 12345<br/>');
|
expect(testValue).toEqual('123 Safelite Street,<br/> Mesa, AZ 12345');
|
||||||
});
|
});
|
||||||
test('appointmentWordingText2 should return Mobile text in expected format', () => {
|
test('appointmentWordingText2 should return Mobile text in expected format', () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const testStore = {
|
const testSessionStorage = {
|
||||||
order: {
|
schedule: {
|
||||||
schedule: {
|
date: '2019-01-01',
|
||||||
date: '2019-01-01',
|
startTime: '09:00',
|
||||||
startTime: '09:00',
|
endTime: '10:00'
|
||||||
endTime: '10:00'
|
},
|
||||||
},
|
serviceLocation: {
|
||||||
serviceLocation: {
|
address: '123 Test Way',
|
||||||
address: '123 Test Way',
|
address2: '#1',
|
||||||
address2: '#1',
|
city: 'Mesa',
|
||||||
city: 'Mesa',
|
state: 'AZ',
|
||||||
state: 'AZ',
|
zipCode: '12345',
|
||||||
zipCode: '12345',
|
appointmentType: 'Mobile'
|
||||||
appointmentType: 'Mobile'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const { wrapper } = getMountedComponent(testStore);
|
window.sessionStorage.setItem('submittedOrder', JSON.stringify(testSessionStorage));
|
||||||
|
const { wrapper } = getMountedComponent();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const testValue = wrapper.vm.appointmentWordingText2;
|
const testValue = wrapper.vm.appointmentWordingText2;
|
||||||
|
|
@ -371,27 +485,26 @@ describe('OrderConfirmation.vue', () => {
|
||||||
});
|
});
|
||||||
test('appointmentWordingText2 should return Drop Off and text in expected format', () => {
|
test('appointmentWordingText2 should return Drop Off and text in expected format', () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const testStore = {
|
const testSessionStorage = {
|
||||||
order: {
|
schedule: {
|
||||||
schedule: {
|
date: '2019-01-01',
|
||||||
date: '2019-01-01',
|
startTime: '09:00',
|
||||||
startTime: '09:00',
|
endTime: '10:00'
|
||||||
endTime: '10:00'
|
},
|
||||||
|
serviceLocation: {
|
||||||
|
provider: {
|
||||||
|
address: {
|
||||||
|
streetAddress: '123 Safelite Street',
|
||||||
|
city: 'Mesa',
|
||||||
|
state: 'AZ',
|
||||||
|
zipCode: '12345'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
serviceLocation: {
|
appointmentType: 'Dropoff'
|
||||||
provider: {
|
|
||||||
address: {
|
|
||||||
streetAddress: '123 Safelite Street',
|
|
||||||
city: 'Mesa',
|
|
||||||
state: 'AZ',
|
|
||||||
zipCode: '12345'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
appointmentType: 'Dropoff'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const { wrapper } = getMountedComponent(testStore);
|
window.sessionStorage.setItem('submittedOrder', JSON.stringify(testSessionStorage));
|
||||||
|
const { wrapper } = getMountedComponent();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const testValue = wrapper.vm.appointmentWordingText2;
|
const testValue = wrapper.vm.appointmentWordingText2;
|
||||||
|
|
@ -402,7 +515,26 @@ describe('OrderConfirmation.vue', () => {
|
||||||
});
|
});
|
||||||
test('appointmentWordingText2 should return In Shop text in expected format', () => {
|
test('appointmentWordingText2 should return In Shop text in expected format', () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = getMountedComponent(initialStore);
|
const testSessionStorage = {
|
||||||
|
schedule: {
|
||||||
|
date: '2019-01-01',
|
||||||
|
startTime: '09:00',
|
||||||
|
endTime: '10:00'
|
||||||
|
},
|
||||||
|
serviceLocation: {
|
||||||
|
provider: {
|
||||||
|
address: {
|
||||||
|
streetAddress: '123 Safelite Street',
|
||||||
|
city: 'Mesa',
|
||||||
|
state: 'AZ',
|
||||||
|
zipCode: '12345'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
appointmentType: 'Inshop'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.sessionStorage.setItem('submittedOrder', JSON.stringify(testSessionStorage));
|
||||||
|
const { wrapper } = getMountedComponent();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const testValue = wrapper.vm.appointmentWordingText2;
|
const testValue = wrapper.vm.appointmentWordingText2;
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,7 @@ export default {
|
||||||
},
|
},
|
||||||
providerFullAddress() {
|
providerFullAddress() {
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
return `<br/>${this.providerAddress},<br/> ${this.providerCity}, ${this.providerState} ${this.providerZipCode}<br/>`;
|
return `${this.providerAddress},<br/> ${this.providerCity}, ${this.providerState} ${this.providerZipCode}`;
|
||||||
},
|
},
|
||||||
appointmentWordingText() {
|
appointmentWordingText() {
|
||||||
switch (this.appointmentType) {
|
switch (this.appointmentType) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue