Skip to content

Fixed platform specific attribute setting #376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nativescript-angular/view-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {ValueSource} from "ui/core/dependency-observable";
import {platformNames, Device} from "platform";
import {rendererLog as traceLog, styleError} from "./trace";

const IOS_PREFX: string = "@ios:";
const ANDROID_PREFX: string = "@android:";
const IOS_PREFX: string = ":ios:";
const ANDROID_PREFX: string = ":android:";
const whiteSpaceSplitter = /\s+/;

export type ViewExtensions = ViewExtensions;
Expand Down
40 changes: 34 additions & 6 deletions tests/app/tests/platform-filter-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,24 @@ export class AndroidSpecificComponent {
constructor(public elementRef: ElementRef) { }
}

@Component({
template: `
<StackLayout>
<Label android:text="ANDROID" ios:text="IOS"></Label>
</StackLayout>`
})
export class PlatformSpecificAttributeComponent {
constructor(public elementRef: ElementRef) { }
}

describe('Platofrm filter components', () => {
describe('Platofrm filter directives', () => {
describe('on IOS device', () => {
let testApp: TestApp = null;

before(() => {
return TestApp.create([provide(DEVICE, { useValue: createDevice(platformNames.ios) })]).then((app) => {
testApp = app;
})
});
});

after(() => {
Expand All @@ -59,15 +68,25 @@ describe('Platofrm filter components', () => {
dumpView(componentRoot, true));
});
});
})


it("applies iOS specific attribute", () => {
return testApp.loadComponent(PlatformSpecificAttributeComponent).then((componentRef) => {
const componentRoot = componentRef.instance.elementRef.nativeElement;
assert.equal(
"(ProxyViewContainer (StackLayout (Label[text=IOS])))",
dumpView(componentRoot, true));
});
});
});

describe('on Android device', () => {
let testApp: TestApp = null;

before(() => {
return TestApp.create([provide(DEVICE, { useValue: createDevice(platformNames.android) })]).then((app) => {
testApp = app;
})
});
});

after(() => {
Expand All @@ -91,5 +110,14 @@ describe('Platofrm filter components', () => {
dumpView(componentRoot, true));
});
});
})
})

it("applies Android specific attribute", () => {
return testApp.loadComponent(PlatformSpecificAttributeComponent).then((componentRef) => {
const componentRoot = componentRef.instance.elementRef.nativeElement;
assert.equal(
"(ProxyViewContainer (StackLayout (Label[text=ANDROID])))",
dumpView(componentRoot, true));
});
});
});
});
8 changes: 4 additions & 4 deletions tests/app/tests/property-sets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,28 @@ describe('setting View properties', () => {
it('sets ios property in ios', () => {
let view = new TestView();
let testUtil = new ViewUtil(iosDevice);
testUtil.setProperty(view, "@ios:anyValue", "blah");
testUtil.setProperty(view, ":ios:anyValue", "blah");
assert.strictEqual("blah", view.anyValue);
});

it('doesn\'t set android property in ios', () => {
let view = new TestView();
let testUtil = new ViewUtil(iosDevice);
testUtil.setProperty(view, "@android:anyValue", "blah");
testUtil.setProperty(view, ":android:anyValue", "blah");
assert.isUndefined(view.anyValue);
});

it('sets android property in android', () => {
let view = new TestView();
let testUtil = new ViewUtil(androidDevice);
testUtil.setProperty(view, "@android:anyValue", "blah");
testUtil.setProperty(view, ":android:anyValue", "blah");
assert.strictEqual("blah", view.anyValue);
});

it('doesn\'t set ios property in android', () => {
let view = new TestView();
let testUtil = new ViewUtil(androidDevice);
testUtil.setProperty(view, "@ios:anyValue", "blah");
testUtil.setProperty(view, ":ios:anyValue", "blah");
assert.isUndefined(view.anyValue);
});
});