|
| 1 | +import { setupTest } from 'ember-qunit'; |
| 2 | +import { module, test } from 'qunit'; |
| 3 | + |
| 4 | +import createGlimmerComponent from '../../../../../helpers/create-glimmer-component'; |
| 5 | + |
| 6 | +module('Unit | Component | Campaigns | Assessment | Results | Hero | Custom Organization Block', function (hooks) { |
| 7 | + setupTest(hooks); |
| 8 | + |
| 9 | + module('#customButtonUrl', function () { |
| 10 | + module('when there is no custom link', function () { |
| 11 | + test('should return null', async function (assert) { |
| 12 | + // given |
| 13 | + const store = this.owner.lookup('service:store'); |
| 14 | + |
| 15 | + const component = createGlimmerComponent( |
| 16 | + 'campaigns/assessment/results/evaluation-results-hero/custom-organization-block', |
| 17 | + ); |
| 18 | + |
| 19 | + component.args.campaign = store.createRecord('campaign', { |
| 20 | + customResultPageButtonUrl: null, |
| 21 | + customResultPageButtonText: 'useless label', |
| 22 | + }); |
| 23 | + |
| 24 | + // when |
| 25 | + const url = component.customButtonUrl; |
| 26 | + |
| 27 | + // then |
| 28 | + assert.strictEqual(url, null); |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + module('when there is a custom link', function () { |
| 33 | + test('should return the custom link', async function (assert) { |
| 34 | + // given |
| 35 | + const store = this.owner.lookup('service:store'); |
| 36 | + |
| 37 | + const component = createGlimmerComponent( |
| 38 | + 'campaigns/assessment/results/evaluation-results-hero/custom-organization-block', |
| 39 | + ); |
| 40 | + |
| 41 | + component.args.campaign = store.createRecord('campaign', { |
| 42 | + customResultPageButtonUrl: 'https://pix.org/', |
| 43 | + customResultPageButtonText: 'custom label', |
| 44 | + }); |
| 45 | + component.args.campaignParticipationResult = store.createRecord('campaign-participation-result', {}); |
| 46 | + |
| 47 | + // when |
| 48 | + const url = component.customButtonUrl; |
| 49 | + |
| 50 | + // then |
| 51 | + assert.strictEqual(url, 'https://pix.org/'); |
| 52 | + }); |
| 53 | + |
| 54 | + module('when there is a mastery rate', function () { |
| 55 | + test('should return the custom link with a rounded mastery percentage search param', async function (assert) { |
| 56 | + // given |
| 57 | + const store = this.owner.lookup('service:store'); |
| 58 | + |
| 59 | + const component = createGlimmerComponent( |
| 60 | + 'campaigns/assessment/results/evaluation-results-hero/custom-organization-block', |
| 61 | + ); |
| 62 | + |
| 63 | + component.args.campaign = store.createRecord('campaign', { |
| 64 | + customResultPageButtonUrl: 'https://pix.org/', |
| 65 | + customResultPageButtonText: 'custom label', |
| 66 | + }); |
| 67 | + component.args.campaignParticipationResult = store.createRecord('campaign-participation-result', { |
| 68 | + masteryRate: 0.755, |
| 69 | + }); |
| 70 | + |
| 71 | + // when |
| 72 | + const url = component.customButtonUrl; |
| 73 | + |
| 74 | + // then |
| 75 | + assert.strictEqual(url, 'https://pix.org/?masteryPercentage=76'); |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + module('when there is an external id', function () { |
| 80 | + test('should return the custom link with external id search param', async function (assert) { |
| 81 | + // given |
| 82 | + const store = this.owner.lookup('service:store'); |
| 83 | + |
| 84 | + const component = createGlimmerComponent( |
| 85 | + 'campaigns/assessment/results/evaluation-results-hero/custom-organization-block', |
| 86 | + ); |
| 87 | + |
| 88 | + component.args.campaign = store.createRecord('campaign', { |
| 89 | + customResultPageButtonUrl: 'https://pix.org/', |
| 90 | + customResultPageButtonText: 'custom label', |
| 91 | + }); |
| 92 | + component.args.campaignParticipationResult = store.createRecord('campaign-participation-result', { |
| 93 | + participantExternalId: 'externalId', |
| 94 | + }); |
| 95 | + |
| 96 | + // when |
| 97 | + const url = component.customButtonUrl; |
| 98 | + |
| 99 | + // then |
| 100 | + assert.strictEqual(url, 'https://pix.org/?externalId=externalId'); |
| 101 | + }); |
| 102 | + }); |
| 103 | + |
| 104 | + module('when there is a stage', function () { |
| 105 | + test('should return the custom link with stage threshold search param', async function (assert) { |
| 106 | + // given |
| 107 | + const store = this.owner.lookup('service:store'); |
| 108 | + |
| 109 | + const component = createGlimmerComponent( |
| 110 | + 'campaigns/assessment/results/evaluation-results-hero/custom-organization-block', |
| 111 | + ); |
| 112 | + |
| 113 | + component.args.campaign = store.createRecord('campaign', { |
| 114 | + customResultPageButtonUrl: 'https://pix.org/', |
| 115 | + customResultPageButtonText: 'custom label', |
| 116 | + }); |
| 117 | + const reachedStage = store.createRecord('reached-stage', { |
| 118 | + threshold: 5, |
| 119 | + }); |
| 120 | + component.args.campaignParticipationResult = store.createRecord('campaign-participation-result', { |
| 121 | + reachedStage, |
| 122 | + }); |
| 123 | + |
| 124 | + // when |
| 125 | + const url = component.customButtonUrl; |
| 126 | + |
| 127 | + // then |
| 128 | + assert.strictEqual(url, 'https://pix.org/?stage=5'); |
| 129 | + }); |
| 130 | + }); |
| 131 | + |
| 132 | + module('when there is all parameters', function () { |
| 133 | + test('should return the custom link with all parameters', async function (assert) { |
| 134 | + // given |
| 135 | + const store = this.owner.lookup('service:store'); |
| 136 | + |
| 137 | + const component = createGlimmerComponent( |
| 138 | + 'campaigns/assessment/results/evaluation-results-hero/custom-organization-block', |
| 139 | + ); |
| 140 | + |
| 141 | + component.args.campaign = store.createRecord('campaign', { |
| 142 | + customResultPageButtonUrl: 'https://pix.org/', |
| 143 | + customResultPageButtonText: 'custom label', |
| 144 | + }); |
| 145 | + const reachedStage = store.createRecord('reached-stage', { |
| 146 | + threshold: 5, |
| 147 | + }); |
| 148 | + component.args.campaignParticipationResult = store.createRecord('campaign-participation-result', { |
| 149 | + reachedStage, |
| 150 | + masteryRate: 0.75, |
| 151 | + participantExternalId: 'externalId', |
| 152 | + }); |
| 153 | + |
| 154 | + // when |
| 155 | + const url = component.customButtonUrl; |
| 156 | + |
| 157 | + // then |
| 158 | + assert.strictEqual(url, 'https://pix.org/?masteryPercentage=75&externalId=externalId&stage=5'); |
| 159 | + }); |
| 160 | + }); |
| 161 | + }); |
| 162 | + }); |
| 163 | +}); |
0 commit comments