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