Fixes sometimes-broken unit tests

This commit is contained in:
Aaron Louie 2020-02-25 15:33:25 -05:00
parent cc4fe0df86
commit e7e568bc8a
3 changed files with 28 additions and 23 deletions

View File

@ -1,13 +1,24 @@
import {Component} from '@angular/core';
import {async, ComponentFixture, TestBed} from '@angular/core/testing'; import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {MatIconModule} from '@angular/material/icon';
import {MatMenuModule} from '@angular/material/menu';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {RouterTestingModule} from '@angular/router/testing'; import {RouterTestingModule} from '@angular/router/testing';
import {MockEnvironment} from 'sartography-workflow-lib'; import {MockEnvironment} from 'sartography-workflow-lib';
import {AppComponent} from './app.component'; import {AppComponent} from './app.component';
import {FooterComponent} from './footer/footer.component';
import {NavbarComponent} from './navbar/navbar.component';
@Component({
selector: 'app-navbar',
template: ''
})
class MockNavbarComponent {
}
@Component({
selector: 'app-footer',
template: ''
})
class MockFooterComponent {
}
describe('AppComponent', () => { describe('AppComponent', () => {
let component: AppComponent; let component: AppComponent;
@ -17,13 +28,11 @@ describe('AppComponent', () => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ declarations: [
AppComponent, AppComponent,
FooterComponent, MockNavbarComponent,
NavbarComponent MockFooterComponent
], ],
imports: [ imports: [
BrowserAnimationsModule, BrowserAnimationsModule,
MatIconModule,
MatMenuModule,
RouterTestingModule, RouterTestingModule,
], ],
providers: [ providers: [

View File

@ -238,11 +238,11 @@ describe('ModelerComponent', () => {
}); });
it('should update the diagram file on change', () => { it('should update the diagram file on change', () => {
const valBefore = ''; const valBefore = BPMN_DIAGRAM.replace('REPLACE_ME', 'raindrops_on_roses');
component.diagramComponent.writeValue(valBefore); component.diagramComponent.writeValue(valBefore);
expect(component.diagramComponent.value).toEqual(valBefore); expect(component.diagramComponent.value).toEqual(valBefore);
const newValue = '<xml>newExpectedValue</xml>'; const newValue = BPMN_DIAGRAM.replace('REPLACE_ME', 'whiskers_on_kittens');
component.diagramComponent.writeValue(newValue); component.diagramComponent.writeValue(newValue);
expect(component.diagramComponent.value).toEqual(newValue); expect(component.diagramComponent.value).toEqual(newValue);
@ -250,16 +250,12 @@ describe('ModelerComponent', () => {
}); });
it('should save file changes when existing diagram is modified and then saved', () => { it('should save file changes when existing diagram is modified and then saved', () => {
const valBefore = '';
component.diagramComponent.writeValue(valBefore);
expect(component.diagramComponent.value).toEqual(valBefore);
const saveFileChangesSpy = spyOn(component, 'saveFileChanges').and.stub(); const saveFileChangesSpy = spyOn(component, 'saveFileChanges').and.stub();
const editFileMetaSpy = spyOn(component, 'editFileMeta').and.stub(); const editFileMetaSpy = spyOn(component, 'editFileMeta').and.stub();
component.workflowSpec = mockWorkflowSpec0; component.workflowSpec = mockWorkflowSpec0;
component.diagramFileMeta = mockFileMeta0; component.diagramFileMeta = mockFileMeta0;
component.diagramComponent.writeValue('<xml>newValue</xml>'); component.diagramComponent.writeValue(BPMN_DIAGRAM.replace('REPLACE_ME', 'bright_copper_kettles'));
component.saveChanges(); component.saveChanges();
expect(saveFileChangesSpy).toHaveBeenCalled(); expect(saveFileChangesSpy).toHaveBeenCalled();
@ -273,7 +269,7 @@ describe('ModelerComponent', () => {
component.newDiagram(FileType.BPMN); component.newDiagram(FileType.BPMN);
expect(component.diagramFileMeta).toBeFalsy(); expect(component.diagramFileMeta).toBeFalsy();
component.diagramComponent.writeValue('<xml>newValue</xml>'); component.diagramComponent.writeValue(BPMN_DIAGRAM.replace('REPLACE_ME', 'warm_woolen_mittens'));
component.saveChanges(); component.saveChanges();
expect(saveFileChangesSpy).not.toHaveBeenCalled(); expect(saveFileChangesSpy).not.toHaveBeenCalled();
@ -287,7 +283,7 @@ describe('ModelerComponent', () => {
component.workflowSpec = mockWorkflowSpec0; component.workflowSpec = mockWorkflowSpec0;
component.diagramFileMeta = mockFileMeta0; component.diagramFileMeta = mockFileMeta0;
component.diagramComponent.writeValue('<xml>newValue</xml>'); component.diagramComponent.writeValue(BPMN_DIAGRAM.replace('REPLACE_ME', 'brown_paper_packages_tied_up_with_strings'));
component.saveFileChanges(); component.saveFileChanges();
expect(updateFileMetaSpy).toHaveBeenCalledWith(mockFileMeta0); expect(updateFileMetaSpy).toHaveBeenCalledWith(mockFileMeta0);
@ -310,7 +306,7 @@ describe('ModelerComponent', () => {
}); });
it('should update file metadata for existing file', () => { it('should update file metadata for existing file', () => {
const newXml = '<xml>New Value</xml>'; const newXml = BPMN_DIAGRAM.replace('REPLACE_ME', 'cream_colored_ponies');
const data: FileMetaDialogData = { const data: FileMetaDialogData = {
fileName: mockFileMeta0.name, fileName: mockFileMeta0.name,
fileType: FileType.BPMN, fileType: FileType.BPMN,
@ -340,7 +336,7 @@ describe('ModelerComponent', () => {
}); });
it('should create new file metadata for new file', () => { it('should create new file metadata for new file', () => {
const newXml = '<xml>New Value</xml>'; const newXml = BPMN_DIAGRAM.replace('REPLACE_ME', 'crisp_apple_strudels');
const data: FileMetaDialogData = { const data: FileMetaDialogData = {
fileName: mockFileMeta0.name, fileName: mockFileMeta0.name,
fileType: FileType.BPMN, fileType: FileType.BPMN,
@ -404,8 +400,8 @@ describe('ModelerComponent', () => {
}); });
it('should start a new diagram', () => { it('should start a new diagram', () => {
component.xml = '<xml>old value</xml>'; component.xml = BPMN_DIAGRAM.replace('REPLACE_ME', 'doorbells');
component.draftXml = '<xml>even older value</xml>'; component.draftXml = BPMN_DIAGRAM.replace('REPLACE_ME', 'sleigh_bells');
component.diagramFileMeta = mockFileMeta0; component.diagramFileMeta = mockFileMeta0;
component.diagramFile = mockFileMeta0.file; component.diagramFile = mockFileMeta0.file;
component.workflowSpec = mockWorkflowSpec0; component.workflowSpec = mockWorkflowSpec0;

View File

@ -5,9 +5,9 @@ import {MatMenuModule} from '@angular/material/menu';
import {Router} from '@angular/router'; import {Router} from '@angular/router';
import {RouterTestingModule} from '@angular/router/testing'; import {RouterTestingModule} from '@angular/router/testing';
import {ApiService, MockEnvironment, mockUser} from 'sartography-workflow-lib'; import {ApiService, MockEnvironment, mockUser} from 'sartography-workflow-lib';
import { NavbarComponent } from './navbar.component'; import { NavbarComponent } from './navbar.component';
describe('NavbarComponent', () => { describe('NavbarComponent', () => {
let component: NavbarComponent; let component: NavbarComponent;
let fixture: ComponentFixture<NavbarComponent>; let fixture: ComponentFixture<NavbarComponent>;