mirror of
https://github.com/nasa/openmct.git
synced 2025-05-29 13:44:21 +00:00
Merge pull request #219 from nasa/open213
[Mobile] Don't move DOM nodes
This commit is contained in:
commit
a356e01b14
@ -85,7 +85,7 @@ define(
|
|||||||
function link(scope, element, attrs, ctrl, transclude) {
|
function link(scope, element, attrs, ctrl, transclude) {
|
||||||
if (deviceMatches(attrs.mctDevice)) {
|
if (deviceMatches(attrs.mctDevice)) {
|
||||||
transclude(function (clone) {
|
transclude(function (clone) {
|
||||||
element.parent().append(clone);
|
element.replaceWith(clone);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,13 +26,12 @@ define(
|
|||||||
function (MCTDevice) {
|
function (MCTDevice) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var JQLITE_METHODS = [ 'parent', 'append' ];
|
var JQLITE_METHODS = [ 'replaceWith' ];
|
||||||
|
|
||||||
describe("The mct-device directive", function () {
|
describe("The mct-device directive", function () {
|
||||||
var mockAgentService,
|
var mockAgentService,
|
||||||
mockTransclude,
|
mockTransclude,
|
||||||
mockElement,
|
mockElement,
|
||||||
mockParent,
|
|
||||||
mockClone,
|
mockClone,
|
||||||
testAttrs,
|
testAttrs,
|
||||||
directive;
|
directive;
|
||||||
@ -48,11 +47,8 @@ define(
|
|||||||
);
|
);
|
||||||
mockTransclude = jasmine.createSpy("$transclude");
|
mockTransclude = jasmine.createSpy("$transclude");
|
||||||
mockElement = jasmine.createSpyObj(name, JQLITE_METHODS);
|
mockElement = jasmine.createSpyObj(name, JQLITE_METHODS);
|
||||||
mockParent = jasmine.createSpyObj(name, JQLITE_METHODS);
|
|
||||||
mockClone = jasmine.createSpyObj(name, JQLITE_METHODS);
|
mockClone = jasmine.createSpyObj(name, JQLITE_METHODS);
|
||||||
|
|
||||||
mockElement.parent.andReturn(mockParent);
|
|
||||||
|
|
||||||
mockTransclude.andCallFake(function (fn) {
|
mockTransclude.andCallFake(function (fn) {
|
||||||
fn(mockClone);
|
fn(mockClone);
|
||||||
});
|
});
|
||||||
@ -65,6 +61,15 @@ define(
|
|||||||
directive = new MCTDevice(mockAgentService);
|
directive = new MCTDevice(mockAgentService);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function expectInclusion() {
|
||||||
|
expect(mockElement.replaceWith)
|
||||||
|
.toHaveBeenCalledWith(mockClone);
|
||||||
|
}
|
||||||
|
|
||||||
|
function expectExclusion() {
|
||||||
|
expect(mockElement.replaceWith).not.toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
|
||||||
it("is applicable at the attribute level", function () {
|
it("is applicable at the attribute level", function () {
|
||||||
expect(directive.restrict).toEqual("A");
|
expect(directive.restrict).toEqual("A");
|
||||||
});
|
});
|
||||||
@ -80,54 +85,54 @@ define(
|
|||||||
it("restricts element inclusion for mobile devices", function () {
|
it("restricts element inclusion for mobile devices", function () {
|
||||||
testAttrs.mctDevice = "mobile";
|
testAttrs.mctDevice = "mobile";
|
||||||
link();
|
link();
|
||||||
expect(mockParent.append).not.toHaveBeenCalled();
|
expectExclusion();
|
||||||
|
|
||||||
mockAgentService.isMobile.andReturn(true);
|
mockAgentService.isMobile.andReturn(true);
|
||||||
link();
|
link();
|
||||||
expect(mockParent.append).toHaveBeenCalledWith(mockClone);
|
expectInclusion();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("restricts element inclusion for tablet devices", function () {
|
it("restricts element inclusion for tablet devices", function () {
|
||||||
testAttrs.mctDevice = "tablet";
|
testAttrs.mctDevice = "tablet";
|
||||||
mockAgentService.isMobile.andReturn(true);
|
mockAgentService.isMobile.andReturn(true);
|
||||||
link();
|
link();
|
||||||
expect(mockParent.append).not.toHaveBeenCalled();
|
expectExclusion();
|
||||||
|
|
||||||
mockAgentService.isTablet.andReturn(true);
|
mockAgentService.isTablet.andReturn(true);
|
||||||
link();
|
link();
|
||||||
expect(mockParent.append).toHaveBeenCalledWith(mockClone);
|
expectInclusion();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("restricts element inclusion for phone devices", function () {
|
it("restricts element inclusion for phone devices", function () {
|
||||||
testAttrs.mctDevice = "phone";
|
testAttrs.mctDevice = "phone";
|
||||||
mockAgentService.isMobile.andReturn(true);
|
mockAgentService.isMobile.andReturn(true);
|
||||||
link();
|
link();
|
||||||
expect(mockParent.append).not.toHaveBeenCalled();
|
expectExclusion();
|
||||||
|
|
||||||
mockAgentService.isPhone.andReturn(true);
|
mockAgentService.isPhone.andReturn(true);
|
||||||
link();
|
link();
|
||||||
expect(mockParent.append).toHaveBeenCalledWith(mockClone);
|
expectInclusion();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("restricts element inclusion for desktop devices", function () {
|
it("restricts element inclusion for desktop devices", function () {
|
||||||
testAttrs.mctDevice = "desktop";
|
testAttrs.mctDevice = "desktop";
|
||||||
mockAgentService.isMobile.andReturn(true);
|
mockAgentService.isMobile.andReturn(true);
|
||||||
link();
|
link();
|
||||||
expect(mockParent.append).not.toHaveBeenCalled();
|
expectExclusion();
|
||||||
|
|
||||||
mockAgentService.isMobile.andReturn(false);
|
mockAgentService.isMobile.andReturn(false);
|
||||||
link();
|
link();
|
||||||
expect(mockParent.append).toHaveBeenCalledWith(mockClone);
|
expectInclusion();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("restricts element inclusion for portrait orientation", function () {
|
it("restricts element inclusion for portrait orientation", function () {
|
||||||
testAttrs.mctDevice = "portrait";
|
testAttrs.mctDevice = "portrait";
|
||||||
link();
|
link();
|
||||||
expect(mockParent.append).not.toHaveBeenCalled();
|
expectExclusion();
|
||||||
|
|
||||||
mockAgentService.isPortrait.andReturn(true);
|
mockAgentService.isPortrait.andReturn(true);
|
||||||
link();
|
link();
|
||||||
expect(mockParent.append).toHaveBeenCalledWith(mockClone);
|
expectInclusion();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("restricts element inclusion for landscape orientation", function () {
|
it("restricts element inclusion for landscape orientation", function () {
|
||||||
@ -135,11 +140,11 @@ define(
|
|||||||
mockAgentService.isLandscape.andReturn(false);
|
mockAgentService.isLandscape.andReturn(false);
|
||||||
mockAgentService.isPortrait.andReturn(true);
|
mockAgentService.isPortrait.andReturn(true);
|
||||||
link();
|
link();
|
||||||
expect(mockParent.append).not.toHaveBeenCalled();
|
expectExclusion();
|
||||||
|
|
||||||
mockAgentService.isLandscape.andReturn(true);
|
mockAgentService.isLandscape.andReturn(true);
|
||||||
link();
|
link();
|
||||||
expect(mockParent.append).toHaveBeenCalledWith(mockClone);
|
expectInclusion();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("allows multiple device characteristics to be requested", function () {
|
it("allows multiple device characteristics to be requested", function () {
|
||||||
@ -148,17 +153,17 @@ define(
|
|||||||
testAttrs.mctDevice = "portrait mobile";
|
testAttrs.mctDevice = "portrait mobile";
|
||||||
link();
|
link();
|
||||||
// Neither portrait nor mobile, not called
|
// Neither portrait nor mobile, not called
|
||||||
expect(mockParent.append).not.toHaveBeenCalled();
|
expectExclusion();
|
||||||
|
|
||||||
mockAgentService.isPortrait.andReturn(true);
|
mockAgentService.isPortrait.andReturn(true);
|
||||||
link();
|
link();
|
||||||
|
|
||||||
// Was portrait, but not mobile, so no
|
// Was portrait, but not mobile, so no
|
||||||
expect(mockParent.append).not.toHaveBeenCalled();
|
expectExclusion();
|
||||||
|
|
||||||
mockAgentService.isMobile.andReturn(true);
|
mockAgentService.isMobile.andReturn(true);
|
||||||
link();
|
link();
|
||||||
expect(mockParent.append).toHaveBeenCalledWith(mockClone);
|
expectInclusion();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user