2023-03-14 14:18:55 +01:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2020-03-31 18:03:15 +01:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupTest } from 'ember-qunit';
|
|
|
|
|
2022-09-15 10:43:17 +02:00
|
|
|
module('Unit | Service | state', function (hooks) {
|
2020-03-31 18:03:15 +01:00
|
|
|
setupTest(hooks);
|
|
|
|
|
|
|
|
// Replace this with your real tests.
|
2022-09-15 10:43:17 +02:00
|
|
|
test('.state creates a state matchable object', function (assert) {
|
2020-03-31 18:03:15 +01:00
|
|
|
const service = this.owner.lookup('service:state');
|
2022-09-15 10:43:17 +02:00
|
|
|
const actual = service.state((id) => id === 'idle');
|
2020-03-31 18:03:15 +01:00
|
|
|
assert.equal(typeof actual, 'object');
|
|
|
|
assert.equal(typeof actual.matches, 'function');
|
|
|
|
});
|
2022-09-15 10:43:17 +02:00
|
|
|
test('.matches performs a match correctly', function (assert) {
|
2020-03-31 18:03:15 +01:00
|
|
|
const service = this.owner.lookup('service:state');
|
2022-09-15 10:43:17 +02:00
|
|
|
const state = service.state((id) => id === 'idle');
|
2023-02-10 13:32:19 -08:00
|
|
|
assert.true(service.matches(state, 'idle'));
|
|
|
|
assert.false(service.matches(state, 'loading'));
|
2020-03-31 18:03:15 +01:00
|
|
|
});
|
2022-09-15 10:43:17 +02:00
|
|
|
test('.matches performs a match correctly when passed an array', function (assert) {
|
2020-03-31 18:03:15 +01:00
|
|
|
const service = this.owner.lookup('service:state');
|
2022-09-15 10:43:17 +02:00
|
|
|
const state = service.state((id) => id === 'idle');
|
2023-02-10 13:32:19 -08:00
|
|
|
assert.true(service.matches(state, ['idle']));
|
|
|
|
assert.true(service.matches(state, ['loading', 'idle']));
|
|
|
|
assert.false(service.matches(state, ['loading', 'deleting']));
|
2020-03-31 18:03:15 +01:00
|
|
|
});
|
|
|
|
});
|