define([
    'bitbucket/internal/model/page-state'
], function(
    pageState
) {

    'use strict';

    /**
     * NOTE: pageState is only loaded once and cannot be reset between tests.
     * Tests on this page will affect each other.
     */
    module('model-page-state');

    test('properties return undefined when undefined and value when set', function() {

        var val = {};

        strictEqual(pageState.getCurrentUser(), undefined, "currentUser returns undefined");
        pageState.setCurrentUser(val);
        strictEqual(pageState.getCurrentUser(), val, "currentUser returns value");

        strictEqual(pageState.getProject(), undefined, "project returns undefined");
        pageState.setProject(val);
        strictEqual(pageState.getProject(), val, "project returns value");

        strictEqual(pageState.getRepository(), undefined, "repository returns undefined");
        pageState.setRepository(val);
        strictEqual(pageState.getRepository(), val, "repository returns value");

        strictEqual(pageState.getPullRequest(), undefined, "pullRequest returns undefined");
        pageState.setPullRequest(val);
        strictEqual(pageState.getPullRequest(), val, "pullRequest returns value");

        strictEqual(pageState.getBranch(), undefined, "branch returns undefined");
        pageState.setBranch(val);
        strictEqual(pageState.getBranch(), val, "branch returns value");

        strictEqual(pageState.getCommit(), undefined, "commit returns undefined");
        pageState.setCommit(val);
        strictEqual(pageState.getCommit(), val, "commit returns value");

        strictEqual(pageState.getFilePath(), undefined, "file returns undefined");
        pageState.setFilePath(val);
        strictEqual(pageState.getFilePath(), val, "file returns value");

        strictEqual(pageState.getRevisionRef(), undefined, "revisionRef returns undefined");
        pageState.setRevisionRef(val);
        strictEqual(pageState.getRevisionRef(), val, "revisionRef returns value");
    });

    test('extend with no getter or setter', function() {
        var pageState = require('bitbucket/internal/model/page-state');

        strictEqual(pageState.getNewDefaultKey, undefined, "getNewDefaultKey is undefined");
        strictEqual(pageState.setNewDefaultKey, undefined, "setNewDefaultKey is undefined");

        pageState.extend("newDefaultKey");

        var val = {};

        strictEqual(pageState.getNewDefaultKey(), undefined, "newDefaultKey returns undefined");
        pageState.setNewDefaultKey(val);
        strictEqual(pageState.getNewDefaultKey(), val, "newDefaultKey returns value");
    });

    test('extend with only getter', function() {
        var pageState = require('bitbucket/internal/model/page-state');

        strictEqual(pageState.getNewGetterKey, undefined, "getNewGetterKey is undefined");
        strictEqual(pageState.setNewGetterKey, undefined, "setNewGetterKey is undefined");

        var val = {};
        function getter() { return val; }

        pageState.extend("newGetterKey", getter);

        strictEqual(pageState.getNewGetterKey(), val, "newGetterKey returns val");
        strictEqual(pageState.setNewGetterKey, undefined, "setNewGetterKey is undefined");
    });

    test('extend with only setter', function() {
        var pageState = require('bitbucket/internal/model/page-state');

        strictEqual(pageState.getNewSetterKey, undefined, "getNewSetterKey is undefined");
        strictEqual(pageState.setNewSetterKey, undefined, "setNewSetterKey is undefined");

        var val = {};

        var storedVal;
        function setter(value) { storedVal = value; }

        pageState.extend("newSetterKey", undefined, setter);

        strictEqual(pageState.getNewSetterKey, undefined, "getNewSetterKey is undefined");
        pageState.setNewSetterKey(val);
        strictEqual(storedVal, val, "setNewSetterKey is undefined");
    });

    test('extend with getter and setter', function() {
        var pageState = require('bitbucket/internal/model/page-state');

        strictEqual(pageState.getNewGetterSetterKey, undefined, "getNewGetterSetterKey is undefined");
        strictEqual(pageState.setNewGetterSetterKey, undefined, "setNewGetterSetterKey is undefined");

        var val = {};

        var storedVal;
        function getter() { return storedVal; }
        function setter(value) { storedVal = value; }

        pageState.extend("newGetterSetterKey", getter, setter);

        strictEqual(pageState.getNewGetterSetterKey(), undefined, "newGetterSetterKey returns undefined");
        pageState.setNewGetterSetterKey(val);
        strictEqual(pageState.getNewGetterSetterKey(), val, "newGetterSetterKey returns value");
    });
});