blob: 3f35158acb66fae1b5facbfc2619bbc28322bc5d [file] [log] [blame]
<!DOCTYPE html>
<!--
@license
Copyright (C) 2018 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>gr-change-requirements</title>
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<link rel="import" href="../../../test/common-test-setup.html"/>
<link rel="import" href="gr-change-requirements.html">
<script>void(0);</script>
<test-fixture id="basic">
<template>
<gr-change-requirements></gr-change-requirements>
</template>
</test-fixture>
<script>
suite('gr-change-metadata tests', () => {
let element;
setup(() => {
element = fixture('basic');
});
test('requirements computed fields', () => {
assert.isTrue(element._computeShowWip({work_in_progress: true}));
assert.isFalse(element._computeShowWip({work_in_progress: false}));
assert.equal(element._computeRequirementClass(true), 'approved');
assert.equal(element._computeRequirementClass(false), '');
assert.equal(element._computeRequirementIcon(true), 'gr-icons:check');
assert.equal(element._computeRequirementIcon(false),
'gr-icons:hourglass');
});
test('label computed fields', () => {
assert.equal(element._computeLabelIcon({approved: []}), 'gr-icons:check');
assert.equal(element._computeLabelIcon({rejected: []}), 'gr-icons:close');
assert.equal(element._computeLabelIcon({}), 'gr-icons:hourglass');
assert.equal(element._computeLabelClass({approved: []}), 'approved');
assert.equal(element._computeLabelClass({rejected: []}), 'rejected');
assert.equal(element._computeLabelClass({}), '');
assert.equal(element._computeLabelClass({value: 0}), '');
assert.equal(element._computeLabelValue(1), '+1');
assert.equal(element._computeLabelValue(-1), '-1');
assert.equal(element._computeLabelValue(0), '0');
});
test('_computeLabels', () => {
assert.equal(element._optionalLabels.length, 0);
assert.equal(element._requiredLabels.length, 0);
element._computeLabels({base: {
test: {
all: [{_account_id: 1, name: 'bojack', value: 1}],
default_value: 0,
values: [],
value: 1,
},
opt_test: {
all: [{_account_id: 1, name: 'bojack', value: 1}],
default_value: 0,
values: [],
optional: true,
},
}});
assert.equal(element._optionalLabels.length, 1);
assert.equal(element._requiredLabels.length, 1);
assert.equal(element._optionalLabels[0].label, 'opt_test');
assert.equal(element._optionalLabels[0].icon, 'gr-icons:hourglass');
assert.equal(element._optionalLabels[0].style, '');
assert.ok(element._optionalLabels[0].labelInfo);
});
test('optional show/hide', () => {
element._optionalLabels = [{label: 'test'}];
flushAsynchronousOperations();
assert.ok(element.$$('section.optional'));
MockInteractions.tap(element.$$('.showHide'));
flushAsynchronousOperations();
assert.isFalse(element._showOptionalLabels);
assert.isTrue(isHidden(element.$$('section.optional')));
});
test('properly converts satisfied labels', () => {
element.change = {
status: 'NEW',
labels: {
Verified: {
approved: [],
},
},
requirements: [],
};
flushAsynchronousOperations();
assert.ok(element.$$('.approved'));
assert.ok(element.$$('.name'));
assert.equal(element.$$('.name').text, 'Verified');
});
test('properly converts unsatisfied labels', () => {
element.change = {
status: 'NEW',
labels: {
Verified: {
approved: false,
},
},
};
flushAsynchronousOperations();
const name = element.$$('.name');
assert.ok(name);
assert.isFalse(name.hasAttribute('hidden'));
assert.equal(name.text, 'Verified');
});
test('properly displays Work In Progress', () => {
element.change = {
status: 'NEW',
labels: {},
requirements: [],
work_in_progress: true,
};
flushAsynchronousOperations();
const changeIsWip = element.$$('.title');
assert.ok(changeIsWip);
});
test('properly displays a satisfied requirement', () => {
element.change = {
status: 'NEW',
labels: {},
requirements: [{
fallback_text: 'Resolve all comments',
status: 'OK',
}],
};
flushAsynchronousOperations();
const requirement = element.$$('.requirement');
assert.ok(requirement);
assert.isFalse(requirement.hasAttribute('hidden'));
assert.ok(requirement.querySelector('.approved'));
assert.equal(requirement.querySelector('.name').text,
'Resolve all comments');
});
test('satisfied class is applied with OK', () => {
element.change = {
status: 'NEW',
labels: {},
requirements: [{
fallback_text: 'Resolve all comments',
status: 'OK',
}],
};
flushAsynchronousOperations();
const requirement = element.$$('.requirement');
assert.ok(requirement);
assert.ok(requirement.querySelector('.approved'));
});
test('satisfied class is not applied with NOT_READY', () => {
element.change = {
status: 'NEW',
labels: {},
requirements: [{
fallback_text: 'Resolve all comments',
status: 'NOT_READY',
}],
};
flushAsynchronousOperations();
const requirement = element.$$('.requirement');
assert.ok(requirement);
assert.strictEqual(requirement.querySelector('.approved'), null);
});
test('satisfied class is not applied with RULE_ERROR', () => {
element.change = {
status: 'NEW',
labels: {},
requirements: [{
fallback_text: 'Resolve all comments',
status: 'RULE_ERROR',
}],
};
flushAsynchronousOperations();
const requirement = element.$$('.requirement');
assert.ok(requirement);
assert.strictEqual(requirement.querySelector('.approved'), null);
});
});
</script>