Commit cd6bbe56 authored by anthony's avatar anthony Committed by benjaminParisel

fix(Import) Improve report when imported page already exist

- differentiate imported element from overriden element in import report
- wording different for pages (save as instead of rename)
- do not display page again in dependencies list as there is already a
section for that
- refactor to change override into overwrite in code (the real behavior)

Covers [BS-18203](https://bonitasoft.atlassian.net/browse/BS-18203)
parent 0e2faceb
......@@ -76,9 +76,9 @@ public class ArtifactImporter<T extends Identifiable> {
ImportReport report = buildReport(element, dependencies);
report.setUUID(anImport.getUUID());
if (force || report.doesNotOverrideElements()) {
if (force || report.doesNotOverwriteElements()) {
if (force) {
//delete element that will be overriden
//delete element that will be overwritten
deleteComponentWithSameUUID(report, element);
}
// then save them
......@@ -115,8 +115,8 @@ public class ArtifactImporter<T extends Identifiable> {
}
private void deleteComponentWithSameUUID(ImportReport report, T element) {
T elementToReplace = (T) report.getElement();
if (report.isOverridden() && elementToReplace instanceof HasUUID
T elementToReplace = (T) report.getOverwrittenElement();
if (report.isOverwritten() && elementToReplace instanceof HasUUID
&& elementToReplace.getId() != element.getId()) {
repository.delete(elementToReplace.getId());
}
......@@ -125,19 +125,19 @@ public class ArtifactImporter<T extends Identifiable> {
private ImportReport buildReport(T element, Map<DependencyImporter, List<?>> dependencies) {
ImportReport report = ImportReport.from(element, dependencies);
if(element instanceof HasUUID) {
checkIfElementWithUUIDIsOverriden(element, report);
checkIfElementWithUUIDIsOverwritten(element, report);
} else if (repository.exists(element.getId())) {
setOverriden(report, element.getId());
setOverwritten(report, element.getId());
}
return report;
}
private void checkIfElementWithUUIDIsOverriden(T element, ImportReport report) {
private void checkIfElementWithUUIDIsOverwritten(T element, ImportReport report) {
String elementUUID = ((HasUUID) element).getUUID();
T overridenElement = null;
T overwrittenElement = null;
if (!StringUtils.isEmpty(elementUUID)) {
// if there is already a artifact with this UUID, it will be replaced
overridenElement = repository.getByUUID(elementUUID);
overwrittenElement = repository.getByUUID(elementUUID);
} else {
try {
UUID.fromString(element.getId());
......@@ -146,21 +146,21 @@ public class ArtifactImporter<T extends Identifiable> {
+ "The migration will give it an uuid attribute with the same value as its id.", element.getId()));
// Migration will give the artifact the same uuid attribute as its ID
// so if there is already an artifact with this UUID, it will be replaced
overridenElement = repository.getByUUID(element.getId());
overwrittenElement = repository.getByUUID(element.getId());
} catch (IllegalArgumentException e) {
logger.info(
format("Imported artifact %s does not have an uuid attribute and its id does not have the UUID format."
+ "A new UUID will be generated by the migration so it will not replace another artifact.", element.getId()));
}
}
if (overridenElement != null) {
setOverriden(report, overridenElement.getId());
if (overwrittenElement != null) {
setOverwritten(report, overwrittenElement.getId());
}
}
private void setOverriden(ImportReport report, String elementId) {
report.setOverridden(true);
report.setElement(repository.get(elementId));
private void setOverwritten(ImportReport report, String elementId) {
report.setOverwritten(true);
report.setOverwrittenElement(repository.get(elementId));
}
private void saveArtefactDependencies(Path resources, Map<DependencyImporter, List<?>> map) {
......
......@@ -26,7 +26,7 @@ import org.bonitasoft.web.designer.model.Identifiable;
public class Dependencies {
private Map<String, List<Object>> added;
private Map<String, List<Object>> overridden;
private Map<String, List<Object>> overwritten;
public static Dependencies from(Map<DependencyImporter, List<?>> dependenciesAsList) {
Dependencies dependencies = new Dependencies();
......@@ -42,7 +42,7 @@ public class Dependencies {
private void add(List<Identifiable> identifiables, ComponentDependencyImporter importer) {
for (Identifiable identifiable : identifiables) {
if (importer.exists(identifiable)) {
addOverriddenDependency(importer.getComponentName(), importer.getOriginalElementFromRepository(identifiable));
addOverwrittenDependency(importer.getComponentName(), importer.getOriginalElementFromRepository(identifiable));
} else {
addAddedDependency(importer.getComponentName(), identifiable);
}
......@@ -53,12 +53,12 @@ public class Dependencies {
return added;
}
public Map<String, List<Object>> getOverridden() {
return overridden;
public Map<String, List<Object>> getOverwritten() {
return overwritten;
}
public void addOverriddenDependency(String componentName, Object dependency) {
overridden = addDependency(overridden, componentName, dependency);
public void addOverwrittenDependency(String componentName, Object dependency) {
overwritten = addDependency(overwritten, componentName, dependency);
}
public void addAddedDependency(String componentName, Object dependency) {
......
......@@ -28,7 +28,8 @@ public class ImportReport {
private Status status;
private Identifiable element;
private Boolean overridden = false;
private Identifiable overwrittenElement;
private Boolean overwritten = false;
private Dependencies dependencies;
private String uuid;
......@@ -49,12 +50,20 @@ public class ImportReport {
return element;
}
public Boolean isOverridden() {
return overridden;
public void setOverwrittenElement(Identifiable overwrittenElement) {
this.overwrittenElement = overwrittenElement;
}
public void setOverridden(Boolean overridden) {
this.overridden = overridden;
public Identifiable getOverwrittenElement() {
return overwrittenElement;
}
public Boolean isOverwritten() {
return overwritten;
}
public void setOverwritten(Boolean overwritten) {
this.overwritten = overwritten;
}
public Dependencies getDependencies() {
......@@ -74,8 +83,8 @@ public class ImportReport {
}
@JsonIgnore
public boolean doesNotOverrideElements() {
return !this.isOverridden() && (this.getDependencies().getOverridden() == null || this.getDependencies().getOverridden().isEmpty());
public boolean doesNotOverwriteElements() {
return !this.isOverwritten() && (this.getDependencies().getOverwritten() == null || this.getDependencies().getOverwritten().isEmpty());
}
public Status getStatus() {
......
......@@ -26,11 +26,11 @@ public class ImportReportBuilder {
private Identifiable element;
List<Identifiable> added = new ArrayList<>();
List<Identifiable> overridden = new ArrayList<>();
List<Identifiable> overwritten = new ArrayList<>();
private String uuid;
private ImportReport.Status status;
private boolean override;
private boolean overwrite;
public ImportReportBuilder(Identifiable element) {
this.element = element;
......@@ -49,8 +49,8 @@ public class ImportReportBuilder {
return this;
}
public ImportReportBuilder withOverridden(WidgetBuilder builder) {
overridden.add(builder.build());
public ImportReportBuilder withOverwritten(WidgetBuilder builder) {
overwritten.add(builder.build());
return this;
}
......@@ -59,8 +59,8 @@ public class ImportReportBuilder {
return this;
}
public ImportReportBuilder withOverride(boolean override) {
this.override = override;
public ImportReportBuilder withOverwrite(boolean overwrite) {
this.overwrite = overwrite;
return this;
}
......@@ -74,12 +74,12 @@ public class ImportReportBuilder {
for (Identifiable identifiable : added) {
dependencies.addAddedDependency(identifiable.getClass().getSimpleName().toLowerCase(Locale.ENGLISH), identifiable);
}
for (Identifiable identifiable : overridden) {
dependencies.addOverriddenDependency(identifiable.getClass().getSimpleName().toLowerCase(Locale.ENGLISH), identifiable);
for (Identifiable identifiable : overwritten) {
dependencies.addOverwrittenDependency(identifiable.getClass().getSimpleName().toLowerCase(Locale.ENGLISH), identifiable);
}
ImportReport importReport = new ImportReport(element, dependencies);
importReport.setUUID(uuid);
importReport.setOverridden(override);
importReport.setOverwritten(overwrite);
importReport.setStatus(status);
return importReport;
}
......
......@@ -154,7 +154,7 @@ public class ImportControllerTest {
ImportReport expectedReport =
anImportReportFor(aPage().withId("aPage").withName("thePage")).withUUID("UUIDZipFile").withStatus(ImportReport.Status.CONFLICT)
.withAdded(aWidget().id("addedWidget").name("newWidget"))
.withOverridden(aWidget().id("overriddenWidget").name("oldWidget")).build();
.withOverwritten(aWidget().id("overwrittenWidget").name("oldWidget")).build();
when(pathImporter.importFromPath(unzipedPath, pageImporter)).thenReturn(expectedReport);
mockMvc.perform(fileUpload("/import/page").file(file))
......@@ -167,8 +167,8 @@ public class ImportControllerTest {
.andExpect(jsonPath("element.name").value("thePage"))
.andExpect(jsonPath("dependencies.added.widget[0].id").value("addedWidget"))
.andExpect(jsonPath("dependencies.added.widget[0].name").value("newWidget"))
.andExpect(jsonPath("dependencies.overridden.widget[0].id").value("overriddenWidget"))
.andExpect(jsonPath("dependencies.overridden.widget[0].name").value("oldWidget"));
.andExpect(jsonPath("dependencies.overwritten.widget[0].id").value("overwrittenWidget"))
.andExpect(jsonPath("dependencies.overwritten.widget[0].name").value("oldWidget"));
}
@Test
......@@ -178,7 +178,7 @@ public class ImportControllerTest {
ImportReport expectedReport =
anImportReportFor(aPage().withId("aPage").withName("thePage")).withUUID("UUIDZipFile").withStatus(ImportReport.Status.IMPORTED)
.withAdded(aWidget().id("addedWidget").name("newWidget"))
.withOverridden(aWidget().id("overriddenWidget").name("oldWidget")).build();
.withOverwritten(aWidget().id("overwrittenWidget").name("oldWidget")).build();
when(pathImporter.forceImportFromPath(unzipedPath, pageImporter)).thenReturn(expectedReport);
mockMvc.perform(fileUpload("/import/page?force=true").file(file))
......@@ -191,8 +191,8 @@ public class ImportControllerTest {
.andExpect(jsonPath("element.name").value("thePage"))
.andExpect(jsonPath("dependencies.added.widget[0].id").value("addedWidget"))
.andExpect(jsonPath("dependencies.added.widget[0].name").value("newWidget"))
.andExpect(jsonPath("dependencies.overridden.widget[0].id").value("overriddenWidget"))
.andExpect(jsonPath("dependencies.overridden.widget[0].name").value("oldWidget"));
.andExpect(jsonPath("dependencies.overwritten.widget[0].id").value("overwrittenWidget"))
.andExpect(jsonPath("dependencies.overwritten.widget[0].name").value("oldWidget"));
}
@Test
......
......@@ -115,12 +115,12 @@ public class ArtifactImporterTest {
ImportReport report = pageImporter.doImport(anImport(pageImportPath));
assertThat(report.getDependencies().getAdded().get("widget")).isEqualTo(addedWidgets);
assertThat(report.getDependencies().getOverridden().get("widget")).isEqualTo(overridenWidgets);
assertThat(report.getDependencies().getOverwritten().get("widget")).isEqualTo(overridenWidgets);
assertThat(report.getElement()).isEqualTo(page);
}
@Test
public void should_return_an_import_report_saying_that_page_is_going_to_be_when_element_already_exists_in_repository() throws Exception {
public void should_return_an_import_report_saying_that_page_is_going_to_be_overwritten_when_element_already_exists_in_repository() throws Exception {
Page page = pMocks.mockPageToBeImported();
Page existingPageInRepo = aPage().withUUID(page.getUUID()).withName("alreadyHere").build();
when(pageRepository.getByUUID(page.getUUID())).thenReturn(existingPageInRepo);
......@@ -128,12 +128,13 @@ public class ArtifactImporterTest {
ImportReport report = pageImporter.doImport(anImport(pageImportPath));
assertThat(report.getElement()).isEqualTo(existingPageInRepo);
assertThat(report.isOverridden()).isTrue();
assertThat(report.getElement()).isEqualTo(page);
assertThat(report.getOverwrittenElement()).isEqualTo(existingPageInRepo);
assertThat(report.isOverwritten()).isTrue();
}
@Test
public void should_return_an_import_report_saying_that_widget_is_going_to_be_overridden_when_element_already_exists_in_repository() throws Exception {
public void should_return_an_import_report_saying_that_widget_is_going_to_be_overwritten_when_element_already_exists_in_repository() throws Exception {
Widget widget = aWidget().id("aWidget").custom().build();
Widget existingWidgetInRepo = aWidget().id("aWidget").favorite().custom().build();
when(widgetLoader.load(widgetUnzippedPath.resolve("widget.json"))).thenReturn(widget);
......@@ -143,18 +144,19 @@ public class ArtifactImporterTest {
ImportReport report = widgetImporter.doImport(anImport(widgetImportPath));
assertThat(report.getElement()).isEqualTo(existingWidgetInRepo);
assertThat(report.isOverridden()).isTrue();
assertThat(report.isOverwritten()).isTrue();
}
@Test
public void should_return_an_import_report_saying_that_element_has_not_been_overridden_when_element_does_not_exists_in_repository() throws Exception {
public void should_return_an_import_report_saying_that_element_has_not_been_overwritten_when_element_does_not_exists_in_repository() throws Exception {
Page page = pMocks.mockPageToBeImported();
when(pageRepository.getByUUID(page.getUUID())).thenReturn(null);
ImportReport report = pageImporter.doImport(anImport(pageImportPath));
assertThat(report.getElement()).isEqualTo(page);
assertThat(report.isOverridden()).isFalse();
assertThat(report.isOverwritten()).isFalse();
assertThat(report.getOverwrittenElement()).isNull();
}
@Test
......@@ -223,7 +225,7 @@ public class ArtifactImporterTest {
ImportReport report = pageImporter.forceImport(anImport);
assertThat(report.getDependencies().getAdded().get("widget")).isEqualTo(addedWidgets);
assertThat(report.getDependencies().getOverridden().get("widget")).isEqualTo(overriddenWidgets);
assertThat(report.getDependencies().getOverwritten().get("widget")).isEqualTo(overriddenWidgets);
assertThat(report.getElement()).isEqualTo(page);
assertThat(report.getUUID()).isEqualTo(anImport.getUUID());
assertThat(report.getStatus()).isEqualTo(ImportReport.Status.IMPORTED);
......@@ -243,8 +245,8 @@ public class ArtifactImporterTest {
ImportReport report = pageImporter.forceImport(anImport);
assertThat(report.getElement()).isEqualTo(existingPageInRepo);
assertThat(report.isOverridden()).isTrue();
assertThat(report.getOverwrittenElement()).isEqualTo(existingPageInRepo);
assertThat(report.isOverwritten()).isTrue();
assertThat(report.getStatus()).isEqualTo(ImportReport.Status.IMPORTED);
assertThat(page.getId()).isEqualTo("id");
verify(pageRepository).delete(existingPageInRepo.getId());
......@@ -265,8 +267,8 @@ public class ArtifactImporterTest {
ImportReport report = pageImporter.forceImport(anImport);
assertThat(report.getElement()).isEqualTo(existingPageInRepo);
assertThat(report.isOverridden()).isTrue();
assertThat(report.getOverwrittenElement()).isEqualTo(existingPageInRepo);
assertThat(report.isOverwritten()).isTrue();
assertThat(report.getStatus()).isEqualTo(ImportReport.Status.IMPORTED);
assertThat(page.getId()).isEqualTo("myPage1");
verify(pageRepository).delete(existingPageInRepo.getId());
......
......@@ -84,7 +84,7 @@ public class ImportReportTest {
ImportReport report = ImportReport.from(aPage().build(), dependencies);
assertThat(report.getDependencies().getAdded().get("widget")).containsOnly(newWidget);
assertThat(report.getDependencies().getOverridden().get("widget")).containsOnly(existingWidget);
assertThat(report.getDependencies().getOverwritten().get("widget")).containsOnly(existingWidget);
}
@Test
......@@ -95,6 +95,6 @@ public class ImportReportTest {
ImportReport report = ImportReport.from(aPage().build(), dependencies);
assertThat(report.getDependencies().getAdded()).isNull();
assertThat(report.getDependencies().getOverridden()).isNull();
assertThat(report.getDependencies().getOverwritten()).isNull();
}
}
......@@ -22,7 +22,6 @@
return {
templateUrl: 'js/home/import/import-report-item-list.html',
scope: {
pageName: '=',
type: '=',
displayPage: '=',
dependencies: '='
......
<ul>
<li ng-if="displayPage" class="ImportReport-page">
<span class="text-muted">
<i class="ui-icon ui-pages"></i>
<translate class="ImportReport-type">{{ type }}</translate>
</span>
{{ pageName }}
</li>
<li ng-repeat="(artifactType, artifacts) in dependencies">
<span class="text-muted">
<i class="ui-icon ui-{{artifactType}}s"></i>
......@@ -14,6 +7,6 @@
class="ImportReport-type">{{ artifactType }}
</translate>
</span>
{{ joinOnNames(artifacts) }}
<strong>{{ joinOnNames(artifacts) }}</strong>
</li>
</ul>
......@@ -34,7 +34,11 @@
}
hasDependencies() {
return this.report.dependencies && this.report.dependencies.added || this.report.dependencies.overridden;
return this.report.dependencies && (this.report.dependencies.added || this.report.dependencies.overwritten);
}
isPageImport() {
return this.report.element.type === 'page' || this.report.element.type === 'form' || this.report.element.type === 'layout';
}
get type() {
......@@ -44,6 +48,14 @@
get name() {
return this.report.element.name;
}
get overwrittenType() {
return this.report.overwrittenElement.type;
}
get overwrittenName() {
return this.report.overwrittenElement.name;
}
}
angular
......
......@@ -3,18 +3,29 @@
<h3 class="modal-title"><i class="fa fa-exclamation-triangle text-warning "></i><translate>Import {{ ::importReport.name }}</translate></h3>
</div>
<div class="modal-body">
<p ng-if="importReport.report.overwritten && importReport.isPageImport()">
<translate>A {{ ::importReport.overwrittenType }} with the same identifier as <strong>{{ ::importReport.name }}</strong> already exists.</translate><br/>
<translate>The {{ ::importReport.overwrittenType }} <strong>{{ ::importReport.overwrittenName }}</strong> will be overwritten.</translate><br/>
<translate>To save <strong>{{ ::importReport.overwrittenName }}</strong> with a different identifier, open it and use <i>Save as</i> before you import.</translate>
</p>
<p ng-if="importReport.report.overwritten && !importReport.isPageImport()">
<translate>A {{ ::importReport.overwrittenType }} with the same Id as <strong>{{ ::importReport.name }}</strong> already exists.</translate><br/>
<translate>Id must be unique, so the {{ ::importReport.overwrittenType }} <strong>{{ ::importReport.overwrittenName }}</strong> will be overwritten.</translate><br/>
<translate>To save <strong>{{ ::importReport.overwrittenName }}</strong> with a different identifier, <i>rename</i> it before you import.</translate>
</p>
<div ng-if="importReport.hasDependencies()">
<translate>The imported {{ ::importReport.type }} contains elements with the same id as some existing elements.</translate>
<translate>The {{ ::importReport.type }} to import contains elements with the same Id as some existing elements.</translate>
<import-report-item-list page-name="importReport.name"
type="importReport.type"
display-page="importReport.report.overridden"
dependencies="importReport.report.dependencies.overridden">
dependencies="importReport.report.dependencies.overwritten">
</import-report-item-list>
<p>
<translate>Id must be unique, so those elements will be overwritten.</translate><br/>
<translate>To save them with different ids, open them and use <i>Save as</i>, before you import.</translate>
<translate>To avoid them being overwritten, <i>rename</i> them before you import.</translate>
</p>
<div ng-if="!importReport.report.overridden || importReport.report.dependencies.added">
<div ng-if="importReport.report.dependencies.added">
<p>
<translate>The imported {{ ::importReport.type }} also contains new elements.</translate>
<span ng-click="showDetails = !showDetails" class="clickable ImportReport--smallAndUnderlined">
......@@ -26,19 +37,12 @@
<div uib-collapse="!showDetails">
<import-report-item-list page-name="importReport.name"
type="importReport.type"
display-page="!importReport.report.overridden"
dependencies="importReport.report.dependencies.added">
</import-report-item-list>
</div>
</div>
</div>
<p ng-if="!importReport.hasDependencies()">
<translate>A {{ ::importReport.type }} with same id named <strong>{{ ::importReport.name }}</strong> already exists.</translate><br/>
<translate>Id must be unique, so the {{ ::importReport.type }} {{ ::importReport.name }} will be overwritten.</translate><br/>
<translate>To save {{ ::importReport.name }} with a different id, open it and use <i>Save as</i> before you import.</translate>
</p>
<p translate>Do you still want to import this {{ ::importReport.type }} now ?</p>
</div>
<div class="modal-footer">
......
......@@ -32,8 +32,8 @@
}
function getState() {
if ($scope.overridden) {
return gettextCatalog.getString('overridden');
if ($scope.overwritten) {
return gettextCatalog.getString('overwritten');
}
return gettextCatalog.getString('added');
}
......
<div class="ImportReport" ng-controller="ImportSuccessMessageController as import">
<p><span class="ImportReport-type">{{ type | translate }}</span> <strong>{{ element.name }}</strong>
<translate>successfully imported.</translate>
<translate>successfully imported.</translate>
</p>
<section class="ImportReport-added" ng-if="dependencies.added">
<translate>Added artifacts</translate>:
<import-report-item-list page-name="element.name" type="type" display-page="!overridden" dependencies="dependencies.added"></import-report-item-list>
<import-report-item-list page-name="element.name" type="type" display-page="!overwritten" dependencies="dependencies.added"></import-report-item-list>
</section>
<section class="ImportReport-overridden" ng-if="dependencies.overridden">
<section class="ImportReport-overwritten" ng-if="dependencies.overwritten">
<translate>Overridden artifacts</translate>:
<import-report-item-list page-name="element.name" type="type" display-page="overridden" dependencies="dependencies.overridden"></import-report-item-list>
<import-report-item-list page-name="element.name" type="type" display-page="overwritten" dependencies="dependencies.overwritten"></import-report-item-list>
</section>
</div>
......@@ -26,7 +26,7 @@
forceImport,
isErrorResponse,
manageImportResponse,
doesImportOverrideExistingContent
doesImportOverwriteExistingContent
};
return service;
......@@ -34,7 +34,7 @@
return response && response.type && response.message;
}
function manageImportResponse(type, checkForOverrides, response) {
function manageImportResponse(type, checkForOverwrites, response) {
var deferred = $q.defer();
//Even if a problem occurs in the backend a response is sent with a message
//If the message has a type and a message this is an error
......@@ -50,7 +50,7 @@
var importReportContext = angular.extend(response, {
type: response.element.type || 'widget' // TODO remove this when widget has type
});
if (!checkForOverrides || service.doesImportOverrideExistingContent(response)) {
if (!checkForOverwrites || service.doesImportOverwriteExistingContent(response)) {
//
alerts.addSuccess({
title: gettextCatalog.getString('Successful import'),
......@@ -65,8 +65,8 @@
return deferred.promise;
}
function doesImportOverrideExistingContent(report) {
return !(report.overridden || (report.dependencies && report.dependencies.overridden));
function doesImportOverwriteExistingContent(report) {
return !(report.overwritten || (report.dependencies && report.dependencies.overwritten));
}
function forceImport(report) {
......
......@@ -3,7 +3,7 @@ describe('importReportItemList directive', () => {
beforeEach(angular.mock.module('bonitasoft.designer.home.import'));
beforeEach(inject(($rootScope, $compile) => {
scope = $rootScope.$new();
var markup = '<import-report-item-list page-name="element.name" type="type" display-page="!overridden" dependencies="dependencies.added"></import-report-item-list> ';
var markup = '<import-report-item-list page-name="element.name" type="type" display-page="!overwritten" dependencies="dependencies.added"></import-report-item-list> ';
var element = $compile(markup)(scope);
scope.$apply();
scope = element.isolateScope();
......
......@@ -61,7 +61,7 @@ describe('Import artifact report controller', () => {
expect(importArtifactReportCtrl.hasDependencies()).toBeTruthy();
importArtifactReportCtrl.report = {
dependencies: {overridden: ['anelement']}
dependencies: {overwritten: ['anelement']}
};
expect(importArtifactReportCtrl.hasDependencies()).toBeTruthy();
});
......
......@@ -23,16 +23,16 @@ describe('Import Success Message Controller', function() {
expect(names).toBe('first, second');
});
it('should get overridden state when element has been overridden', function() {
scope.overridden = true;
it('should get overwritten state when element has been overwritten', function() {
scope.overwritten = true;
var state = controller.getState();
expect(state).toBe('overridden');
expect(state).toBe('overwritten');
});
it('should get added state when element has been added', function() {
scope.overridden = false;
scope.overwritten = false;
var state = controller.getState();
......
......@@ -22,20 +22,20 @@ describe('ImportArtifactSuccessMessageTemplate', function() {
element: {
name: 'pageName'
},
overridden: false
overwritten: false
});
scope.$apply();
expect(hardTrim(element.find('p').first().text())).toBe('page pageName successfully imported.');
});
it('should print to user that element has been overridden', function() {
it('should print to user that element has been overwritten', function() {
angular.extend(scope, {
type: 'page',
element: {
name: 'pageName'
},
overridden: true
overwritten: true
});
scope.$apply();
......@@ -56,7 +56,7 @@ describe('ImportArtifactSuccessMessageTemplate', function() {
it('should display added dependencies', function() {
angular.extend(scope, {
element: { name: 'aPage' },
overridden: false,
overwritten: false,
dependencies: {
added: {
page: [{ name: 'anotherPage' }],
......@@ -67,12 +67,11 @@ describe('ImportArtifactSuccessMessageTemplate', function() {
scope.$apply();
expect(element.find('section.ImportReport-added').length).toBe(1);
expect(hardTrim(element.find('section.ImportReport-added ul li').first().text())).toBe('aPage');
expect(hardTrim(element.find('section.ImportReport-added ul li').next().first().text())).toBe('page anotherPage');
expect(hardTrim(element.find('section.ImportReport-added ul li').next().next().text())).toBe('widget aWidget');
expect(hardTrim(element.find('section.ImportReport-added ul li').first().text())).toBe('page anotherPage');
expect(hardTrim(element.find('section.ImportReport-added ul li').next().text())).toBe('widget aWidget');
});
it('should not display overridden dependencies section when no dependencies are overridden', function() {
it('should not display overwritten dependencies section when no dependencies are overwritten', function() {
angular.extend(scope, {
dependencies: {
......@@ -80,13 +79,13 @@ describe('ImportArtifactSuccessMessageTemplate', function() {
});
scope.$apply();
expect(element.find('section.ImportReport-overridden').length).toBe(0);
expect(element.find('section.ImportReport-overwritten').length).toBe(0);
});
it('should display overridden dependencies', function() {
it('should display overwritten dependencies', function() {
angular.extend(scope, {
dependencies: {
overridden: {
overwritten: {
page: [{ name: 'aPage' }, { name: 'anotherPage' }],
widget: [{ name: 'aWidget' }]
}
......@@ -94,8 +93,8 @@ describe('ImportArtifactSuccessMessageTemplate', function() {
});
scope.$apply();
expect(element.find('section.ImportReport-overridden').length).toBe(1);
expect(hardTrim(element.find('section.ImportReport-overridden ul li').first().text())).toBe('pages aPage, anotherPage');
expect(hardTrim(element.find('section.ImportReport-overridden ul li').next().text())).toBe('widget aWidget');
expect(element.find('section.ImportReport-overwritten').length).toBe(1);
expect(hardTrim(element.find('section.ImportReport-overwritten ul li').first().text())).toBe('pages aPage, anotherPage');
expect(hardTrim(element.find('section.ImportReport-overwritten ul li').next().text())).toBe('widget aWidget');
});
});
......@@ -54,9 +54,9 @@ describe('Import service', () => {
context: errorToDisplay });
});
it('should resolve response processing when override is false ', function() {
it('should resolve response processing when overwritten is false ', function() {
var report = {
overridden: false,
overwritten: false,
element: { type: 'page' }
};